lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mark harwood <markharw...@yahoo.co.uk>
Subject RE: Return all distinct values
Date Thu, 30 Mar 2006 09:34:37 GMT
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


Mime
View raw message