-->
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.  [ 3 posts ] 
Author Message
 Post subject: H Search Whitespace Issue
PostPosted: Wed May 30, 2007 10:07 pm 
Newbie

Joined: Fri Apr 27, 2007 5:05 pm
Posts: 7
Hi,
I have problems to analyze Strings with whitespaces in H Search.

I use this method to search over multiple fields and return the corresponding List (List with hits)

Code:
public static List<Character> getResultList(String fullText, String gameFilter){
               
      List<Character> result = null;
      org.apache.lucene.search.Query luceneQuery = null;

      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      FullTextSession fullTextSession = Search.createFullTextSession(session);
      
      
      String[] fields = {"name","guild","server"};
      MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new WhitespaceAnalyzer());
            
      try {
         luceneQuery = parser.parse(fullText);
      } catch (ParseException e) {
         e.printStackTrace();
      }
      org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );
             
      //look in the database for Character Objects
      session.beginTransaction();
      result = fullTextQuery.list(); //return a list of managed objects   
      session.getTransaction().commit();
      return result;
}


My class character has got a String name where I can write "Surname name" for instance. If I am looking for this name by using Surname*, I am able to find the character. But if I use only Surname without the Wildcard I didn't find it. Could anybody help me here?

Thnx
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Seems like you don't use the same analyzer for querying and indexing

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 3:14 pm 
Newbie

Joined: Fri Apr 27, 2007 5:05 pm
Posts: 7
Hi,
first I used the Keywordanalyzer and now I tried to switch to the Whitespaceanalyzer. I deleted the old indexes and now the search only found new created characters. I think I have to try the Lucene Demo war file first and look how I recreate a proper index.

Thnx for that hint with the Analyzer and Indexing :)

Edit: I create now a setIndexHelperMethod to ensure that all characters are indexed (after I deleted the index or try to change the Analyzer). Is that a good approach to use this helper method every time I change something at the search or the @Index in the Character DTO?

Helper Method:
Code:
public static void indexCharacters(){
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      FullTextSession fullTextSession = Search.createFullTextSession(session);
      
      Transaction tx = fullTextSession.beginTransaction();
      
      Query q = session.createQuery("from Character character");
      List<Character> characters = q.list();
          
      for (Character character : characters) {
         fullTextSession.index(character);
      }
      
      tx.commit();
   }


Cu
Alex


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