lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Scanlon <jscan...@element115.net>
Subject Re: "GROUP BY" query
Date Sun, 02 Jan 2011 01:24:48 GMT
Something like this works pretty well

public static Map <String, Integer> getFullTerms(IndexReader ir, String
fieldName, IndexSearcher is) throws IOException{
   Map<String,Integer > termMap = new LinkedHashMap<String,Integer>();
          TermEnum terms = ir.terms(new Term(fieldName, ""));
          while (fieldName.equals(terms.term().field()))
          {
         // System.out.println(terms.term().text());
           termMap.put(getCatName(terms.term().text(), ir, is),
terms.docFreq());
             System.out.println("Unique category ids: " +terms.term().text()
+ " catname: "+getCatName(terms.term().text(), ir, is)+" shows up in this
many docs: "+ terms.docFreq());
              if (!terms.next())
                  break;
          }
          return termMap;
   }

On Sat, Jan 1, 2011 at 4:32 PM, Benzion G <benzionk@yahoo.com> wrote:

> Lets' say I have documents with following.
>
> id    text
> 1     User not found
> 2     User not found
> 3     Address not found
> 4     Fatal error
> 5     User not found
> 6     Address not found
> 7     User not found
>
>
> How can I get each text only once in search results (similar to SQL "GROUP
> BY"),
> i.e.
>
> id    text
> 1     User not found
> 3     Address not found
> 4     Fatal error
>
>
> Regards,
> Benzion.
>
>
>




-- 
Joe Scanlon

jscanlon@element115.net

Mobile: 603 459 3242
Office:  312 445 0018

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message