-->
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: Searching case insensitive in case sensitive indexes
PostPosted: Tue Apr 20, 2010 11:54 am 
Newbie

Joined: Tue Apr 20, 2010 11:36 am
Posts: 1
Hi,
I'm trying to implement a fulltext search for a content string in an entity. The user should differ between case sensitive and case insensitive search. So I implemented a Analyzer that do not lowercase the indexes. I annotated the content as
Code:
@Lob
@org.hibernate.search.annotations.Field(index = Index.TOKENIZED)
@Analyzer(impl = CustomAnalyzer.class)
private String content = "";

For searching I use a MultiFieldQueryParser and a lucene Query.
Code:
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[] {"content" }, new CustomAnalyzer());
org.apache.lucene.search.Query ftq;
ftq = parser.parse("content: searchString");
entities = entityManager.createFullTextQuery(ftq, Entity.class).getResultList();

A search like this is always case sensitive. But can't be case insensitive.
Is there a way to do a case insensitive search in a case sensitive index? The hint from a lucene forum to create 2 indexes one case sensitive and one insensitive is not an option.

Thanks, Timo


Top
 Profile  
 
 Post subject: Re: Searching case insensitive in case sensitive indexes
PostPosted: Tue Apr 20, 2010 4:39 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, you don't need to make two different indexes, you should index the same data in two different fields, like having
Code:
   @Fields( {
      @Field(name = "content_casesensitive", index = Index.TOKENIZED, analyzer = @Analyzer(definition="casesensitiveAnalyzer")),
      @Field(name = "content_caseInsensitive", index = Index.TOKENIZED, analyzer = @Analyzer(definition="caseInsensitiveAnalyzer"))
   } )
   public String getContent(){

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


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.