Using AND, OR, and NOT in a Solr Request

I am trying to execute a Solr request like this

+field1:* AND (field2:1 OR field2:10) NOT(field3:value1 OR field3:value2)

But field3 of the request part has no effect. It still brings an entry that has value1 or value2 in field3

Why is this?

+3
source share
3 answers

try it

+field1:* +(field2:1 OR field2:10) -(field3:value1 OR field3:value2)
+5
source

I think there is no AND / OR between the last two blocks. Then it will become something like:

+field1:* AND (field2:1 OR field2:10) AND NOT(field3:value1 OR field3:value2)
+4
source

Solr UTF8, + () - , , ..

:

Space => +
+ => %2B
( => %28
) => %29

.., URL- - SOLR: https://wiki.apache.org/solr/SolrQuerySyntax

Try:

str_replace(array('+','(',')',' '), array('%2B','%28','%29','+'), '+field1:* (field2:1 field2:10) -(field3:value1 field3:value2)');

:

%2Bfield1:*+%2B%28field2:1+field2:10%29+-%28field3:value1+field3:value2%29

​​ OR, OR.

The above result is far from clean and readable, but it is a correctly formatted UTF8 string that Solr requires you to pass. You will notice the difference as soon as you run it.

Why str_replace instead of urlencode? Well, you can use urlencode because it will format the string correctly as UTF8, but it can format some string components that don't need to be encoded.

0
source

Source: https://habr.com/ru/post/1755955/


All Articles