Difference between q and fq in Solr - 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

Related

Why does Dismax's bq (Boost Query) parameter filter results instead of just boosting them?

I'm using Solr 8.11.2. In order to boost documents with certain field values, I'm using Dismax's bq (Boost Query) parameter.
From what I've read, this should only influence the score of the search results returned by the rest of the query. What I see happening is that it filters all search results that don't have the field I'm boosting.
I'm using the following query, which returns all documents containing both words procedure and maintenance:
q=((+procedure+maintenance))&rows=10&start=0&wt=xml&q.op=AND&fl=id,score,alias,author,hash,collection,label,url,lastModified,path,extension,objectId,objectDtType,title,DocumentPK_s,Taal_s,Site_s,SharePointId_s&hl=true&hl.qt=highlightRH&hl.fl=content,description,label&hl.snippets=5&defType=dismax&bf=recip(max(0,ms(NOW-3MONTH,creationDate)),3.16e-11,1,1)&pf=content&sort=score DESC
But as soon as I append &bq=language:english^10000, which is supposed to boost documents where the field language is set to english, all documents where the field language doesn't exist are no longer part of the results.
Am I misunderstanding how this parameter is supposed to work? Is it a side effect?

No matches when mixing keywords

I am trying to do a product search setup using Solr. It does return results for keywords that follow the same order in the product name. However, when the keywords are mixed up, no results are returned. I would like to get results with scores that closely match the given keywords in any order.
My question on scoring has the schema, data configuration and query. Any help will be greatly appreciated.
As long as you enter your query as a regular query, instead of using wildcards, any hits in a text_general field as you've defined should be returned.
You can use the mm parameter to adjust how many of the terms supplied that need to match from a query. I suggest using the edismax query parser, as that allows you do to more "natural" queries instead of having to add the fieldnames in the query itself:
defType=edismax&qf=catchall&q=nikon dslr
defType=edismax&qf=catchall&q=dslr nikon
should both give the same set of documents (but possibly different scores when using phrase boosts).

How to boost a solr document at query time based on attribute value

I want boost at query time all documents that have value user_id=2. Basically I want on the top of my results all the documents belonged to a specific user.
After looking at some Solr resources I ended up writing a query like, but it is not working properly.
/solr/public-main/select?q={!boost b=if(div(155623,user_id),2,1)}sometext&wt=json&indent=true&debugQuery=true
Any hints?
Thanks
You don't need to use the boost with a dynamic boost. Apply a boost query which will boost all the documents that match the query: bq=user_id:2^4. Adjust 4 to a suitable boost value depending on the rest of your boosts (if any in q or qf).
One option is to have a function query with fl=x,y,userexists:exists(query({!v='user_id:2'})) and then u can sort by userexists and then by score field.

problems with facet.sort parameter with solr

I'm trying to order facets from a single query with multiple facet queries.
But facet.order and facet.mincount are not working.
the query is:
facet.query=text:word1&facet.query=text:word2&facet.query=text:word3&facet=true&q=*:*&facet.mincount=50&facet.sort=count
I'm generating it with solrj
query.setQuery("*:*");
query.setFacet(true);
query.setFacetSort(FacetParams.FACET_SORT_COUNT); //count
query.setFacetMinCount(50);
query.addFacetQuery("text:word1");
query.addFacetQuery("text:word2");
query.addFacetQuery("text:word3");
the response is:
...facet_counts={facet_queries={text:word1=597,text:word2=23,text:word3:1100},facet_fields={},facet_dates={},facet_ranges={}}}
Thanks.
UPDATE
It seems that facet.field must be set to use the other facet.mincount and facet.sort. But it only affects to the words in facet field not the facet queries. Is that true? Any solution?
Yes, either you do a "query faceting" (without extra parameters) or a "field faceting" that has all the parameters (mincount, order, etc)
http://wiki.apache.org/solr/SimpleFacetParameters#facet
BTW, ampersand is missing after q=*:* in:
facet.query=text:word1&facet.query=text:word2&facet.query=text:word3&facet=true&q=*:*facet.mincount=50&facet.sort=count

Solr filter queries and boosting

Is it possible to boost fields that appear in filter queries (fq=) in Solr?
I have a faceted query that has a tagged filter query something like this:
...&q=*:*&fq={!tag:X}brand:(+"4911")+OR+body:(abc)&facet.field={!ex:X}brand&..
(I facet on brand and the facet is set to ignore the filter query tagged X, so I need to use a filter query.)
I would like to make matches on the brand field score higher than matches on body field in the filter query.
The fields brand and body are multivalued.
I've tried adding bf=/bq= arguments, and I can get brand matches to score higher if I change the filter query to be the main 'q=' query, but I don't seem to be able to influence the score of anything in the filter query. I think I maybe going about it in the wrong way..
Thanks.
Solr "fq"'s do not affect score -- see the wiki. So, you should add your queries to "q" that you actually want to boost. If need be, you can always duplicate a query restriction in both "q" and "fq", as "fq" only acts as a restriction on the results set.

Resources