4

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?

Naijaba
  • 1,019
  • 1
  • 13
  • 24

1 Answers1

4

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
MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • Great! Thanks for the quick reply. For future visitors, the numbers I reported above are the number of documents containing the term "apple", not the number of times the word apple occurs. This solution gets what I wanted...and incredibly fast. – Naijaba Aug 13 '14 at 18:56