lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Volodymyr Bychkoviak <vbychkov...@i-hypergrid.com>
Subject Re: Return all distinct values
Date Thu, 30 Mar 2006 09:40:48 GMT
There is one little note. If index has deletions then counters could 
have wrong values...

mark harwood wrote:
> This example code gets the unique terms for a field
> and a total num docs for each...
>
> String fieldName="myfield";
> valueCounts=new ArrayList();
> TermEnum termEnum;
> termEnum = indexReader.terms(new Term(fieldName,""));
> Term term = termEnum.term();
> while (term!=null)
> {
> 	if (!fieldName.equals(term.field()))
> 	{
> 		break;
> 	}
> 	valueCounts.add(new ValueCount(term.text(),
> termEnum.docFreq()));
> 	if(!termEnum.next())
> 	{
> 		break;
> 	}
> 	term=termEnum.term();			
> }
>
> class ValueCount implements Serializable
> {
> 	String value;
> 	int docCount;
> 	public ValueCount(String value,int docCount)
> 	{
> 		this.value=value;
> 		this.docCount=docCount;
> 	}
> }
>
>
>
> 	
> 	
> 		
> ___________________________________________________________ 
> Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>   

-- 
regards,
Volodymyr Bychkoviak


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message