You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by JM Tinghir <jm...@gmail.com> on 2005/07/26 19:29:09 UTC

Querying the values of a field

Hi,

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.

Thanks in advance,
Jean-Marie Tinghir

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


Re: Querying the values of a field

Posted by Chris Hostetter <ho...@fucit.org>.
: 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