-->
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.  [ 4 posts ] 
Author Message
 Post subject: Serach creating index files with no data
PostPosted: Wed May 19, 2010 6:26 am 
Newbie

Joined: Wed May 19, 2010 6:16 am
Posts: 2
Hi,
I am using Hibernate Search + Hibernate 3 with JPA and I have a strange problem.
When I do indexing, I can see index files being created but they are blank. The luke also shows nothing in these files. Hence the search is also not working. Can anyone please help me regarding this.
My persistence.xml file:
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
   
   <persistence-unit name="defaultManager"
      transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.connection.driver_class"
            value="com.mysql.jdbc.Driver" />
         <property name="hibernate.connection.url"
            value="jdbc:mysql://localhost:3306/hibernatetest" ></property>
         <property name="hibernate.connection.username" value="root" />
         <property name="hibernate.connection.password"
            value="root" />
         <property name="hibernate.show_sql" value="false" />               
      
         <property name="hibernate.search.default.directory_provider"
               value="org.hibernate.search.store.FSDirectoryProvider" />
         <property name="hibernate.search.indexing_strategy" value="manual" />
         <property name="hibernate.search.default.indexBase" value="e:\indexes" />
      </properties>
   </persistence-unit>
</persistence>





The EO calss is simpple
Code:
@Indexed
@Entity
@Table(name="book")
/*@AnalyzerDef(name = "customanalyzer",
      tokenizer = @TokenizerDef(factory =   StandardTokenizerFactory.class),
      filters = {
      @TokenFilterDef(factory = LowerCaseFilterFactory.class),
      @TokenFilterDef(factory = SnowballPorterFilterFactory.class,
      params = {
      @Parameter(name = "language", value = "English")
      })
      })*/
public class BookEO {
   
   @DocumentId
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Integer id;
   
   @Field(index=Index.TOKENIZED)
   
   //@Analyzer(definition = "customanalyzer")
   private String title;
   @Field(index=Index.TOKENIZED)
   //@Analyzer(definition = "customanalyzer")
   private String subtitle;
   
   
   @IndexedEmbedded
   @ManyToMany
   private Set<AuthorEO> authors = new HashSet<AuthorEO>();
   
   @Field(index = Index.UN_TOKENIZED)
   @DateBridge(resolution = Resolution.DAY)
   private Date publicationDate;
//getter and setters



And the code doing search is follows:
Code:
EntityManager em = HibernateEntitymanagerHelper.getEntityManagerFactory().createEntityManager();
        FullTextEntityManager fullTextEntityManager =  Search.getFullTextEntityManager(em);
       
        fullTextEntityManager.getTransaction().begin();
       
      
        List<BookEO> books = em.createQuery("select book from BookEO as  book").getResultList();
        for (BookEO book : books) {
              fullTextEntityManager.index(book);
         }
       // fullTextEntityManager.getSearchFactory().optimize(BookEO.class);
          //System.out.println("Done optimise123!!!!!!!!!");
       
          //fullTextEntityManager.getTransaction().commit();
                     
         
          //fullTextEntityManager.getTransaction().begin();
        /*
        String[] fields = new String[]{"title", "subtitle"};
        MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
       // parser.setDefaultOperator(QueryParser.AND_OPERATOR);
        org.apache.lucene.search.Query query = parser.parse( "hibernate" );
        // wrap Lucene query in a javax.persistence.Query
        javax.persistence.Query persistenceQuery =  fullTextEntityManager.createFullTextQuery(query, BookEO.class);
        // execute search
        List<BookEO> result = persistenceQuery.getResultList();
        System.out.println("result ::"+result);
        for (BookEO book : result) {
           System.out.println("Book ::"+book.getTitle());
      }
fullTextEntityManager.getTransaction().commit();
           em.close();
         HibernateEntitymanagerHelper.shutdown();


Top
 Profile  
 
 Post subject: Re: Serach creating index files with no data
PostPosted: Wed May 19, 2010 6:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
How do your index your data? Do you already have data in your database and you create an initial index? Or do you just create new objects after startup and persist them and rely on automatic indexing?

When Hibernate Search starts up it will create the initial index directories (or opens them in case they already exist), but you still need to index something first prior to searching.

--Hardy


Top
 Profile  
 
 Post subject: Re: Serach creating index files with no data
PostPosted: Wed May 19, 2010 2:50 pm 
Newbie

Joined: Wed May 19, 2010 6:16 am
Posts: 2
I have data in the table and in code I am trying index before searching as below:
Code:
List<BookEO> books = em.createQuery("select book from BookEO as  book").getResultList();
        for (BookEO book : books) {
              fullTextEntityManager.index(book);
         }


The index directories are being created by the entity class name, but the created files are just of 1KB.(Where my table has lots of data).Luke tool also shows nothing in these files. It lists index file size as 0 KB.

Please help me.


Top
 Profile  
 
 Post subject: Re: Serach creating index files with no data
PostPosted: Wed May 19, 2010 3:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Do you have some debug trace from the log file? Does this indexing loop work? Are there entities retrieved from the db? Anything else out of the ordinary in the log files.


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