How do I search multiple models in a CMS using Sphinx?

I am trying to use Sphinx in my CMS as a regular search. Since each model in the CMS has different full text fields, I created an index for each model. However, according to the Sphinx forum , multiple index searches with a different schema are not supported.

How do you guys at the CMS use Sphinx for your general site search? Making an Sphinx call for each model and tracking offsets to pages? Creating one huge index with index field per model / field? Is there any other solution that I am not thinking about?

+1


a source to share


1 answer


You probably decided this a long time ago, but ok ...

You cannot span multiple indexes with a different schema in a single call -> Query (), but you can execute multiple queries with AddQuery () and RunQueries ()

So instead of calling

->Query( 'keywords' , ( 'schemaA', 'schemaB', 'schemaC' ) )

      

You doing:

->AddQuery('keywords' , ( 'schemaA') );
->AddQuery('keywords' , ( 'schemaB') );
->AddQuery('keywords' , ( 'schemaC') );
->RunQueries();

      

You will receive an array of results, one for each request. Then on the search results page, you can display results separated by "type" (or schema), for example:



___ PAGE RESULTS _______

Searching for "blue" ...

--- we found 23 results in machines ----

  • car 1
  • car 2
  • car 3
  • ..

--- we found 2 results in houses ----

  • House number 1
  • House 2
  • The House 3
  • ..

_ (end) PAGE RESULTS _____

0


a source







All Articles