This feels like basic faceting on category, but you are trying to make
a latest record, rather than count as a sorting/grouping principle.

How about using JSON Facets?
https://lucene.apache.org/solr/guide/8_8/json-facet-api.html
I would do the first level as range facet and do your dates at
whatever granularity (say 1 week?) and then second level category
terms.

Let us know if it works. It is an interesting question.

Regards,
   Alex.

On Fri, 5 Feb 2021 at 08:18, Hullegård, Jimi
<jimi.hulleg...@svensktnaringsliv.se> wrote:
>
> Hi,
>
> Say we have a bunch of documents in Solr, and each document has a multi value 
> field "category". Now I would like to get the N most recently used 
> categories, ordered so that the most recently used category comes first and 
> then in falling order.
>
> My simplistic solution to this would be:
>
> 1. Perform a search for all documents with at least one category set, sorted 
> by last modified date
> 2. Iterate over the search results, extracting the categories used, and add 
> them to a list
> 3. If we have N number of categories, stop iterating the results
> 4. If there isn't enough categories, go to the next page in the search 
> results and start over at step 2 above, until N categories are found or no 
> more search results
>
> But this doesn't seem very efficient. Especially if there are lots of 
> documents, and N is a high number and/or only a handful of categories are 
> used most of the time, since it could mean one has to look through a whole 
> lot of documents before having enough categories. Worst case scenario: N is 
> higher than the total number of unique categories used, in which case one 
> would iterate over every single document that has a category.
>
> Is there a way one can construct some special query to solr to get this data 
> in a more efficient way?
>
> Regards
> /Jimi
>
> Svenskt Näringsliv är företagsamhetens röst i Sverige. Vi samverkar med 50 
> arbetsgivar- och branschorganisationer och är den gemensamma rösten för 60 
> 000 företag med nästan 2 miljoner medarbetare. Vår uppgift är att tala för 
> alla företag och branscher, även de som ännu inte finns men som kan uppstå om 
> förutsättningarna är de rätta. Ett bättre företagsklimat för ett bättre 
> Sverige. Det är vårt uppdrag.
>
> Svenskt Näringsliv behandlar dina personuppgifter i enlighet med GDPR. Här 
> kan du läsa mer om vår behandling och dina rättigheter, 
> Integritetspolicy<https://www.svensktnaringsliv.se/dataskydd/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email>

Reply via email to