-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hibernate Search Index file creation
PostPosted: Tue May 22, 2007 8:07 am 
Newbie

Joined: Mon Apr 09, 2007 3:20 am
Posts: 5
Location: Colombo
Hi all,

I'm very new to Hibernate search this is the first time I'm going to work with hibernate search. I have some experience in Hibernate.
The problem is like this.
I have configured the hibernate search with my .ear and annotated entity beans with the relevant annotations which are provided in the reference documentation.


This is the property configuration part in persistence.xml

<property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
<property name="hibernate.search.default.indexBase" value="D:\HibernateSearch\indexes"/>



This is my entity bean (I included only the fields which are annotated for Hibernate Search)

@Entity
@Indexed(index="tblHotels")
@Role(name="roomsnet.r5.pojo.portal.TblHotels_hotelToBeMapped")
@Name("roomsnet.r5.pojo.portal.TblHotels")
@Table(name = "TBL_HOTELS", uniqueConstraints = {})
public class TblHotels implements java.io.Serializable {
....
....
....

@Column(name = "HOT_NAME", unique = false, nullable = false, insertable = true, updatable = true, length = 2000)
@Field(name="HotelName", index=Index.TOKENIZED, store=Store.YES)
public String getHotName() {
return this.hotName;
}

@Column(name = "HOT_DES", unique = false, nullable = true, insertable = true, updatable = true, length = 1500)
@Field(name="HotelDes", index=Index.TOKENIZED, store=Store.YES)
public String getHotDes() {
return this.hotDes;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 22, 2007 6:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
well first of all, what's wrong? :)
Second if you are using Seam be sure to replace hibernate-all.jar by the latest versions of Hibernate Search / Annotations / commons-annotations / Core

_________________
Emmanuel


Top
 Profile  
 
 Post subject: It's a mistake...
PostPosted: Wed May 23, 2007 1:39 am 
Newbie

Joined: Mon Apr 09, 2007 3:20 am
Posts: 5
Location: Colombo
Sorry..Emanuel I couldn't add my problem, This is the same message I have posted earlier.

1. I'm not doing any insert, update, delete records from the database using the entity bean. I do only the SELECT because in this application user search for hotels and we are returning the list of hotels according to the search word. It returns as the list of TblHotels objects. Can I use Hibernate Search for such a scenario?

2. I have tried as mentioned in the Hibernate documentation but no indexes are created in the specified directory?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 9:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If your application is read onlym, it means the index is not updated when the DB is updated, and especially the first time.
So on a regular basis you should do something like
Code:
List hotels = session.createCriteria(Hotel.class).list(); //actually a scroll would be better if you have a lot of hotels
for (Object hotel : hotels) fullTextSession.index(hotel);

//also add proper transaction demarcation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 8:45 am 
Newbie

Joined: Mon Apr 09, 2007 3:20 am
Posts: 5
Location: Colombo
Ok..Thanks Emanuel, As you said its only a read only program. therefore I have to index them periodically. These days I'm designing that module. I really appreciate your help.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 02, 2007 1:11 am 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
I tried unsuccessful to create an index for seed data in Seam. Only the index directories were created successfully during deployment. Here is the code to create a full index:

Code:

@Stateless
@Name("searchBean")
public class SearchBean implements Search {
    @PersistenceContext
    private EntityManager em;

    @In(create=true)
    private BusinessHome businessHome;

    /**
     * load and re-persist every entity that is indexed
     */
    public void indexAll() {
        List<Business> businesses = em.createQuery("from Business c")
                    .getResultList();
            FullTextSession session = Search.createFullTextSession(((HibernateEntityManager) em.getDelegate()).getSession());
        for (Business business : businesses) {
            session.index(business);
        }
        return;
    }



After some debugging, I found the indexing is failing at indexing the "categories" field of Business. This field is declared as such:

Code:
   
@Field(name="category", index=Index.TOKENIZED, store= Store.NO)
    @FieldBridge(impl = CategoryBridge.class)
    private List<Category> categories = new ArrayList<Category>(0);


By default the seed businesses have empty categories. Here is the objectToString(Object object) method of CategoryBridge.class:
Code:

    public String objectToString(Object object) {
        List<Category> cats = (List<Category>) object;
        if (cats == null)
            return null;
        else {
            StringBuffer sb = new StringBuffer(16);
            for (Category cat : cats) {
                sb.append(cat.getId()).append(", ");
                if (cat.getParent() != null) {
                    sb.append(cat.getParent().getId()).append(", ");
                }
            }
            return sb.toString();
        }
    }


However, if I update each record through UI, the index will get updated each time.

What am I doing wrong? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 02, 2007 1:25 am 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
One more piece of information to add: when updating a business from UI, one must select a category. I wonder why an empty categories property will throw indexing off.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 02, 2007 11:48 am 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
After I modified the UI to allow empty category selection, indexing still worked. So it doesn't seem to be related to empty categories but to the way index is done. Any help?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 11:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think I exclude colelction when I buld the metadata for field indexing.
You could try using @IndexedEmbedded instead

Can you open a JIRA issue with a test case, I'll need to have a look

_________________
Emmanuel


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