-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate Search: need exact match on a specific field
PostPosted: Wed Apr 18, 2007 2:57 am 
Newbie

Joined: Fri Dec 22, 2006 8:17 am
Posts: 6
I need to make following HSQL to a lucene queue in hibernate search:
"from Person where name like '%james%' and country='us' "

I've tried:
luceneQuery = parser.parse( "name:james And country:us" )
this doesn't work because country "usa" is returned.

How to make this query? Anyone knows?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 7:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
interesting, did you tokenize the field? And what is your analyzer?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 7:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Also, doing lucenequery.toString() helps to understand what happens

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 10:36 pm 
Newbie

Joined: Fri Dec 22, 2006 8:17 am
Posts: 6
I'm using ChineseAnalyzer. Is it possible to use ChineseAnalyzer for name field, and use KeywordAnalyzer for country field in my query? I think the problem can be solved if I can use different analyzers for those fields.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 10:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no, not from the regular Lucene query parser.
But you can:
- write your own query parser by extending theirs
- use the programmatic API Lucene Query objects, to tune what you want (which is usually what people end up doing with complex query requirements.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Apr 22, 2011 6:04 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
emmanuel wrote:
- use the programmatic API Lucene Query objects, to tune what you want (which is usually what people end up doing with complex query requirements.


what would you use to have an exact match with a query ?

.ignoreAnalyzer() ?


Top
 Profile  
 
 Post subject: Re: Hibernate Search: need exact match on a specific field
PostPosted: Fri Apr 22, 2011 6:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
With the Hibernate Search query DSL, you would do

Code:
builder.keyword().onField("name").matching("Emmanuel").createQuery()

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Hibernate Search: need exact match on a specific field
PostPosted: Fri Apr 22, 2011 6:44 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
the initial problem seems that 'emmanuell' would match 'emmanuel'


Top
 Profile  
 
 Post subject: Re: Hibernate Search: need exact match on a specific field
PostPosted: Fri Apr 22, 2011 7:42 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi mirak,
use
Code:
@Field(index=Index.UN_TOKENIZED
on the property that you don't want to analyze.

Or alternatively specify a different analyzer to it which fits your need: apparently you don't want to use the ChineseAnalyzer on that property, but you can apply different analyzers to each field. (UN_TOKENIZED means no analyzer at all is going to be applied, treating the full value as a keyword)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Hibernate Search: need exact match on a specific field
PostPosted: Fri Apr 22, 2011 7:48 am 
Beginner
Beginner

Joined: Mon Apr 04, 2011 12:08 pm
Posts: 32
ok, thank you


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