I've been experimenting with Solr (5.2.1) groups and stats and I am getting nowhere. I have a bunch of documents grouped by a key. I am returning the groups in my results and I want to return the minimum value of a field for each group. Note that I ONLY need it for the groups being returned in the search query.
I am able to get the stats component working, however it just returns the results for all groups; like regular facets.
Here is the query:
facet=true&stats=true&stats.field={!tag=t1}pr&facet.pivot={!stats=t1}groupid
I also tried to use stats.facet component without any luck. Am I missing something here or is this not in Solr?
For example, you have following fields
id, name, category, score
11,name1,A,1
22,name2,A,2
33,name3,B,1
44,name4,B,2
55,name5,B,3
Then you can group based on category, and inside group, you can get stats based on field score.
q=*%3A*&fl=count&wt=json&indent=true&facet=true&stats=true&stats.field={!tag=t1}score&facet.pivot={!stats=t1}category
Results would be like
"facet_counts":{
"facet_queries":{},
"facet_fields":{},
"facet_dates":{},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{},
"facet_pivot":{
"sentiment_cat":[{
"field":"sentiment_cat",
"value":"SECOND",
"count":3,
"stats":{
"stats_fields":{
"sentiment_score":{
"min":1.0,
"max":3.0,
"count":3,
"missing":0,
"sum":6.0,
"sumOfSquares":14.0,
"mean":2.0,
"stddev":1.0}}}},
{
"field":"sentiment_cat",
"value":"FIRST",
"count":2,
"stats":{
"stats_fields":{
"sentiment_score":{
"min":1.0,
"max":2.0,
"count":2,
"missing":0,
"sum":3.0,
"sumOfSquares":5.0,
"mean":1.5,
"stddev":0.7071067811865476}}}}]}}
As you can see, min, max, sum are done on score field. This is the capability of facet and stat. let me know, if you need something different from above
Related
I am looking for possibility to apply filter on group in Solr. It means that if at least one of documents in group isn't restricted by filter entire group should be displayed in search results. Moreover I need apply Solr filter on document to filter documents inside group. For example, I have following documents and group it by baseProductCode:
group test1
Test1VariantProduct1
restrictedCountries: US
type: ebook
baseProductCode: test1
Test1VariantProduct2
type: paperbook
baseProductCode: test1
In this example I need to apply filter on document by restrictedCountries field and filter on group by type. It means that I would like to filter document with restricted countries and it could be implemented using fq=-countries=US. From the other hand I want to hide group from search result by type if all group documents are hidden. As result I want following cases will be valid:
Our system shouldn't display this group in search results for US country and ebook type.
Our system should display this group in search results for any other country and ebook type.
Could you please advice is it possible to implement it using Solr features?
If you're using faceting to get your groups, they'll work with the set of documents after they've been filtered, so the groups won't be shown if there are no documents that matches from that group (i.e. you'd be faceting on baseProductCode).
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 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 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.
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.