#community-help

Displaying Paginated List of Distinct Cities from Documents

TLDR gab was struggling to paginate a list of distinct cities in documents. Kishore Nallan suggested to use the group_by command, and adjusting group_limit to display only a single document per city.

Powered by Struct AI
9
18mo
Solved
Join the chat
Apr 19, 2022 (18 months ago)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
10:22 AM
Hi,
I have documents with a "city" facet field.
I would like to display paginated list of cities.
How could I browse all cities ? (page 1: 20 groups, page 2: 20 groups, etc)
Also I don't want hits for each groups.

I also tried with facet_by but it doesn't seem to be the proper way of doing it.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:25 AM
Looks like you want to show unique list of cities across all documents?
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
10:25 AM
yes
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:26 AM
Have you tried to do group_by of cities?
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
10:29 AM
Yes I'm trying with group_by but:
• I wonder if I'm browsing groups or documents using per_page/page
• Also I cannot remove hits from results. I tried with limit_hits:0 (Also with "group_limit":1)
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:37 AM
The actual group results won't matter for you: need to just look at the group keys.
10:38
Kishore Nallan
10:38 AM
You can set group_limit: 1 to limit to just a single doc per group.
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
10:50 AM
Thanks,
it seems so far I can browse properly
{
            "collection": "warehouses",
            "query_by": "name",
            "per_page": 20,
            "page":"1",
            "group_by": "city",
            "q":"",
            "sort_by":"city:asc",
            "group_limit": 1,
        }
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:53 AM
😎