I am trying to find the facet count for a particular field in my Solr Implementation.
I was wondering if there is a way to get facet counts for only a few specific words in that field?
For example,
field name = product
values can be camera <10> , tv <20> , DVD <20> , CD <30>
Now is it possible to get the facet counts of only tv and DVD?
I tried using facet.prefix, but it does not work for multiple values.
--Jay
Solr support faceting by arbitrary queries as described here.
So, in your case you could get facet counts for only tv and DVD by the following query:
http://localhost:8983/solr/select?q=*:*&facet=true&facet.query=product:tv&facet.query=product:DVD
Related
I've noticed something curious with our SOLR 7 results.
We have faceting enabled on, for example, a manufacturer field.
When a search is performed for a particular manufacturer, the facet data will include a number of results for that manufacturer (in this case, 99 results). Also, all the facet results add up to match the total number of documents matching the query (which makes sense).
If a "blank" search is performed (resulting in a : query), all documents are returned from SOLR (~242,000). The facet results for the manufacturer field are no longer adding up to the total number of documents returned, however. It ends up being ~36,000 documents short. The specific manufacturer that I searched for in the prior example, which DID return a count of 99 in the facet data for that manufacturer, now returns nothing for that manufacturer. There is no facet result shown for that manufacturer.
If I query solr for the specific manufacturer value in the specific field we're faceting on, then it finds the 99 matches, and the facet data also shows the 99 results.
I think this problem is only happening when a : (or blank q) query is done.
Any suggestions?
Please let me know if you require more information.
Thanks,
Bill
I'm not sure I get your problem true but I suggest you some typical solution.
you can use "enum" facet method for huge facets.
facet.method=enum
Furthermore you need to control facet counts with:
facet.limit=10000 //maximum number of returned facets
facet.offset= 0
for more information about Solr facet params go to:
https://wiki.apache.org/solr/SimpleFacetParameters
Solr creates multi-select facet counts for me as described here:
https://web.archive.org/web/20131202095639/http://wiki.apache.org/solr/SimpleFacetParameters#Multi-Select_Faceting_and_LocalParams
I also have various predefined searches that allow a user to browse the catalog. Here is one such example and its query parameters:
q=*:*
fq={!tag=g}genre:western
facet=on
facet.field={!ex=g}genre
facet.mincount=1
facet.limit=50
With this search I get up to 50 genre values in the facet list. I then go through and mark which values were selected by the user; western in this case. This works well except when western is pushed out of the top 50. So I manually add it to the list to make a total of 51. This way the user can see that it is indeed selected. The problem is I have to leave the count for western blank because I don't know it.
Is there a way to get counts for specific facet values such as western in this case? Or another approach to solve this issue?
I am using Solr 4.7.0.
Solr allows you to create a query-based facet count by using the facet.query parameter. When creating a filter query (fq) that's based on a facet field value, I now create a corresponding facet query:
facet.query={!ex=g}genre:western
and add it to the rest of my parameters:
q=*:*
fq={!tag=g}genre:western
facet=on
facet.field={!ex=g}genre
facet.query={!ex=g}genre:western
facet.mincount=1
facet.limit=50
The facet_queries object will now be populated in the solr response:
{
...
"facet_counts": {
"facet_queries": {
"{!ex=g}genre:western": 7
},
...
},
...
}
Regardless of what is returned in the facet_fields object, I'm now guaranteed to have a facet count for genre:western. With some parsing, facet field counts can be extracted from the facet queries.
In Solr , I am fetching results using groupBy on "hash" ( my custom field ) field.
As we know each group will contains a set of documents.
My requirement is:
Solr first do a sorting based on score , that it is already doing.
If score of any two groups is same , then group with more number of documents should come up.
If even number of documents are same , then there should be some tie-breaker.
I need guidance for point 2 and 3. I am not able to get how to do it using 'sort' parameter.
Thanks
Amit Aggarwal
2)group with more number of documents should come up
There is no way to do it. Alternatively, you can use two queries to achieve this. Facets. They are, by default, sorted by numfound. And they loop through facet results to get results per facet.
I am not sure if this is possible or what's the best way to do it? How can I get facet count in Solr where it counts as in following example.
Let's say I have got following values equal to the number of times they repeat in a field..
Tv = 100
Sony Tv = 10
LG Tv=10
Nokia Mobile= 5
iPhone Mobile = 4
If a user query is 'tv & mobile'. Based on above values in a field, How can I get the facets like...
Tv (120)
Mobile (9)
Based on the comment you gave to Jayendra's answer, you want to leverage Solr MultiValued fields to store those values and then facet on that multiValued field. This would give you the behavior you want for faceting.
Additionally, if you want to limit the facet results to a specific set of values, you will to supply a facet.query along with your request to Solr.
You can index the data in hierarchy form and use Solr Pivots to implement this facet.
e.g. tv/sony, tv/LG, mobile/Nokia & mobile/iPhone
This would help you to facet over parent and further drill down on the same.
I am using SolrMeter to test Apache Solr search engine. The difference between Facet fields and Filter queries is not clear to me. SolrMeter tutorial lists this as an exapmle of Facet fields :
content
category
fileExtension
and this as an example of Filter queries :
category:animal
category:vegetable
categoty:vegetable price:[0 TO 10]
categoty:vegetable price:[10 TO *]
I am having a hard time wrapping my head around it. Could somebody explain by example? Can I use SolrMeter without specifying either facets or filters?
Facet fields are used to get statistics about the returned documents - specifically, for each value of that field, how many returned documents have that value for that field. So for example, if you have 10 products matching a query for "soft rug" if you facet on "origin," you might get 6 documents for "Oklahoma" and 4 for "Texas." The facet field query will give you the numbers 6 and 4.
Filter queries on the other hand are used to filter the returned results by adding another constraint. The thing to remember is that the query when used in filtering results doesn't affect the scoring or relevancy of the documents. So for example, you might search your index for a product, but you only want to return results constrained by a geographic area or something.
A facet is an field (type) of the document, so category is the field. As Ansari said, facets are used to get statistics and provide grouping capabilities. You could apply grouping on the category field to show everything vegetable as one group.
Edit: The parts about searching inside of a specific field are wrong. It will not search inside of the field only. It should be 'adding a constraint to the search' instead.
Performing a filter query of category:vegetable will search for vegetable in the category field and no other fields of the document. It is used to search just specific fields rather than every field. Sometimes you know that the term you want only is in one field so you can search just that one field.