What is the best way to get information from Sphinx (in PHP)?

I am new to sphinx and I am setting it up on a new site. It works great, and when I search with search in the console, everything works.

Using PHP api and search gives me the same results. But this only gives me identifiers and weights for the rows found. Is there a way to bring some togheter text fields with a 'matches' hash, for example?

If there is no way to do this, does anyone have a good idea on how to retrieve records from a database (sql) in order to sort the sphinx weight (while looking at all of them at the same time)?

+4
source share
4 answers

You can use the mysql FIELD () function call in your ORDER BY so that everything is in the specified sphinx order.

$idlist = array(); foreach ( $sphinx_result["matches"] as $id => $idinfo ) { $idlist[] = "$id"; } $ids = implode(", ", $idlist); SELECT * FROM table WHERE id IN ($ids) ORDER BY FIELD(id, $ids) 
+1
source

Yes, the sphinx does not bring results. But I found an easy way to change the order of the request using the IN () clause to put everything together.

Request for something

 SELECT * FROM table WHERE id IN(id_list... ) 

just indexing the result with their id in the table:

 while ($row = mysql_fetch_objects) $result[$row->id] = $row; 

and having corresponding results from sphinx, it is very easy to change it:

 $ordered_result = array(); foreach ($sphinxs_results['matches'] as $id => $content) $ordered_result[] = $result1[$id]; 

this will work if your $ sphinxs_results are in the correct order.

its almost a pat response, but with fewer cycles. You can probably make some differences in the big results.

+4
source

unfirst sphinx does not return matching fields, only its identifiers (the sphinx index contains no data - only a hash from the data). Post a message about this problem that you can find on the sphinxsearch.com forum.

0
source

According to Alex, Sphinx does not return this information. You will need to use identifiers for an independent query to the database - just swipe through each identifier, get your data, saving the results in a weighting order. To do this in one request, you can try something like the following (psuedo-code - PHP is not my choice language):

 results = db.query("SELECT * FROM table WHERE id IN (%s)", matches.join(", ")); ordered_results = []; for (match in matches) { for (result in results) { if (result["id"] == match) { ordered_results << result; } } } return ordered_results; 
0
source

All Articles