-->
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.  [ 2 posts ] 
Author Message
 Post subject: Multifielded Query question
PostPosted: Wed Dec 16, 2009 5:00 am 
Newbie

Joined: Wed Dec 16, 2009 4:35 am
Posts: 1
Hi everybody, I'm new to Hibernate Search and have the following problem I need to solve:

I currently do the following multifielded query, which works fine:

Code:
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{"name", "album.title", "artists.name", "genres.genre"}, new StandardAnalyzer());
try {
    Query query = parser.parse(queryString);
    org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Song.class);
    return hibQuery.list();
} catch (org.apache.lucene.queryParser.ParseException e) {
    log().error("error in searchSongs()");
    e.printStackTrace();
}

Generated query is: name:test album.title:test artists.name:test genres.genre:test

With the default setting that means each field is searched with the OR operator. I noticed it's possible to change it with:
Code:
parser.setDefaultOperator(MultiFieldQueryParser.AND_OPERATOR);

However I now want to be able to filter my queries by genres, artists etc. Something like this:

(name:test OR album.title:test OR artists.name:test) AND (genres.genre:pop)

or maybe

(name:test OR album.title:test ) AND (genres.genre:pop) AND (artists.name:Jackson)

Is it possible? Where could I find documentation on how to achieve this?

Cheers!


Top
 Profile  
 
 Post subject: Re: Multifielded Query question
PostPosted: Wed Dec 16, 2009 9:52 am 
Hibernate Team
Hibernate Team

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

the best place to look for examples is the Lucene wiki, eg query parser syntax. Also look at the Lucene javadocs.
You don't have to use a query parser either. In your case it might be better to construct the query programmatically using BooleanQuery. You could have several TermQuery instances combined in the BooleanQuery or also multiple queries generated from different query parsers.

Also have a look at Filter. Filtering is in many usecases a better and faster solution to your search "problems".

--Hardy


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