-->
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: Session.createFullTextQuery(luceneQuery, Item.class);
PostPosted: Fri Oct 15, 2010 3:27 am 
Newbie

Joined: Fri Oct 15, 2010 3:08 am
Posts: 4
Hi all,

I am struggling with the hibernate search, I had been implemented a small POC on the hibernate search.It works perfectly for my one database table named as "Item" but when I am trying to use the same configuration for some other tables then Session.createFullTextQuery(luceneQuery, Item.class); returns me null result.

I have configure the beans and hibernate configure same as I had used it for the Item table.

Please help me ASAP trying from last two days.

Thank you in advance.....


Top
 Profile  
 
 Post subject: Re: Session.createFullTextQuery(luceneQuery, Item.class);
PostPosted: Fri Oct 15, 2010 5:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
The last parameter of the createFullTextQuery is a vararg parameter allowing you to specify which entity type (index) you want to search. In your case you are searching the Item index.
Code:
Session.createFullTextQuery(luceneQuery, Item.class);


You can either remove the last parameter and search in all indexes:
Code:
Session.createFullTextQuery(luceneQuery);


Or you explicitly search for your new indexed Entity
Code:
Session.createFullTextQuery(luceneQuery, MyNewEntity.class);


Btw, I think it helps to think object/entity related instead of database tables.

--Hardy


Top
 Profile  
 
 Post subject: Re: Session.createFullTextQuery(luceneQuery, Item.class);
PostPosted: Fri Oct 15, 2010 6:21 am 
Newbie

Joined: Fri Oct 15, 2010 3:08 am
Posts: 4
hey thanx Hardy to reply to my post,

I had made the changes as you suggest me in recent post but still it returns the null result.

See my code below....
======================searcher.java file code===============================

Code:
String[] productFields = { "name_astp", "description_astp" }; // targeted fields
   //   Map<String, Float> boostPerField = new HashMap<String, Float>(2); // boost
                                                         // factors
   //   boostPerField.put("name_astp", (float) 4);
   //   boostPerField.put("description_astp", (float) 1);
      // QueryParser parser = new MultiFieldQueryParser(productFields,new
      // StandardAnalyzer(),boostPerField);
      //QueryParser parser = new QueryParser("name_astp", new StandardAnalyzer());

      QueryParser parser = new MultiFieldQueryParser(productFields,
            new StandardAnalyzer());
      org.apache.lucene.search.Query luceneQuery;
      try {
         luceneQuery = parser.parse(seachKeyStr);
      } catch (ParseException e) {
         throw new RuntimeException("Unable to parse query: " + seachKeyStr,
               e);
      }
      Session session = HibernateUtil.getSessionFactory().getCurrentSession();

      session.beginTransaction();
      FullTextSession ftSession = org.hibernate.search.Search.createFullTextSession(session);
      
      
      // ftSession=org.hibernate.search.Search.getFullTextSession(session);

      Query query = ftSession.createFullTextQuery(luceneQuery); // return, Item.class
                                                                  
      @SuppressWarnings("unchecked")
      List<Item> results = null;
      try {
         results = query.list();
      } catch (Exception ex) {
         ex.printStackTrace();
      }


//======================Item.hbm.xml============================================

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--  Example 2.7 -->
<hibernate-mapping package="com.manning.hsia.dvdstore.model">
    <class name="AmAssetType" table="am_asset_type_astp">  <!-- mapping externalized in hbm.xml files -->
       <id name="id">
          <generator class="native"/>
       </id>       
       <property name="name_astp"/>
       <property name="description_ast"/>       
   </class>
</hibernate-mapping>


//============================= hibernate.cfg.xml =====================================
Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!--  Example 2.3 -->
<hibernate-configuration>
  <session-factory>
     <!--  database configuration -->
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://192.168.1.12:3306/dvdstore</property>
    <property name="connection.username">root</property>
   <property name="connection.password">admin</property>
    <property name="hibernate.connection.pool_size">1</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
    <property name="show_sql">true</property>
    <!-- generate schema -->
    <property name="hibernate.hbm2ddl.auto">update</property>   
    <!-- Hibernate Search configuration -->
    <property name="hibernate.search.default.indexBase">./build/indexes</property>
    <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.RAMDirectoryProvider</property>   
    <!-- classes mapping -->
    <mapping class="com.manning.hsia.dvdstore.model.Item"/>
  </session-factory>
</hibernate-configuration>



hope you will get clear idea about what exactly I am trying to do........

Thank you in advance.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.