manticoresearch
manticoresearch copied to clipboard
Two negative terms in search query gives error: query is non-computable
Describe the bug
A query in the form of: something -something2 -something3 gives an error: {'error': 'query error: query is non-computable (node consists of NOT operators only)'}
something -(something2 something3) however does work, but users may not always type it out this way. It's quite naturally to do a double negation with the above syntax.
MRE Below python code will create an index and do 3 searches. One for just one word, another for one word and a negation of another word. And the third with two negations. The last one fails with the above error message.
import manticoresearch
config = manticoresearch.Configuration(
host = "http://127.0.0.1:9308"
)
client = manticoresearch.ApiClient(config)
searchApi = manticoresearch.SearchApi(client)
row = {'content': 'word sentence', 'title': 'here', 'contentid': '10'}
resp = indexApi.insert({"index" : 'products', "doc" : row})
resp = searchApi.search({"index":ixname,"query":{"query_string":"word"}, "limit":1})
print(resp)
resp = searchApi.search({"index":ixname,"query":{"query_string":"word -sentence"}, "limit":1})
print(resp)
resp = searchApi.search({"index":ixname,"query":{"query_string":"word -sentence -paragraph"}, "limit":1})
print(resp)
manticore has 'fixed' this, but you need to enable the option for it work
There is a per query option OPTION not_terms_only_allowed=1
in the python API, guessing it something like
searchApi.search({"index":ixname,"query":{"query_string":"word -sentence", "options": {"not_terms_only_allowed":1} }, "limit":1})
https://manual.manticoresearch.com/Searching/Options#not_terms_only_allowed
Or can enable it 'globally' in searchd.conf https://manual.manticoresearch.com/Server_settings/Searchd#not_terms_only_allowed
@barryhunter It was enabled in the global config under searchd section. Also added it to the search options, but no luck. Getting the same error. Possible for you to try my python MRE, and let me know if it works for you.
Ah, what version of searchd are you using? It requires recent version.
That been said perhaps can reproduce it (sorry, no idea how to get the python client installed)
RT.staging>create table test11 (content text, title text, contentid integer);
Query OK, 0 rows affected (0.025 sec)
RT.staging>insert into test11 (content,title,contentid) values ('word sentence', 'here', 10);
Query OK, 1 row affected (0.021 sec)
RT.staging>select * from test11 where match('word');
+---------------------+-----------+---------------+-------+
| id | contentid | content | title |
+---------------------+-----------+---------------+-------+
| 4829618108685615120 | 10 | word sentence | here |
+---------------------+-----------+---------------+-------+
1 row in set (0.013 sec)
RT.staging>select * from test11 where match('word -sentence');
Empty set (0.001 sec)
RT.staging>select * from test11 where match('word -sentence -paragraph');
Empty set (0.001 sec)
RT.staging>select * from test11 where match('-sentence -paragraph');
ERROR 1064 (42000): index test11: query error: query is non-computable (node consists of NOT operators only)
RT.staging>select * from test11 where match('-sentence -paragraph') option not_terms_only_allowed=1;
ERROR 1064 (42000): index test11: query error: query is non-computable (node consists of NOT operators only)
RT.staging>select * from test11 where match('-sentence') option not_terms_only_allowed=1;
Empty set (0.001 sec)
RT.staging>select * from test11 where match('-sentence');
ERROR 1064 (42000): index test11: query error: query is non-computable (single NOT operator)
RT.staging>Ctrl-C -- exit!
Aborted
root@development-0:/var/www/geograph$ python
bash: python: command not found
Have the select * from test11 where match('-sentence -paragraph') option not_terms_only_allowed=1; ERROR 1064 (42000): index test11: query error: query is non-computable (node consists of NOT operators only)
when match('-sentence') option not_terms_only_allowed=1 works.
Manticore version is 5.0.2 348514c86@220530 dev The latest one I think (at least as of 2 weeks ago)
This looks like a bug to me:
mysql> select * from t where match('-c -d') option not_terms_only_allowed=1;
ERROR 1064 (42000): index t: query error: query is non-computable (node consists of NOT operators only)
The workaround is to use parentheses:
mysql> select * from t where match('-(a|d)') option not_terms_only_allowed=1;
+------+------+
| id | f |
+------+------+
| 1 | c |
+------+------+
1 row in set (0.00 sec)
but at least the error is misleading. I think syntax -c -d should be supported as well.
@sanikolaev Just want to point out that with the python client, searches such as : a -b -c also fail. In SQL, these work. Whereas -b -c fails in both.
➤ Sergey Nikolaev commented:
searches such as : a -b -c also fail. In SQL, these work. Whereas -b -c fails in both.
I've created a separate issue about it https://github.com/manticoresoftware/manticoresearch/issues/878
should be fixed at 6747a8ba