lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@lucene.com>
Subject Re: How to get field contents
Date Fri, 13 Jun 2003 17:27:31 GMT
This can be done more efficiently if you only want to enumerate the 
terms of a particular field.  Term enumerations are ordered first by 
field, then by the term text.  You can also specify the initial position 
of a term enumeration.  Thus an efficient enumeration of the terms in 
"myField" can be done with something like:

   IndexReader reader = IndexReader.open("index");
   TermEnum te = reader.terms(new Term("myField", ""));
   while (te.term() != null && "myField".equals(te.term().field())) {
     ... do something silly ...
     te.next();
   }

Doug


Neil Couture wrote:
> As far as I know you will have to go throught the index and verify the 
> field field (that is not an error) of each term:
> 
> 			IndexReader reader 	= IndexReader.open("index");
> 			TermEnum 	te 		= reader.terms(); 
> 			
> 			while ( te.next() ) {
> 				
> 				Term tt = te.term();
> 				
> 				String fieldOfTerm = tt.field();
> 				
> 				if ( fieldOfTerm.compareTo( "contents" ) ) {
> 
> 					do_something_silly()...
> 				
> 				} else if ( fieldOfTerm.compareTo( "path" ) ) {
> 
> 					do_something_silly2()...
> 				}
> 			}
> 
> 
> -neil
> 
> 
> 
> 
> -----Original Message-----
> From: Ulrich Mayring [mailto:ulim@denic.de]
> Sent: 13 juin, 2003 08:14
> To: lucene-user@jakarta.apache.org
> Subject: How to get field contents
> 
> 
> Hello,
> 
> I'd like to build a list with all values from a certain field that occur 
> in an index. Looking at the API, there's a method getFieldNames(), but I 
> already know the field name, I want to get a list of all the values. 
> Also, I can enumerate fields by giving Terms, but a Term means I have to 
> have the field name and value.
> 
> Can this be done?
> 
> Kind regards,
> 
> Ulrich
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 


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


Mime
View raw message