Solr facet counts for specific field values - solr

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.

Related

SOLR Faceting not returning all facets when searching for "All" (*:*)

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

Filter on the list of facet values

I have a 'keywords' field in my index, which is Facetable, and of type Collection(Edm.String).
In my UI I show a facet for this fields which returns the top 10 keywords.
The total number of distinct keywords value may be many hundreds.
So I would like the user to be able to enter a term, and the top 10 facet values containing this term would be returned.
So this is kind of filtering the list of facet values for a field.
Is this currently possible with Azure Search API ?
No, this is not supported. It's possible to filter the set of documents returned, which will influence the facets that are returned, but there is no way to directly filter the facet values themselves using a search expression or "contains" semantics.
You could filter on your keywords field, but then you'd only get the matching facet value, not the top 10 facet values that contain a search term.

dynamic fields as facet in solr

I am trying to develop a filter system using dynamic fields in solr. These dynamic fields may vary from product to product and have a prefix attribute_filter_ to help me recognize the filter field. So given a search query, I want to get faceted results based on these dynamic fields.
For example, I have 3 products as docs in solr
{ID:1, attribute_filter_color:"white", attribute_filter_brand:"Dell"}
{ID:2, attribute_filter_color:"red", attribute_filter_category:"electronics"}
{ID:3, attribute_filter_size:"mobiles", attribute_filter_brand:"samsung"}
When my search query matches doc 1 and doc2, I want only filters color, brand and category and so facet fields are attribute_filter_color, attribute_filter_brand and attribute_filter_category.
When my search query matches doc 2 and doc3, I want filters color, size, category and brand and so facet fields are attribute_filter_color, attribute_filter_size, attribute_filter_category and attribute_filter_brand.
When my search query matches doc 1 and doc3, I want filters color, brand and size and so facet fields are attribute_filter_color,attribute_filter_brandand attribute_filter_size.
Also these filters can be ~300 total over 10^5 products. This creates another problem for making a GET URL with 300 facet fields which might cross the limit for GET URL.
This jira ticket shows how regex could have helped in this situation.
My solution would be to index the field names to an additional field, so that you have "facet_fields": ["attribute_filter_color","attribute_filter_brand"] for the documents containing the fields as well.
Generate a facet across your document result set, then use that result in a new query to generate facets across the fields you're interest in. It will be an extra query, but should scale decently. The part that will be expensive will be the larger number of different fields you're faceting on anyway - the facet_fields field will be quick to calculate and return.

Solr group.facet=true will not return facet counts

As the title states, I can't get facet values or counts to return when using the group.facet=true parameter. group.truncate appears to return the correct values, but that's not what I'm looking for.
I started with the Solr 4 alpha, then Beta, and I'm now working on the nightly build from 9/5/2012.
I'm grouping by a single value field. The fields I am faceting on are a mix of single and multi value fields. I've simplified my query here MyFacetField represents a single value field.
Here are the grouping parameters:
group.field=GroupField
group.ngroups=true
group.facet=true
group=true
Facet set up like this:
f.MyFacetField.facet.limit=-1
f.MyFacetField.facet.mincount=1
f.MyFacetField.facet.sort=false
facet.field=MyFacetField
facet=true
Match all documents:
q:*:*
Again, my problems is:
When I specify group.facet=true I get the list of facet fields I specified in the request paramaters with no values and no counts.
WHen I specify group.facet=false (or leave the parameter out) I get facet values and counts for the ungrouped result set as expected.
According to the wiki this feature is included in solr4.
It turns out that the issue was in this parameter.
f.MyFacetField.facet.limit=-1
When limit is set to -1 (all) and group.facet=true, facet values and their respective counts are not returned by solr. I'm not sure if this is intended behavior, or not. This doesn't appear to be a requirement of truncate or of faceting in general with group.facet=false.

Difference between Solr Facet Fields and Filter Queries

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.

Resources