# Search works in dev but not in prod?

**URL:** <https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434>\
**Category:** Rails\
**Created:** [June 3, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434 "2008-06-03T21:55:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/1 "2008-06-03T21:55:53Z")

</div>

Is there any reason for a search page that searches through events for a  
keyword and then displays those that contain the keyword to not give any  
results in production when it does in development? I’ve made sure I’m  
searching terms that should give me results in production, but it’s like  
it’s not searching through the events at all or something.

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 10:14pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/2 "2008-06-03T22:14:49Z")

</div>

Amanda … wrote:

> Is there any reason for a search page that searches through events for a  
> keyword and then displays those that contain the keyword to not give any  
> results in production when it does in development? I’ve made sure I’m  
> searching terms that should give me results in production, but it’s like  
> it’s not searching through the events at all or something.

Check or turn on your logging in Production to see what’s going on.

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 10:32pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/3 "2008-06-03T22:32:43Z")

</div>

Ar Chron wrote:

> Check or turn on your logging in Production to see what’s going on.

In my dev log I get a whole bunch of stuff from checkin each event for  
the keywords (i think thats what its doin):

Processing SearchController#keyword (for 127.0.0.1 at 2008-06-03  
16:29:17) [POST]  
Session ID: bc95e3751aa213c624c33af71a846c8c  
Parameters: {“commit”=\>“Search”, “text”=\>“test”,  
“order”=\>“created\_on”, “action”=\>“keyword”, “method”=\>“post”,  
“controller”=\>“search”, “search\_auds”=\>“1”, “search\_streams”=\>“1”}  
e[4;36;1mCalendar Load (0.001025)e[0m e[0;1mSELECT \* FROM calendars  
WHERE (hidden=0) e[0m  
e[4;35;1mCalendar Columns (0.002512)e[0m e[0mSHOW FIELDS FROM  
calendarse[0m  
e[4;36;1mCalendar Load (0.001113)e[0m e[0;1mSELECT \* FROM calendars  
WHERE (hidden=0) e[0m  
e[4;35;1mStream Columns (0.002510)e[0m e[0mSHOW FIELDS FROM  
calendarse[0m  
e[4;36;1mEvent Columns (0.002639)e[0m e[0;1mSHOW FIELDS FROM  
eventse[0m  
e[4;35;1mStamp Columns (0.001862)e[0m e[0mSHOW FIELDS FROM  
stampse[0m

…

In the production log I just get:

Processing SearchController#keyword  
[POST]  
Session ID: a0db357e9a9aaec2298535c55618f688  
Parameters: {“commit”=\>“Search”, “text”=\>“test”,  
“order”=\>“created\_on”, “action”=\>“keyword”, “method”=\>“post”,  
“controller”=\>“search”, “search\_auds”=\>“1”, “search\_streams”=\>“1”}  
Rendering within layouts/application  
Rendering search/keyword  
Completed in 0.15170

So it doesn’t even check for the keywords in the events?

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/4 "2008-06-03T22:41:33Z")

</div>

I believe you need to turn on debug for your production environment to  
see more.

Something like this in your production.rb should give you most of  
“production” behaviors, but you’ll still get debug.

# Show full error reports and enable caching

config.log\_level = :debug  
config.action\_controller.consider\_all\_requests\_local = true  
config.action\_controller.perform\_caching = true  
config.action\_view.cache\_template\_extensions = true  
config.action\_view.debug\_rjs = true

I always add

config.active\_record.colorize\_logging = false

to get rid of the unreadable e[4;35;1mS stuff

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 3, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/5 "2008-06-03T22:45:13Z")

</div>

Ar Chron wrote:

> I believe you need to turn on debug for your production environment to  
> see more.

Where do I do this? In the terminal? sorry I’m new to the rails stuff

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 4, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/6 "2008-06-04T13:28:18Z")

</div>

You do this in your environment configuration file, in this case  
config/environments/production.conf

Serge

On Jun 3, 5:45 pm, “Amanda …” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 4, 2008, 8:07pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/7 "2008-06-04T20:07:16Z")

</div>

Does anyone have any suggestions? I’m completely stuck on this and my  
logs aren’t showing me anything that would help.

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 4, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/8 "2008-06-04T15:27:45Z")

</div>

Thanks a lot for that, now I can see that it is finding some  
events…but only past events (dated before today), and not displaying  
them (this is what it’s supposed to do)…but it should also be finding  
events for today and the future and displaying them. I think there might  
be something wrong in the base condition in the event search method:

def self.search(search\_streams, search\_auds, keywords, options = {},  
\*args)

default\_options = {  
“calendars” =\> Calendar.find\_public,  
:status =\> :approved  
}

options = default\_options.merge(options)

if keywords.nil? or keywords == “”  
t = “%” + keywords.to\_s.gsub(/\s/, ‘%’) + “%”  
base\_condition = ["(title like ? OR body like ? OR location like  
?)", t, t, t]  
else  
t = (keywords.split(" “).collect { |x| “[[:\<:]]” + x + “[[:\>:]]”  
}).join(”|")  
base\_condition = ["(title regexp ? OR body regexp ? OR location  
regexp ?)", t, t, t]  
end

events = []  
streams = []  
audiences = []

options[“calendars”].each do |c|  
audiences \<\< c if c.is\_a?(Audience)  
streams \<\< c if c.is\_a?(Stream)  
end

if search\_streams == “1”

```
 for cal in streams

```

base\_condition[0] += ’ AND stamps.calendar\_id = ? AND stamps.status =  
?’  
base\_condition += [cal.id, Stamp::STATUS[options[:status]]]  
e = Event.find(:all, :conditions =\> base\_condition, :include =\>  
:stamps)  
events += e  
end  
end

if search\_auds == “1”

```
  for cal in audiences
    base_condition[0] += " AND audiences_events.audience_id = ?"
    base_condition << cal.id
    # explicitly written joins instead of using the :include option
    # the :include option creates an invalid SQL statement
    e = Event.find(:all, :conditions => base_condition, :include => 

```

:stamps,  
:joins =\> ‘LEFT OUTER JOIN audiences\_events ON  
audiences\_events.event\_id = events.id LEFT OUTER JOIN  
calendars ON calendars.id = audiences\_events.audience\_id’)  
events += e  
end  
end

events.uniq!

Do you see anything there that would work properly in development but  
not in production? Thanks a lot for your help!

---

<div class="post-metadata">

**Author:** ![amanda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/67e7ee/32.png) [@amanda](https://www.ruby-forum.com/u/amanda)\
**Post date:** [June 4, 2008, 9:23pm UTC](https://www.ruby-forum.com/t/search-works-in-dev-but-not-in-prod/139434/9 "2008-06-04T21:23:54Z")

</div>

Okay so I figured out that if i comment out the 2 lines:

base\_condition[0] +=’ AND stamps.calendar\_id = ? AND stamps.status = ?’

base\_condition += [cal.id, Stamp::STATUS[options[:status]]]

Then the search finds and displays the events like it should…anyone  
know why this is? I don’t get it
