Shopping cart solutions
Narola® InfotechMail for E-commerce Solutionsecommerce Application development

Services

Products


News Events

How to use Hibernate Search

How to use hibernate search ?

Below are steps :

  1. Add below line above the field declaration which should be indexed

    @Field(index=Index.TOKENIZED, store=Store.NO)

  2. In hibernate.cfg.xml, add below property. Path is where index file will be created.

    <property name="hibernate.search.default.indexBase">F:\indexes</property>

  3. In hibernate.cfg.xml, add below property after mapping propery.

    <event type="post-update">
    <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
    </event>
    <event type="post-insert">
    <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
    </event>
    <event type="post-delete">
    <listener class="org.hibernate.search.event.FullTextIndexEventListener"/>
    </event>

  4. Add Indexed annotation on table name on which you want to apply indexing. Over here ItemShop is that table/Entity.

    @Entity
    @Indexed
    public class ItemShop

  5. Now run that registry file

    AnnotationConfiguration aConf = new AnnotationConfiguration();
    aConf.configure();
    Long t = (Long aConf.buildSessionFactory().openSession().createQuery("select count(*) from ItemShop").uniqueResult();
    System.out.println("starting loop");
    for (int i = 0 ; i< t; i = i+100){
    FullTextSession fullTextSession = Search.createFullTextSession(this.getSession());
    org.hibernate.Transaction tx = fullTextSession.beginTransaction();
    List itemShops = this.getSession().createQuery("from ItemShop").setFirstResult(i).setMaxResults(100).list();
    System.out.println("beginTransaction");
    tx = fullTextSession.beginTransaction();
    for (int j=0;j
    {
    ItemShop itemShop = (ItemShop) itemShops.get(j);
    fullTextSession.index(itemShop);
    Product p = itemShop.getProduct();
    fullTextSession.index(p);
    System.out.println("indexed: "+itemShop.getId());
    }
    tx.commit();
    }

Shopping cart solutionsCall us or write us to place an inquiry.
Home | About us | Technologies | Services | Products | Blog | Contact | Directory | Article | Knowledge Exchange | Sitemap
© 2005-09 http://www.narolainfotech.com | All Rights Reserved.
Narola Infotech RSS Narola Infotech Resource Sitemap Valid CSS! Valid XHTML 1.0 Transitional