Is there a way to get the count of different facets in solr?
This is an example facet:
Camera: 20
Computer: 80
Monitor: 40
Laptop: 120
Tablet: 30
What I need to get here is "5" as in 5 different electronic items. Of course I can count the facet but some of them have many items inside and fetching and counting them really slow it down.
You need to apply Solr Patch SOLR-2242 to get the Facet distinct count.
In SOLR 5.1 will be a "JSON Facet API" with function "unique(state)".
http://yonik.com/solr-facet-functions/
Not an exact answer to this question, but if facet distinct count doesn't work for anyone, you can get that information using group.ngroups:
group = true
group.field = [field you are faceting on]
group.ngroups = true
The disadvantage of this approach is that if you want ungrouped results, you will have to run the query a second time.
Of course the patch is recommended, but the cheesy way to do this for a simple facet, as you have here, is just to use the length of the facet divided by 2. For example, since you are faceting on type:
facetCount = facet_counts.facet_fields.type.length/2
Use this GET request:
http://localhost:8983/solr/core_name/select?json.facet={x:"unique(electronic_items)"}&q=*:*&rows=0
Related
I am working with Solr and I have a issue. It is:
I use query to get results in Solr and the results are not my expectation. The query is : product_id: ("2" OR "3" OR "1") and the order of results do not like the order I input in query. maybe it's 1-2-3 or 3-2-1. The order of results I expect is as same order as I query 2-3-1.
So are there solution to solve it?
Sure, boost each term with a differnt, decreasing value, for example:
q=product_id:2^10 3^5 1
Look the specifics on the docs
I am running Solr 4.10.3 and trying to resort top 10 documents come from Solr. How can i do that? I am thinking of sub-query but don't know how to do that, needed help.
Example:
Suppose on query of "car" Solr return 250 documents on the basis of high score of relevancy. Now from 250 documents take top 10 documents and resort them on the basis of custom field.
i can't do that:
select?q=car&sort=score desc, pr desc
Because it will do sorting on entire 250 documents. So is there any solution?
I think you mean query reranking ? This is what is used when you want to:
use a first, more lightweight query to get a result based on the score
get a fair top x number of matches, like 2000 for example
use a heavier query to resort only those again, to get the final score
That is what you need to use if you want to do it in two steps, like you state. Now, I am not sure you need to use query reranking for your use case, maybe just boosting by that field, or sorting on a function should be enough for you.
I'm trying to find a solution to make a subfacet list for some facets.
I have a clothes size on some products and they are stored in solr
"Size_both":"W30L30",
"Size_width":"W30",
"Size_length":"L30"
I wish to generate a list of subfacet for each width:
W30 (8)
L30 (3)
L32 (1)
L33 (4)
W32 (2)
L30 (1)
L34 (1)
etc
Anyone know how to accomplish this? I thought I could do this with group, but that didn't work.
Solr pivot faceting should do what you are asking for. If it does, you may want to be more precise on what specifically fails.
Use Facet Pivoting to achieve desired result:
Facet Pivoting
Try Below Query:
http://<host_name>:<port>/solr/<core_name>/select?q=*:*&rows=20&wt=json&indent=true&facet=true&facet.pivot=Size_width,Size_length
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.
Say I want to fetch all users who belong to org number 2 and the have the string "baba" in them. I can do either:
q=baba AND org:2
OR
q=baba&fq=org:2
I am not sure what is the difference. Can some one shade some light.
A filter has no effect on scoring, it just does the filtering part. Filters are also more performant in situations where a) the number of matching docs is high and 2) the results are often reused.
filtering also allows tagging of facets.
you can tag facets to include all facets that are returned for your query, not taking into account the FQ.
For exmaple in you post if you returned org as facets and there were 10 with value 1 and 10 with value 2, the "q=baba AND org:2" would return facets with q 2(10), but if you did q=baba&fq=org:2 and tagged the facet you would get facets with q 1(10) 2(10).
Hope that makes sense