I need to a faceted search on a particular column and drill down within its results.
Here is my schema.
State ZipCode PersonName
CA 12345 Tom
CA 12345 Mike
CA 23458 John
CA 23458 Lucy
I tried writing a facet query
http://localhost:8983/solr/query?facet=on&facet.field=State and it facets only based on State.
How do I include Zip code within it, so that I can drill down based on State & Zip code
You can do this two ways, depending on what you want.
If you just want to include a ZipCode facet as well, in addition to the State facet, add another facet.field parameter: &facet.field=ZipCode. That way you'll get facets for both fields in your response. The facets will be modified depending on your query results and filter queries, so if the user selects a State first, the fq= will make the ZipCode facet only return facet values within that state. You might also want to look at Tagging and excluding filters, if you want to show a count of all States, regardless of one being chosen at the moment.
Another option is to use facet.pivot to get a two-dimensional table with facet values; for each state, get the count of the zipcodes in that state. &facet.pivot=State,ZipCode.
Related
I have a field country. I need to do a search in which I need to show the search result of a country or some countries last in the search result for eg. for country code BD. What query should I use to get the above result.
The key is to do the opposite - instead of trying to move the documents matching the country further down, boost everything that doesn't match the country up:
q=(*:* -country:BD)^999
This can also be applied as a boost query (bq) with the edismax handler.
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).
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.
I am experimenting with Solr Facets. I imported my DB
pseudo:
item colorName colorID
ball red 1
plate red 1
table blue 2
Now, when I display the facet on the site, I instinctually want to have both colorName and colorID in my json, however the Solr Fusion interface and all the documents I have read the last several hours tell me I can only do either {Colorname, count} or {colorID, count} where I actually want { colorID,ColorName, count}. I dont have a real reason actually but coming from the old times, I couldn't feel comfortable with just a name or id and not both...
Facets are meant to be simple key => value pairs, with the key being your facet.field and the value being the number of documents that fall under that facet. The idea is to be able to give users a broad overview of various categories, along with the number of items available in that category. From there, you can use filter queries to drill down further into the data.
Your best bet in your example is to facet on multiple fields. For example:
/select?q=field_name%3APIN&rows=0&wt=json&indent=true&facet=true&facet.field=unique&facet.field=manufacturer_id
And then filter on whatever combination you need.
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.