[hibernate-dev] problem in implementing the hibernate search
Emmanuel Bernard
emmanuel at hibernate.org
Fri Oct 15 08:32:08 EDT 2010
Hi,
Please use the user forum https://forum.hibernate.org/viewforum.php?f=9 or consider commercial support from Red Hat.
This mailing list is dedicated to the development of the Hibernate projects.
On 15 oct. 2010, at 14:22, nitin warkar wrote:
> 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.
>
> See the 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.
>
>
>
>
>
>
>
>
>
>
>
> --
> -Regards
> Nitin warkar
> 3B Productivity Paradigms.
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
More information about the hibernate-dev
mailing list