Is it possible to exclude certain keywords from an empty query through Sphinx?
What I had in mind is to use the Extended2 match mode, and in order to exclude keywords, I’ll be using the - or ! operator. I only need to fetch data through Sphinx without using any query (except for the exclusion operators).
In Sphinx, I fetch data using the following method:
$data = $sphinx->query('');
This query returns data which doesn’t have to match anything (it means it’ll return all data, and of course limited to the query limit). The problem is, if I add a keyword with the ! or – operator, it doesn’t return anything. For instance:
$data = $sphinx->query('-google');
$data is returned as false
Maybe there is another method for this to work. Please help.
Thank you.
Sphinx doesnt like negation only queries. If you check GetLastError()/GetLastWarning() it will explicitly say so.
The main reason, is it can’t efficently use its index. Sphinx is based on the concept of inverted indexes. So to run this query, it needs to fetch a list of every document, then remove the ones matching the keyword.
But you make it work. Just need to give sphinx a keyword that will be in every single document. Then can just do
If you dont have a word taht will be every document, just add a fake one 🙂
can then just do
As the word will be on every document.
Dont expect the query to be very fast.