-->
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: Case-insensitive queries?
PostPosted: Mon Apr 18, 2016 6:08 pm 
Newbie

Joined: Tue Apr 12, 2016 4:09 pm
Posts: 9
I have a requirement to do case insensitive text searching. I have the following JP-QL query working well via Hibernate Search:
Code:
@NamedQuery(name = Product.BY_NOMENCLATURE_QUERY,
            query = "from Product p join p.brandCodes brandCodes join fetch p.names names where brandCodes in :brandCodes and (p.id like :nomenclature or names like :nomenclature)")


I have the following field indexes confirmed working well with Hibernate Search:
Code:
@ElementCollection(fetch = FetchType.EAGER)
@Field(analyze = Analyze.NO)
@FieldBridge(impl = BuiltinIterableBridge.class)
private Set<String> brandCodes;

@ElementCollection
@MapKeyEnumerated(EnumType.STRING)
@Field(analyze = Analyze.NO)
@FieldBridge(impl = BuiltinMapBridge.class)
private Map<Brand, String> names;



Normally with JP-QL, I could use either the "upper" or "lower" function in the query, and change the case of my named parameter in order to do case-insensitive searching. However, I understand that Hibernate OGM doesn't support JP-QL functions in general. Is there any way to meet my requirement using OGM? Right now, it's looking like my only alternative is to fetch all objects of this entity type from the data store, loop through them all and evaluate which match my search criteria. Since I need to do this for an auto-suggest form, this probably isn't going to be good from performance / resource perspective.


Top
 Profile  
 
 Post subject: Re: Case-insensitive queries?
PostPosted: Tue Apr 19, 2016 6:01 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
out of curiosity, which datastore are you using?

Wouldn't it be possible to analyze the field using a lowercase filter or similar? It can be a separate field, then you could use a full text query to find the values.

The only portable solution I can think of is to store the values in a separate analyzed field or entity property.
Alternatively, you can use a native query; Hibernate OGM will return a managed entity anyway.

Davide


Top
 Profile  
 
 Post subject: Re: Case-insensitive queries?
PostPosted: Tue Apr 19, 2016 9:28 am 
Newbie

Joined: Tue Apr 12, 2016 4:09 pm
Posts: 9
Hi.

I'm using Redis as the data store right now. I'd like to use Infinispan, but having issues getting it up and running correctly on Wildfly 10.

I could store a version of my "names" field with a different analyzer. Is there a standard analyzer I can use to make it case insensitive, or will I have to implement my own?

In any case, I think case insensitive searching is a pretty common requirement. It would be great if OGM supported this out of the box in the future.


Top
 Profile  
 
 Post subject: Re: Case-insensitive queries?
PostPosted: Thu Apr 21, 2016 5:58 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
I've created a JIRA to keep track of this issue: https://hibernate.atlassian.net/browse/OGM-1025

It's quite easy to create a new analyzer, you can find an example on StackOverflow: http://stackoverflow.com/questions/1178 ... etokenizer

It's even easier if you use Hibernate Search annotations:

Code:
@AnalyzerDef(name = "lowercaseanalyzer",
  tokenizer = @TokenizerDef(factory = KeywordTokenizerFactory.class),
  filters = {
    @TokenFilterDef(factory = LowerCaseFilterFactory.class)})
  })


Assuming that you don't want to tokenize the fields, otherwise the default analyzer will already store lowercase tokens.

Hope this help,
Davide


Top
 Profile  
 
 Post subject: Re: Case-insensitive queries?
PostPosted: Fri Apr 22, 2016 10:19 am 
Newbie

Joined: Tue Apr 12, 2016 4:09 pm
Posts: 9
Thank you. I was able to get things working using your advice.


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.