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 Java Programmer <jp...@gmail.com> on 2006/03/30 11:05:54 UTC

Return all distinct values

Hello,
I created small Lucene's application which stores lot of my users
infomation, on of it is zipcode in numeric format eg. 50501, 63601 -
zip codes are stored in Text fields so they are fully searchable what
I want now to do is getting all unique zipcodes which was stored so
far. Something like SQL: select distinct zipcode from ...
Is it possible?

Best regards,
Adr

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


RE: Return all distinct values

Posted by Pa...@saaconsultants.com.




The IndexReader.terms() method gets a list of all the terms in an index.
You need to somehow limit this to the terms for your ZipCode field which I
don't know how to do. Luke has the ability to do this though so it is
certainly possible.

Regards

Paul I.


                                                                           
             "Ramana Jelda"                                                
             <ramana.jelda@cia                                             
             o-group.com>                                               To 
                                       <ja...@lucene.apache.org>       
             30/03/2006 10:21                                           cc 
                                                                           
                                                                   Subject 
             Please respond to         RE: Return all distinct values      
             java-user@lucene.                                             
                apache.org                                                 
                                                                           
                                                                           
                                                                           
                                                                           




Hi,
Actually lucene does not provide you a straight forward  Query to get
UNIQUE
results.
But as far as I know, u can use HitsCollector & BitSet combination to
count/get unique results.

Regards,
Jelda

> -----Original Message-----
> From: Java Programmer [mailto:jprogramista@gmail.com]
> Sent: Thursday, March 30, 2006 11:06 AM
> To: java-user@lucene.apache.org
> Subject: Return all distinct values
>
> Hello,
> I created small Lucene's application which stores lot of my
> users infomation, on of it is zipcode in numeric format eg.
> 50501, 63601 - zip codes are stored in Text fields so they
> are fully searchable what I want now to do is getting all
> unique zipcodes which was stored so far. Something like SQL:
> select distinct zipcode from ...
> Is it possible?
>
> Best regards,
> Adr
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>


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




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


Re: Return all distinct values

Posted by Volodymyr Bychkoviak <vb...@i-hypergrid.com>.
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


RE: Return all distinct values

Posted by mark harwood <ma...@yahoo.co.uk>.
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


RE: Return all distinct values

Posted by Ramana Jelda <ra...@ciao-group.com>.
Hi,
Actually lucene does not provide you a straight forward  Query to get UNIQUE
results.
But as far as I know, u can use HitsCollector & BitSet combination to
count/get unique results.

Regards,
Jelda

> -----Original Message-----
> From: Java Programmer [mailto:jprogramista@gmail.com] 
> Sent: Thursday, March 30, 2006 11:06 AM
> To: java-user@lucene.apache.org
> Subject: Return all distinct values
> 
> Hello,
> I created small Lucene's application which stores lot of my 
> users infomation, on of it is zipcode in numeric format eg. 
> 50501, 63601 - zip codes are stored in Text fields so they 
> are fully searchable what I want now to do is getting all 
> unique zipcodes which was stored so far. Something like SQL: 
> select distinct zipcode from ...
> Is it possible?
> 
> Best regards,
> Adr
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 


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