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.
Related
I have applied solr facet on properties of products.
Eg: The product can be either Medicine(0/1) or Drug(0/1) or Poison(0/1).
0 means NO, 1 means YES.
These are different features of a product hence appear as different facets. It is possible to display them under one facet instead eg: "Type", under which these three solr facet "Medicine", "Drug", "Poison" should display like:
Type
-----
Medicine (50)
Drug (100)
Poison (75)
Not sure about Hybris, but you should be able to do so with facet queries. You would have one facet query per each of your three conditions. In the UI, you can organize the counts anyway you want.
However, I am not sure why you can't just have a category field that contains a multi-valued field that contains Medicine and/or Drug and/or Poison value. Then faceting on that field would give you the breakdowns. If your values do not come in that way, you can probably manipulate them either with copyField or with a custom Update Request Processor chain to merge into one field.
This is super easy. Just make an IndexedProperty "Type" and a new custom ValueProvider for it. Then extract these values based on the boolean flags - just hard code if necessary. No need for anything more complex.
I tried the solutions posted here but they were not fitting my requirement. I did changes through facet navigation tag files to bring all classification attribute facets (Medicine, Drug, Poison) under a single facet (Type).
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.
I have integrated Solr 4 for e-commerce application. And offers a facet filters like flipkart on category pages. Filters works fine, however, the facets has min count set to 1, so facets with zero count are not returned by Solr.
Now, I want to display those with zero count like displayed here in this image.
However, just like in this image, Screen Size can be present in other category as well, so in this case instead of displaying only those options presents for this category it displays all options which are no applicable for the this current category.
So, it lists all the facets as zero even if they have nothing to do with this category. My problem is I want to display only those facets which are available if there no filters applied and then display them greyed out when they are no longer applicable.
Any clue how to do this?
One thing you can try is getting the facets with and without the filter within the same query.
Check Multi-Select_Faceting_and_LocalParams
Return the Same facet with and without exclusion
If No filters they would be same.
If filter applied, the Normal facet will have filtered Facets and exclusion facet will have facets without the filter. fq={!tag=dt}doctype:pdf&facet=on&facet.field={!ex=dt}doctype&facet.field=doctype
Compare at Client side for the differences and display accordingly.
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.