Search code examples
sphinx

Optimizing Sphinx Query when matching records in a table


If I am trying to find all matches to keywords in an indexed Sphinx text field/table, is there a way to load ALL records into the query at once vs doing one at a time?

In other words if I have a query such as

(Enjoy | Like | Love) << ($Language) << (Cuisine | Food | Dining)

would I be better served stepping through each language in the Language table so that I process

(Enjoy | Like | Love) << Albanian << (Cuisine | Food | Dining)

through

(Enjoy | Like | Love) << Mexican  << (Cuisine | Food | Dining)

through

(Enjoy | Like | Love) << Zimbabwean << (Cuisine | Food | Dining)

or is there a way to process this all at once and return matches:

(Enjoy | Like | Love) << (Albanian | ... | Mexican | ... | Zimbabwean) << (Cuisine | Food | Dining)

So that each record is part of an OR pipe and I get a list of all matches? Is this possible and if so do I gain anything in terms of speed, cpu, ram usage?


Solution

  • Really, performance questions can only be answered by benchmarking. The biggest effects on performance are often very subtle

    For example, in your case the number of results in each language is possibly the biggest factor. If few results in each, then the second is better (avoids running lots of queries with no results) - but if there are many reults in most languages, then probably little different.

    But that's my point I am guessing. May be totally wrong!


    Having said that, if performance is really improtant, then the wordforms trick mentioned in Use exact search with OR operator inside Sphinx query might help. Basically doing more work upfront (during indexing) to make queries quicker (less work)