5

I am trying a Solr query which is like this

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

But field3 part of the query is not making any impact. It still brings record which has value1 or value2 in field3

Why is this?

2
  • what do you intend to query with field1:* ? Commented Jul 22, 2010 at 14:12
  • 3
    Please mark one of the answers as accepted, or mention why none of them meet your needs. Commented Aug 21, 2012 at 16:59

3 Answers 3

7

Try this

+field1:* +(field2:1 OR field2:10) -(field3:value1 OR field3:value2)
Sign up to request clarification or add additional context in comments.

Comments

5

I think a AND / OR is missing between the two last blocks. It would then become something like :

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

2 Comments

Do you pass this query directly in an URL, or do you use any API ?
I am trying in Solr Admin area
0

You need to urlencode certain characters in the Solr query to meet UTF8 standards and the + (plus) symbol is one of them, as well as space, brackets etc.

Things to encode are:

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

and so forth, you can see an example of an encoded URL on the SOLR website: https://wiki.apache.org/solr/SolrQuerySyntax

Try:

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

This should give you:

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

IF your default query parser operation is set to OR, then any space between fields will be interpreted as an OR operator.

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.