lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: Querying the values of a field
Date Sun, 31 Jul 2005 07:17:52 GMT
: I have an index with about 20 different fields.
: I'd like to query my index to get the list of all different terms for
: a given field.
: Is it something possible in a simple way? I mean simpler than getting
: every terms of the index and then keeping only those which match the
: given field.

I'm guessing you are refering to using a TermEnum to iterate over all the
terms in the index.  The two key aspects of a TermEnum that you should
allways remember are:

1) when you get one from an IndexReader, you can specify a "starting Term"
and be garunteed that the first Term returned by the TermENum willl either
be that term, or some "later" Term (look at IndexReader.terms(Term))

2) TermEnums allways iterate in Term order, which is Field order then
value order.  so if you are iterating over a bunch of terms, and the field
of the Terms changes, then you are garunteed that there are no more Terms
using the old field (look at the javadocs for TermEnum and Term.compareTo)

Which means something like this (untested psuedocode) should be usefull...

	String f = "myField";
	List allInFieldF = new LinkedList();
	TermEnum e = r.terms(new Term(f, ""));
	while (e.next() && e.term().field().equals(f)) {
		allInFieldF.add(e.term().text());
	}


-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message