Good time of day!

There is such a config Sphinx

source txtcontent : ru_config { sql_query = SELECT `id` as `txt_id`, 1 as index_id, `type_id`,`content_type_id`, `title`, `annonce`, `content` FROM `TxtContent` WHERE `status` = 1 AND `content_type_id` != 14 sql_attr_uint = index_id sql_attr_uint = type_id } 

The entire table is indexed and stored in one large search index. When it comes to finding something in it, everything works OK

But today there was a task to perform a search by category. Categories are described in the type_id field and are of type int.

How in php through SphinxAPI to perform such a search?

Standard search looks like this.

 $sphinxClient = new SphinxClient(); $sphinxClient->SetServer("127.0.0.1", 3312 ); $sphinxClient->SetLimits( 0, 700,700 ); $sphinxClient->SetSortMode(SPH_SORT_RELEVANCE); $sphinxClient->SetArrayResult( true ); $result = $sphinxClient->Query( $this->query, 'txtcontent provider item'); 

I tried adding $sphinxClient->SetFilter('type_id','1'); to perform a search only where type_id = 1, but this did not help.

Actually: how can I search for a specific category? The option to find everything and to throw out unnecessary results from phpp is not considered (otherwise the search will be overwritten by the existing limit) how to do it “correctly” through the API, without putting each topic into a separate search index?

  • And if you feed in SetFilter is not a string, but still an array of numbers? - andreymal
  • I tried it already $array = array( "0" => 1, ); $sphinxClient->SetFilter('index_id',$array) $array = array( "0" => 1, ); $sphinxClient->SetFilter('index_id',$array) hasn’t changed anything at all, other garbage gets into the output - Stas Borzikh
  • Oh, these pkhp-arrays. There is a suspicion that without a reproducible example with a sample of indexed data it will be difficult to help - andreymal
  • This is a braid, you need to filter by type_id (already corrected) type_id takes different values ​​in the database 0 - 10 - Stas Borzoi
  • Okay, “error”) Well then $sphinxClient->SetFilter('type_id', array(1)) doesn't work either? - andreymal

1 answer 1

In short, he solved his problem himself, the problem was that in the search indices the provider item was not indexed with type_id while txtcontent was, you must add type_id for other indexes and then the filtering will take place normally.