Solr OR between Block Join expressions - solr

Does anyone know how to make a query in Solr between a block join expression and a "regular" expression? For example like this:
{!parent which="content_t:customer"}(content_t:order AND orderDate_dt:[* TO 2016-01-13T00:00:00Z])
OR
customerType=VIP
It seems to me like I have tried all combinations and alternativs with "q" and "fq" parameters, but there is always something giving me a query error. By default we have AND between fq parameters, and I guess q.op does not change that?
I have also tried to create a corresponding NOT AND query, which logically is the same. This works for queries that do not contain block join expressions. E.g., this is not valid:
fq=-{!parent which="content_t:customer"}(content_t:order AND orderDate_dt:[* TO 2016-01-13T00:00:00Z])
but this is:
-(customerType=VIP)
We are using Solr 5.2.1. Can someone please help?

Related

AND in solr query returns more results

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.

Solr: Subquery concept

http://xx.xx.xx.xx:8983/solr/collection1/select?q=_query_:{! v=cars rows=10 df=content_urdu fl=score,*}&wt=json&indent=true&rows=30&sort=pr desc
Please someone can explain me, what the above query will do to clear my concepts? Is the text inside curly brackets is sub-query? How will it execute?
query will give you the flexibility of using different query parcers instead of the ones that is by default selected by your query handler in your mentioned example select handler.
Everything inside the braces are your parameters for the Qparser and anything outside is the q parameter for the parser but should be within the quotes. In the below example edismax and surround parser are working together with AND in between them. So they act as a filter. Its the same as using them in fq fields but this helps when generating dynamic queries where there can be OR instead of AND. This feature leverages solr and lucene's multiple Qparsers and can be used together with faceting to get desired results.
_query_:"{!edismax rows=10 df=content_urdu } source_type:\"custom\"" AND
_query_:"{!surround maxBasicQueries=10000} content:5N(tru*,(equi* OR and*))

Difference between q and fq in Solr

Someone please give me a decent explanation of the difference between q and fq in Solr query, covering some points such as -
Do they have the same syntax?
Do they return same results?
When to use which one and why?
Any other differences
Standard solr queries use the "q" parameter in a request. Filter queries use the "fq" parameter.
The primary difference is that filtered queries do not affect relevance scores; the query functions purely as a filter (docset intersection, essentially).
The q parameter takes your query and execute against the index. Then you can use filter queries (can use multiple filter queries) to filter the results.
For example your query can look like this.
q=author:shakespeare
this will match the documents which has 'shakespeare' in the 'author' field. Then you can use filter queries like this.
fq=title:hamlet
fq=type:play
Those will filter the results based on the other fields. You can even filter on the same field.
The query syntax is similar for both q and fq parameters

Solr Boolean query on multi-valued field in filter query

We have a multi-valued indexed field named tags. We want to find all documents that meet one of the following conditions via a filter query:
if tag flagged is present, then tag safe should also be present.
tag flagged is not present.
I tried fq=(tags:(flagged AND safe) OR -tags:flagged) but it is not returning the desired results. Instead it is returning documents taggedsafe and not tag flagged i.e. the result is same as this query: fq=(tags:safe AND -tags:flagged). How do I fix my query?
Also both fq=(tags:safe AND -tags:flagged) and fq=(tags:safe OR -tags:flagged) are returning the same results. Why is this?
Solr version: 3.6.2
The following works correctly.
From Erik Hatcher (solr-user mailing group):
Inner purely negative clauses aren't allowed by Lucene. (Solr supports top-level negative clauses, though, so q=NOT foo works as expected.)
To get a nested negative clause to work, try this:
q=tags:(flagged AND safe) OR (*:* AND NOT tags:flagged)

Lucene OR query not working

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.

Resources