I'm having some trouble understanding facet result...
# community-help
p
I'm having some trouble understanding facet results. Need to figure out a way to create a test suite for you to test if needed. For a search query, without
facet_by
or
group_by
typesense fetches 57 hits (
found: 57
). I add a
facet_by=author
and
group_by=author
. My expectation was that the "`found`" count would remain the same and just the results count will be facet'ed between the values in the "author" field. There are 2 distinct "author" field values. The facet counts show a count of 1 for each author field value. "found" also shows only 2 instead of 57 without the facet_by and group_by search query, but the number of documents are 3 each for the 2 authors. So i'm having bit of hard time understanding how to interpret the search results between both cases. Any help would be appreciated. Thanks.
k
On grouping the counts will now be based on the groups, and not the individual documents.
p
Thanks for the quick response. I assumed so. I guess the other count that I need to understand better is the
facet_counts
>
counts
array. There are 2 elements in the array, which is fine given there are 2 distinct values for the
author
field. However each element of the
counts
array shows a
count:1
.I was expecting this to have counts like a SQL equivalent of
select author, count(document.id) from collection group by author
.
k
I think it will be great if you can put together a small example using
curl
snippets so that it's easy for us to reference things.
p
Will do. Thanks.
I have tried to capture test case and my interpretation at https://gist.github.com/prabhur/e1abae978f7f299f27c1d4a34b54351d. Hope this helps.
k
Thanks for putting that together. Facet counts happen on the grouped results because that's what makes sense most of the times. Imagine a ecommerce store selling multiple variants of the same product. When you do a group_by on the product_id, you want the facets to be applied only on the groups (i.e. the product and it's variants form a unified group).
p
Hmm..thanks for the explanation. I'm just rethinking what I'm trying to achieve in my case. I guess my objective is - given a search term, • get a list of articles from all authors in my collection. • Organize the results by author with a suggested count of hits by each author. I guess, I'll get the counts from within the
grouped_hits
itself. Alternatively, will rethink my whole approach. Thanks for the quick explanation!
👍 1
k
@Prabhu Ravichandran We will be happy to consider this as a feature request (maybe via a new parameter that specifies the behavior for counts). Can you please open a Github issue with the example above?
p
Will do! Thanks.