Hi Alan

It's not so much that Thinking Sphinx ANDs conditions, but rather Sphinx just 
treats that as the default. You can't change this default, but you can have 
multiple values for a condition handled in an OR manner like so:

  tags = ['foo', 'bar', 'baz']
  Model.search :conditions => {:tags => "(#{tags.join(' | ')})"}

In Sphinx's syntax, that becomes "@tags (foo | bar | baz)"

Is that what you're after?

Cheers

-- 
Pat

On 07/02/2013, at 7:18 AM, Alan DeLonga wrote:

> Hey Pat,
> 
> Thanks for responding. I had to build up a simple app to test thinking sphinx 
> to understand how it actually worked in my specific application. It was 
> really difficult trying to jump into a project assuming their implementation 
> was correct when nothing was set up right. Basically what I began to 
> understand was the following.
> 
> For the 'with' to work it HAS to be a number. Converting with CRC32 wasn't 
> working for me because the numbers created for day names like monday, 
> tuesday, etc. were being converted to numbers larger then what an int could 
> hold (so it was always depricated to the int cap which is like 2147483647). 
> So for the constraining factors I had to create additional fields like 
> day_id, in the DB, so it was only a number 1-7. Then I would check against it 
> with the current day by creating an array and do an indexOf with the current 
> day value. 
> 
> The next thing I had to do was understand how the conditions worked. It seems 
> like all the (value/condition) strings had to be present in the db row for a 
> match to be made. So what I had to do was then only add the tag/string that 
> should always match. So I had to run the search with budget as the only 
> condition. Then go through the list of tags (add it as a condition) and run 
> the search and remove that condition, for each tag. If I tried to run the 
> search using all tags, it would only return a bar if ALL the tags matched not 
> 1. 
> 
> But I also read that is because the default of thinking sphinx is to AND the 
> conditions. To OR them you have to add something else, but I didn't figure 
> that out. If you have the time to maybe shed some light on how to OR the 
> values put into conditions that would be helpful. Again I appreciate the 
> response.
> 
> Thanks,
> 
> Alan
> 
> On Friday, February 1, 2013 4:27:14 PM UTC-8, Pat Allan wrote:
> Hi Alan
> There's a lot to take in there, but I think the core of the issue you're 
> currently facing comes down to the fact that you're using a string attribute, 
> and Sphinx doesn't let you filter by attributes (:conditions is for fields, 
> :with is for attributes). There's a note buried in the docs about this:
> http://pat.github.com/ts/en/common_issues.html#string_filters
> 
> I would probably recommend switching days to be field instead, and just use 
> conditions.
> 
> Let me know how it goes and whether there's further questions.
> 
> Cheers
> 
> -- 
> Pat
> 
> 
> On 01/02/2013, at 12:49 PM, Alan DeLonga wrote:
> 
> > Hey Pat,
> > 
> > I have been wrestling with an outsourced project that they brought back in 
> > house. They used Thinking Sphinx, without giving any documentation or 
> > comments in their code about how they set things up or what they were 
> > trying to achieve. After months of hacking away at this app, its 95% 
> > finished. The last part I am having difficulty fixing is getting the search 
> > to constrain the results correctly. I am super new to this and would 
> > appreciate any insight you could give me. So here is my issue on 
> > stackoverflow, and I will elaborate below as well.
> > 
> > So basically the issue is between 3 models/tables users, bars and 
> > bar_profiles. There are bar_profiles for each bar, that contains the 
> > criteria we are matching against the users criteria. There is a bar_profile 
> > for each day, containing the criteria to match against for the users 
> > selections.
> > 
> > Inside bar is where the search is happening so they set up indexes for 
> > bar_profiles as follows:
> > 
> > has_many :bar_profiles
> > 
> > define_index do
> > 
> >     has bar_profiles
> > (:day), :as => :
> > days
> >     indexes bar_profiles
> > .budget, :as => :budget_tags
> >     indexes bar_profiles.day, :as => :
> > day
> >     indexes bar_profiles
> > .tags, :as => :daily_tags
> >     .
> > 
> >     
> > .
> > 
> >   
> > end
> > 
> > and in the method that runs the search I have:
> > 
> >     today = ((Time.now + Time.zone_offset('EST')).strftime("%A")).downcase
> >     search_options = {:conditions => {}, :with => {:days=>today}, :page => 
> > 1, :per_page => algorithm.results_per_page}
> > 
> >     search_options[:conditions][:experience_tags] = options[:experience] 
> > unless options[:experience].blank?
> >     budget = combine_budgets(options[:budget])
> >     search_options[:conditions][:budget_tags] = budget unless budget.blank? 
> > 
> > What I am trying to do is match the options[...] that the user selects 
> > against the bar_profile that matches up with the current day. The current 
> > set up allows the search to run without errors using:
> > 
> > bars = Bar.search(search_options)
> > 
> > But when I added in the :with=> {:days=>today}, I stopped getting any 
> > results back from the search. So I am guessing I just don't fully 
> > understand how to use 'with' in Thinking Sphinx for my exact 
> > implementation. What I am trying to do is make the search constrain the 
> > results based on the current day.
> > 
> > Where my goal would be if I don't pass in any conditions, it would return 
> > all the bars with a profile for today. If I have a condition for budget_tag 
> > = low budget, I only want to get back bars that have a bar_profile for 
> > today that contains that budget_tag.
> > 
> > Currently without the 'with' option it will return any bar that has ANY 
> > bar_profile that has one of the match criteria. So I am getting a bar that 
> > has the criteria, but for the wrong day.
> > 
> > If you could help guide me to some examples or give some insight I would 
> > really appreciate it. I have been wrestling with this issue for a week now 
> > and I have gotten to this point but still can't seem to get the 
> > functionality I need. I know I am doing something wrong, I just don't 
> > really understand how to correct it. Either way I appreciate you taking the 
> > time to read this.
> > 
> > Thanks,
> > 
> > Alan
> > 
> > 
> > -- 
> > You received this message because you are subscribed to the Google Groups 
> > "Thinking Sphinx" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >  
> >  
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to