Does it work for numeric fields too? I am working with 2.9.0 and the following code gives extra values:
@Test public void distinct() throws Exception { RAMDirectory directory = new RAMDirectory(); IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED); for (int l = -2; l <= 2; l++) { Document doc = new Document(); doc.add(new Field("text", "the big brown", Field.Store.NO, Field.Index.ANALYZED)); doc.add(new NumericField("trie", Field.Store.NO, true).setIntValue(l)); writer.addDocument(doc); } writer.close(); IndexReader reader = IndexReader.open(directory, true); TermEnum termEnum = reader.terms(new Term("trie", "")); Term next = termEnum.term(); List<Integer> ints = new ArrayList<Integer>(); while (next != null && next.field().equals("trie")) { ints.add(NumericUtils.prefixCodedToInt(next.text())); next = termEnum.next() ? termEnum.term() : null; } reader.close(); log.info(ints.toString()); } ==> [-2, -1, 0, 1, 2, -16, 0, -256, 0, -4096, 0, -65536, 0, -1048576, 0, -16777216, 0, -268435456, 0] Is there a way to make this work? Uwe Schindler wrote: > > You can get this list using IndexReader.terms(new Term(fieldname,"")). > This > returns an enumeration of all terms starting with the given one (the field > name). Just iterate over the TermEnum util the field name of the iterated > term changes. > > ----- > Uwe Schindler > H.-H.-Meier-Allee 63, D-28213 Bremen > http://www.thetaphi.de > eMail: u...@thetaphi.de > -- View this message in context: http://www.nabble.com/Distinct-terms-values--%28like-in-Luke%29-tp23470919p26056543.html Sent from the Lucene - Java Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org