-->
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.  [ 3 posts ] 
Author Message
 Post subject: Search text for tokens from 3 fields
PostPosted: Sat Nov 07, 2009 8:47 am 
Newbie

Joined: Tue Aug 04, 2009 6:46 am
Posts: 17
hi all,
i have a table Sample containing fields menu1, menu2, menu3 and some more columns

Sample table :

id Menu1 Menu2 Menu3 other columns
------------------------------------------------------------------------------------------
1 java oracle sap
2 accounts finance administration
some more rows follows..

i have indexed 3 fields (menu1, menu2, menu3)

so when a story(containing 100 to 200 words) containing all the 3 words java, oracle, sap comes i want to fetch the first row from database

(Example: some text here java some more text here sap some more text oracle and some more text)

For this i have implemented the following 2 ways but unfortunately none of them is working:

CASE 1:
QueryParser parser1 = new QueryParser("menu1", new WhitespaceAnalyzer());
org.apache.lucene.search.Query query1 = parser1.parse(Story);
QueryParser parser2 = new QueryParser("menu2", new WhitespaceAnalyzer());
org.apache.lucene.search.Query query2 = parser2.parse(Story);
QueryParser parser3 = new QueryParser("menu3", new WhitespaceAnalyzer());
org.apache.lucene.search.Query query3 = parser3.parse(Story);
BooleanQuery bq = new BooleanQuery();
bq.add(query1, Occur.MUST);
bq.add(query2, Occur.MUST);
bq.add(query3, Occur.MUST);
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(bq, Sample.class);
List list = hibQuery.list();

CASE 2:
String[] fields = {"menu1", "menu2", "menu3"};
Occur[] occur = new Occur[3];
occur[0] = Occur.MUST;
occur[1] = Occur.MUST;
occur[2] = Occur.MUST;
org.apache.lucene.search.Query query = MultiFieldQueryParser.parse(story, fields, occur, new WhitespaceAnalyzer());
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Sample.class);
List list = hibQuery.list();

in both cases iam getting no errors, and also no results for the text
some text here java some more text here sap some more text oracle and some more text

can any one tell what iam doing wrong here
Thanks a lot,
Bye


Top
 Profile  
 
 Post subject: Re: Search text for tokens from 3 fields
PostPosted: Tue Nov 10, 2009 6:01 am 
Newbie

Joined: Tue Aug 04, 2009 6:46 am
Posts: 17
hi all,

I have got the results
My mistake was i have deleted the index and searching for the results
no problem with the code

Now i am getting the results

Bye


Top
 Profile  
 
 Post subject: Re: Search text for tokens from 3 fields
PostPosted: Tue Nov 10, 2009 6:12 am 
Hibernate Team
Hibernate Team

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

the following might not be a direct answer to your question, but maybe it helps you to figure out what's going on.
First, are you sure you want to use a WhitespaceAnalyzer? This only splits tokens at white spaces and does not for example lowercase the text. Either way, you have to make sure that you are using the same analyzer for indexing as well as searching. Are you also using a WhitespaceAnalyzer for indexing?

Also, what is your actual usecase? Your example seems somehow back to front. You have single values in the database and your query is a story? That said, I would expect that you get a result for both queries if you pass your example query. Both of your generated queries translates into something like this:
+(menu1:<story>) +(menu2:<story>) +(menu3:<story>)

Have you inspected your generated index with Luke? How do your annotated entities look like?

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.