We have a simple domain where
FirstName_s:"Bob"
returns 40 documents, and
-Department_t:"Ninjas"
returns all of the documents (we don't have a ninja department).
We expected the query
(FirstName_s:"Bob") OR (-Department_t:"Ninjas")
to return all documents, however it only returned the original 40 documents.
We have experimented with a couple of different orderings, tried using 'NOT' instead of '-' all to no avail.
Is this expected behavior?
Perhaps more importantly, how do we get the behavior we expect?
I stumbled upon https://issues.apache.org/jira/browse/SOLR-2209 so maybe parentheses are causing error. Does this work ?
FirstName_s:"Bob" OR -Department_t:"Ninjas"
Does rewritting the query in a way, that it won't contain OR (using De_Morgan's law) helping ?
-(-FirstName_s:"Bob" AND Department_t:"Ninjas")
This turned out to be an issue with multivalued fields and the way they behave with not.
We had to modify all of our not queries for multivalued fields to
(*:* -department_t:"Ninjas")
Related
First of all, I'm not very experienced in using Solr, so I hope this isn't a stupid question ..
I am experiencing some unexpected behavior with a Solr query. Suppose the query is q="Foo:"Bar" . Now make it q="Foo:"Bar" AND() and we get more results back, which just seem random and certainly not meeting condition "Foo" = "Bar".
Am I missing something here? It doesn't seem logical that an extra condition would return more results instead of less.
Your example queries are not valid Solr queries - if you want to query the field "Foo" for the value "Bar", do Foo:Bar. The AND clause is used between several terms to combine the result for all the terms, i.e. Foo:Bar AND Spam:Eggs.
Your example probably just got parsed to be either Foo:Bar or the value AND somewhere in the default search field.
I am trying to query Solr with following requirement:
_ I would like to get all documents which not have a particular field
-exclusivity:[* TO *]
I would like to get all document which have this field and got the specific value
exclusivity:(None)
so when I am trying to query Solr 4 with:
fq=(-exclusivity:[* TO *]) OR exclusivity:(None)
I have only got results if the field exists in document and the value is None but results not contain results from first query !!
I cannot understand why it is not working
To explain your results, the query (-exclusivity:[* TO *]) will always get no results, because you haven't specified any result to retrieve. By default, Lucene doesn't retrieve any results, unless you tell it to get them. exclusivity:(None) isn't a limitation placed on the full result set, it is the key used to find the documents to retrieve. This differs from a database, which by default returns all records in a table, and allows you to limit the set.
(-exclusivity:[* TO *]) only specifies what NOT to get, but doesn't tell it to GET anything at all.
Solr has logic to handle Pure negative queries (I believe, in much the same way as below, by implicitly retrieving all documents first), but from what I gather, only as the top level query, and it does not handle queries like term1 OR -term2 documented here.
I believe with solr you should be able to use the query *:* to get all docs (though that would not be available in raw lucene), so you could use the query:
(*:* -exclusivity:[* TO *]) exclusivity:(None)
which would mean, get (all docs except those with a value in exclusivity) or docs where exclusivity = "None"
I have founded answer to this problem. I have made bad assumption how "-" works in solr.I though that
-exclusivity:[* TO *]
add everything without exclusivity field to the data set but it is not the case. The '-' could only exclude things from data set. BTW femtoRgon you are right but I am using it as fq (filter query) not as a master query I have forgotten to mention that.
So the solution is like
-exclusivity:([* TO *] AND -(None))
and full query looks like
/?q=*:*&fq=-exclusivity:([* TO *] AND -(None))
so that means I will get everything does not have field exclusivity or has this field and it is populated with value None.
I have a field in my solr schema as "Post Date"(exclude the quotes). when i fire a query with "fl" (field list) parameter in order to view only Post Date of search results, since this field contains a space I am not getting anything in the docs responses. I tried using +, %20 but still i get no results. Please help.
I would like to inform that i have found a solution to this. I tried experimenting and hence came up with a solution on putting \+ as the substitute for white space in the query. Hence the query should be Post\+Date:[ranges]
I couldnt aford to change my schema as many teams are depending on it and we are upgrading our system to a new search engine.
You can specify (what Solr deems crazy) fields by wrapping them like this:
field(Post Date)
This actually changes the returned results fieldname too so you'll get back something like:
"field(Post Date)" : "2010-01-01"
And not just the name as you might imagine.
As a possible workaround, you might be able to use a wild card to achieve your results. Using the solr wiki http://wiki.apache.org/solr/CommonQueryParameters#glob you may be able to specify fl=Post*Date which would possibly get around your problem. I have not verified this but it might work.
Update: This doesn't seem to work on either version of solr I tried (1.4.0 and 3.6.1). Looks like this may have been discussed at http://wiki.apache.org/solr/FieldAliasesAndGlobsInParams but it does not appear to be implemented.
Can anybody tell me why these Solr queries would return vastly different results:
q=BBC+Food&fq=Source:"BBC-WORLDWIDE"
and
q=(BBC+Food)+AND+(Source:"BBC-WORLDWIDE")
The first returns 6 results, and the latter 58.
Can you add &debugQuery=on to the end of your queries and see if the values in the debug output lend any insight into the different between the two queries?
It turns out that the first query is searching for documents that contain both the words BBC AND Food. The second query is searching for either of the words using OR logic.
By placing the keywords in parenthesis, and combining it with any other clause, Solr appears to be inverting the implied "AND" logic for the keywords and instead applying "OR" logic.
The following queries demonstrate this a little better:
q=(BBC+Food)
q=(BBC+Food)+AND+(BBC+Food)
They both return very much different results because the keywords have reversed logic applied.
Solr newbie here.
I have created a Solr index and write a whole bunch of docs into it. I can see
from the Solr admin page that the docs exist and the schema is fine as well.
But when I perform a search using a test keyword I do not get any results back.
On entering * : *
into the query (in Solr admin page) I get all the results.
However, when I enter any other query (e.g. a term or phrase) I get no results.
I have verified that the field being queried is Indexed and contains the values I am searching for.
So I am confused what I am doing wrong.
Probably you don't have a <defaultSearchField> correctly set up. See this question.
Another possibility: your field is of type string instead of text. String fields, in contrast to text fields, are not analyzed, but stored and indexed verbatim.
I had the same issue with a new setup of Solr 8. The accepted answer is not valid anymore, because the <defaultSearchField> configuration will be deprecated.
As I found no answer to why Solr does not return results from any fields despite being indexed, I consulted the query documentation. What I found is the DisMax query parser:
The DisMax query parser is designed to process simple phrases (without complex syntax) entered by users and to search for individual terms across several fields using different weighting (boosts) based on the significance of each field. Additional options enable users to influence the score based on rules specific to each use case (independent of user input).
In contrast, the default Lucene parser only speaks about searching one field. So I gave DisMax a try and it worked very well!
Query example:
http://localhost:8983/solr/techproducts/select?defType=dismax&q=video
You can also specify which fields to search exactly to prevent unwanted side effects. Multiple fields are separated by spaces which translate to + in URLs:
http://localhost:8983/solr/techproducts/select?defType=dismax&q=video&qf=features+text
Last but not least, give the fields a weight:
http://localhost:8983/solr/techproducts/select?defType=dismax&q=video&qf=features^20.0+text^0.3
If you are using pysolr like I do, you can add those parameters to your search request like this:
results = solr.search('search term', **{
'defType': 'dismax',
'qf': 'features text'
})
In my case the problem was the format of the query. It seems that my setup, by default, was looking and an exact match to the entire value of the field. So, in order to get results if I was searching for the sit I had to query *sit*, i.e. use wildcards to get the expected result.
With solr 4, I had to solve this as per Mauricio's answer by defining type="text_en" to the field.
With solr 6, use text_general.