-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Lucene, Getting all values and hits for a specific field
PostPosted: Wed Jan 14, 2009 7:32 pm 
Newbie

Joined: Wed Jan 14, 2009 7:25 pm
Posts: 5
Hello All,

I am using lucene to index my entities and I want to get the whole indexed values and their hits for a specific field of my class.

for example I have a Car class which has an indexed column named brand, I want to get all indexed brand names and their hits. is there a way to do it in my DAO using lucene?

Thanks and regards.

edit: To be more clearer, if I have 3 cars like, ferrari, mercedes and copy ferrari, I want to get the following data somehow

2 ferrari
1 copy
1 mercedes


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 9:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I assume you are using Hibernate Search and not pure Lucene, right? If so it would help if you would share your entity and any other configuration.

Trying to give you an answer anyways - you can definitely use your problem with Lucene. However, probably not in one query. Depending on your data it might in fact be better to do some sort of HQL query.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 9:42 am 
Newbie

Joined: Wed Jan 14, 2009 7:25 pm
Posts: 5
Hi Hardy,

yes I am using hibernate-search. what I have tried was something like this:

Map<String,Integer> hits = new HashMap<String,Integer>();
IndexReader reader = IndexReader.open( getDirectory() );
TermEnum terms = reader.terms( new Term( field, "" ) );

while( field.equals( terms.term().field() ) ){
hits.put( field, terms.docFreq() );
}

but it does not seem working.

I am using hibernate-search 3.1.0.GA by the way.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 10:34 am 
Newbie

Joined: Wed Jan 14, 2009 7:25 pm
Posts: 5
Hello again,

it is my mistake, it is working with the following code:

public Map<String,Integer> getAllHits(String field) {
Map<String,Integer> hits = new HashMap<String,Integer>();
IndexReader reader = IndexReader.open( getDirectory() );
TermEnum terms = reader.terms( new Term( field, "" ) );

while( field.equals( terms.term().field() ) ){
hits.put( terms.term().text(), terms.docFreq() );

if( !terms.next() )
break;

}
}

Yigit.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2009 10:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Seems like a legit way of doing this :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.