Hi Alan

Thanks for that clarification.

Having OR logic between attributes is a little tricky, but it's certainly 
possible:
http://pat.github.com/ts/en/common_issues.html#or_attributes

However, combining fields and attributes together with OR logic is probably not 
possible - Sphinx keeps the two concepts quite separate.

Cheers

-- 
Pat

On 09/02/2013, at 6:36 AM, Alan DeLonga wrote:

> Hi Pat,
> 
> I actually got that far, my issue was with having different attributes ORed. 
> 
> The problems I was having when I tried to run the search were as follows:
> 
> 1. A bar has multiple profiles and each profile has a budget, experiece and 
> tags. I needed the search to be able to give me back bars only if it had a 
> profile for the current day that matched the budget and experience specified. 
> If I made indexes for day, experience and budget as I said in email 1, then 
> put them as conditions in the search. What it would return is bars that had 
> profiles that combined contained that budget and experience, so if I wanted 
> budget penniless and experience ravin on monday it would return the bar if it 
> had a profile for monday and one of its profiles contained ravin and any 
> other contained penniless.
> 
> Then I tried using the 'with' clause and created a day_id to filter on. But 
> then when I did this it only checked the first profile for that bar, if it 
> wasn't the right day it wouldn't return anything. So basically if I had a bar 
> and I saved the profiles to the DB in this order tuesday, monday, thursday 
> and wanted to check against thursday profiles it would never check the 
> thursday profile for this bar. It would only check if the order the 
> bar_profiles were added to the db started with that day. So it would have to 
> be thursday, monday, wednesday.
> 
> This led me to believe I probably just didn't understand how this was 
> supposed to be working. It seems like it works like this, conditions happen 
> first to populate a collection to be filtered using the with clause. So if I 
> wanted to find a day with the specific budget experience tags I have to have 
> id numbers for each of those and put them in the with clause and the day as 
> the condition. 
> 
> (I know I am leaving off stuff in the search_options hash I am just showing 
> the relevant info)
> 
> So I was doing:
>  search_options = { conditions=>{:budget=>budget, :experience=>}, 
> with=>{:day=>day_id}, ...}
> 
> When I think I need to do:
>  search_options = { conditions=>{:day=>today}, with=>{:budget=>budget(number 
> val), :experience=>experience(number val)}, ...}
> 
> The problems is how the tables were set up to use thinking sphinx weren't 
> configured to run the right search because they didn't understand how to do 
> it either.
> 
> The problem with ORing was like I said between condition values (not just 
> within one condition)
> 
> So if I wanted all users that were 23 OR white I can't just run 
> search_options = {conditions={:age=>23, race=>"white"}, ...}
> 
> Because this only returns users that are 23 AND white, since there is only 1 
> profile associated with each user. That was the problem I had, I ended up 
> just coding up additional functions and had to run multiple queries. I wanted 
> to try to figure out how to do all this with the correct implementation of 
> sphinx. But I also had to ensure I didn't break any of the functionality 
> based the current db set up. Either way I did figure it out. But if you could 
> explain either of these I know it would help others. I couldn't find any 
> specific examples explaining solutions to these issues. Your thinking_sphinx 
> documentation is very thorough but there weren't any implementation examples, 
> just 1 line code snippets. Implementation examples are extremely helpful in 
> explaining the correct implementation of this query engine. I am only so 
> curious because I do want to know how to use this correctly because it seems 
> like something I should be using on future projects. Thanks again for getting 
> back to me. My project is done using this, but if you could give some insight 
> on these issues it would still be really helpful.
> 
> Thanks,
> 
> Alan
> 
> On Thursday, February 7, 2013 5:30:56 PM UTC-8, Pat Allan wrote:
> 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.
>  
>  


-- 
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