Naijaba
Naijaba

Reputation: 1029

Solr total term frequency for multiple terms

I'm using the following query to get the total number of times the word "apple" appears in the "text" field:

/solr/collection1/select/?q=text:apple&fl=totaltermfreq(text,apple)&rows=0&omitHeader=true

<response>
    <result name="response" numFound="152322" start="0"/>
</response>

query time: 12 milliseconds

I have a dozen such queries (e.g. "orange", "pear", "banana", etc). Each query runs very fast (~10-20 milliseconds), but I'm having to send them individually. I'd like to send them all at once.

I've tried using Solr Terms Component with a regular expression, but it takes over a minute just for one term:

/solr/terms?terms.fl=text&terms.regex=apple&omitHeader=true

<response>
    <lst name="terms">
        <lst name="text">
            <int name="apple">152322</int>
        </lst>
    </lst>
</response>

query time: 69866 milliseconds

It'd be great if I could pass multiple terms to the total term frequency function query. Ideas?

Upvotes: 4

Views: 1419

Answers (1)

MatsLindh
MatsLindh

Reputation: 52902

Query for all the documents using *:* and add a function query to the field list for each term you want to extract the total number of terms for:

?q=*:*&fl=ttf(text,apple),ttf(text,banana),ttf(text,pear)&rows=1

Upvotes: 4

Related Questions