Migrating from Sphinx 2.2.11 with manticoresearchphp

Hi,

I’m migrating my app from sphinx search to manticore search (sphinx 2.3.x always bugs, and sphinx 3.x cant start on several servers). I used the sphinxapi in php and i’m going to use manticoresearch-php. With sphinx i would just get the document ids like this:
$query = $sphinx->EscapeString($query);
$results = $sphinx->Query(str_replace(’-’, ’ ‘, $query), VCfg::get(‘sphinx_index’));
And then from mysql i just get my columns like this:
$ids = implode(’,’, array_keys($results[‘matches’]));
$this->db->query(’
SELECT ‘.implode(’, ‘, $columns).’
FROM #__video AS v
LEFT JOIN #__channel AS c ON (c.channel_id = v.channel_id)
LEFT JOIN #__user AS u ON (u.user_id = v.user_id AND u.status = 1)
WHERE v.video_id IN (’.$ids.’)
ORDER BY FIELD (v.video_id, ‘.$ids.’)
');

How can i do this with manticoresearch-php. I didnt find an option to get document ids only, it always fetches all fields from the index. I have alot more columns that i need from mysql, which i dont save in the index (it would just use space, i dont use those columns for searching).

Thank you!

SELECT id FROM idx_name ... should returns only id attribute at result set

Yes, but can i do this with manticoresearch-php? Using $results = $index->search(‘space team’)->get();

you could set select list with SetSelect method https://github.com/manticoresoftware/manticoresearch/blob/99c8e7a9c94a960bba80ba0699ac1855ffc74a08/api/sphinxapi.php#L995

That would be like going back to sphinx :slight_smile: I will do more research.

not quite sure
In case you use API I just point you to API method

We also have SphinxQL and HTTP endpoints along with different clients generated with OpenAPI tool such as manticoresearch-php

$ids = implode(’,’, array_keys($results[‘matches’]));
How can i do this with manticoresearch-php

Here https://github.com/manticoresoftware/manticoresearch-php#perform-a-search in the example you can see:

   echo 'Document:'.$doc->getId()."\n";

is this what you are looking for? Or do you want to avoid iterating through the documents array and are looking for a method which would do it for you and would return the ids list right away?

I wanted to avoid iterating through the documents array (2 times). In the end i decided i will use php mysqli for this. I will benchmark which method is faster once i get some free time. Thank you for helping!

I did a small benchmark and using mysqli is faster (2x). While using manticoresearch-php might be easier to maintain in the long run, using mysqli is important because i have alot of clients that want to run video sites with 1 million entries on a 20$ vps.

When, years ago, I stopped using the Sphinx PHP API, I did so because I got tired of the effort involved in updating the PHP API when I updated the searchd version. In other words, I believe that that using the SQL interface is easier to maintain over search engine version upgrades.