-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Search fails on search with capital letters
PostPosted: Tue Jul 14, 2009 12:44 pm 
Newbie

Joined: Thu Oct 23, 2008 12:35 pm
Posts: 5
Hi,

I'm currently working on integrating hibernate search. In general everything works now, but I can't search for words which start with a capital letter. I'm using the StandardAnalyzer. The strange thing is, if I copy and paste the same query into luke, everything is fine, the expected result is found.

Example term: "username:Heffer*" finds nothing with hibernate search, but fine in luke.
"username:hawa" fine in hibernate search and luke.

Any idea what might be wrong?

Kind Regards,

ingo


Top
 Profile  
 
 Post subject: Re: Hibernate Search fails on search with capital letters
PostPosted: Wed Jul 15, 2009 6:41 am 
Hibernate Team
Hibernate Team

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

do you use the same analyzer for indexing and searching? If so it would help to see the indexing and search code and maybe the annotated entities.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search fails on search with capital letters
PostPosted: Wed Jul 15, 2009 8:27 am 
Newbie

Joined: Thu Oct 23, 2008 12:35 pm
Posts: 5
Hi Hardy,

thanks for helping!

Yes, of course, I use the same analyzer for indexing and searching. I tried the StandardAnalyzer and the simple analyzer, I don't want any stop words, word stemming is also not necessary, I only want ignore-case.

This is the annotation I used:

Code:
/**
* username for web frontend / updates
*/
@Column(unique = true)
@Field(index = Index.TOKENIZED, store = Store.NO)
private String username;


And this is the reindex code:

Code:
      List<ProfileDto> result;
      Query query = session.createQuery("from ProfileDto as ProfileDto");
      query.setFirstResult(startIndex);
      query.setMaxResults(REINDEX_PAGE_SIZE);
      query.setCacheable(false);
      query.setReadOnly(true);

      result = query.list();
      for (ProfileDto profile : result) {
           profile.setMasterData(getUserDao().getByUid(profile.getUserId()));
           fullTextSession.index(profile);
      }
      resultSize = result.size();
      fullTextSession.flushToIndexes();


And this for querying:

Code:

       FullTextQuery query = (FullTextQuery) fullTextSession.createFullTextQuery(parser.parse("masterData.username:" +searchParams.getUsername() + "*"), ProfileDto.class);

       Sort sort = new Sort(new SortField("masterData.lastAccessTime", true));
       query.setSort(sort);
       query.setTimeout(getQueryTimeout());

       if (size != null && offset != null) {
          query.setFirstResult(offset);
          query.setMaxResults(size);
       }
       List<ProfileDto> result = query.list();


Any idea what might be wrong?

Kind regards,

Ingo


Top
 Profile  
 
 Post subject: Re: Hibernate Search fails on search with capital letters
PostPosted: Wed Jul 15, 2009 9:02 am 
Hibernate Team
Hibernate Team

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

I cannot see anything obvious. You can try Store.YES. This way you can inspect all indexed tokens in Luke. You kind of tested this already by running the query in Luke, but this is just more visual.

You can also inspect the generated query by for example calling toString on it.

In your code you are not showing which type of Parser you are using and how you construct it. I assume you pass in the default analzer there, since you are not passing it into the parse() method.

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search fails on search with capital letters
PostPosted: Wed Jul 15, 2009 9:26 am 
Newbie

Joined: Thu Oct 23, 2008 12:35 pm
Posts: 5
Hi Hardy,

I use the "QueryParser".

I only posted the relevant stuff, no debug, I had a debug output and used the logged query in luke. Works fine there.

I just changed Index.UN_TOKENIZED to Index.TOKENIZED for the username and now the search works fine although I don't really understand why, as Luke does find the proper result with UN_TOKENIZED.

Ingo


Top
 Profile  
 
 Post subject: Re: Hibernate Search fails on search with capital letters
PostPosted: Wed Jul 15, 2009 9:39 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Here you have your answer - if you index Index.UN_TOKENIZED no analyzer is applied. Instead the property is added as is into the index. What I don't understand is why in your example you already used Index.TOKENIZED???

--Hardy


Top
 Profile  
 
 Post subject: Re: Hibernate Search fails on search with capital letters
PostPosted: Wed Jul 15, 2009 9:47 am 
Newbie

Joined: Thu Oct 23, 2008 12:35 pm
Posts: 5
Hi,

Ups, I'm terribly sorry, I was just doing the change when your response came and accidently took the changed code. So, if I get this right, those fields have to be tokenized otherwise wildcard use wouldn't work properly?

Ingo


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