Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.66 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to get a count of all the words in lucene index AFTER a search?
  2. IndexReader ir = new IndexReader(dirIndex);<br>
  3. TermEnum terms = ir.terms();<br>
  4.            while (terms.next()) {<br>
  5.                 String fieldCount = terms.term().field();<br>
  6.                 if (fieldCount.equals(field)) {<br>
  7.                     String[] contents = new String[2];<br>
  8.                     contents[0] = terms.term().text();<br>
  9.                     contents[1] = Integer.toString(terms.docFreq());<br>
  10.                     l.add(contents);<br>
  11.                 }<br>
  12.             }<br>
  13.             terms.close();<br>
  14. return l;  // l is a List of all words and freq in a Field...