Search code examples
solrrequesthandler

SOLR 4.0: Get unique LONG fields in requestHandler code


I am writing a request handler for SOLR 4.0 and i am trying to get all unique values of a field of type tlong (field is indexed of course).

Whenever i try to get all unique terms for a tstring field i can simply use the following code:

DocTermsIndex sourceIndex=FieldCache.DEFAULT.getTermsIndex(searcher.getAtomicReader(), "txtField")      
TermsEnum terms=sourceIndex.getTermsEnum()

Then i can iterate over all unique terms, execute utf8ToString() on every term and it is working fine.

When i try to do the same for a tlong field i get garbled results - number of terms returned is different from the number of unique values and the values themselves do not represent Long in any way (different value lengths etc..).

Is there another way of obtaining a list of unique values for a tlong field?


Solution

  • Ok, i found it out. If anyone is interested: longs seem to use different type of encoding in Solr 4.0, so we can approach them as ordinary strings as in the code above but later we have to use a different parser to convert term value to long:

     FieldCache.NUMERIC_UTILS_LONG_PARSER.parseLong(term)
    

    It seems to throw an exception when no more elements are present. As for now it is working fine.