-->
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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Hibernate Search] Indexing objects in classes
PostPosted: Mon May 07, 2007 10:45 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

I have a class called Document :

Code:
@Indexed
public class Document {

   @DocumentId
   private Integer id;

   @Field(index=Index.TOKENIZED, store=Store.YES)
   private String titre;

   // getters and setters
}


and a class called Entite which include a list of Document :

Code:
@Indexed
public class Entite
{
   @DocumentId
   private Integer id;

   @Field(index=Index.TOKENIZED, store=Store.YES)
   private String resume;

   @ContainedIn
   private List documents;

   // getters and setters
}


and I want to have all "Entite" in which there is one "Document" which have titre=something.


I tried that :

Code:
      FullTextSession fullTextSession = Search.createFullTextSession(s);
   
      QueryParser parser = new QueryParser("title", new StopAnalyzer());

      String requete = "titre:something";

      org.apache.lucene.search.Query luceneQuery = null;
      try {
         luceneQuery = parser.parse(requete);
      } catch (ParseException e) {
         e.printStackTrace();
      }
      org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery,Entite.class);

      List result = (fullTextQuery).list(); //return a list of managed objects
      Iterator i = result.iterator();

      while(i.hasNext())
      {
         System.out.println("Objet trouve : "+i.next());
      }


but it found nothing. And if I remove "Entite.class" restriction, there are "Document" results but not "Entite" ...

Thank you.


Last edited by fabreax on Mon May 07, 2007 11:50 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 11:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
replace @ContainedIn with @IndexedEmbedded

and

your quesry should be "documents.titre:whatever"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 11:50 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Thank you Emmanuel,

I replaced @ContainedIn with @IndexedEmbedded

My query is "documents.titre:something" but there is no result.


Last edited by fabreax on Mon May 14, 2007 3:23 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 4:33 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I downloaded the last Hibernate Search (from SVN).

It seems that "documents.titre:something" doesn't work.

Moreover, I have :
Code:
@IndexedEmbedded
private List documents;


Last edited by fabreax on Mon May 14, 2007 3:23 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 11:18 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
UP


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It may be because you are missing the generic type
it has to be a List<Document>, otherwise, HSearch cannot guess the type

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 1:10 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Yes, it's only a List, not a List<Document>, because I had problems when with List<Document>.

I muse use List<Document> ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 1:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I m pretty sure it's mandatory yes. At least it was in a previous version of the code. I remember I relaxed part of it in SVV HEAD but I not guaranty here.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 6:10 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I made the update :
@IndexedEmbedded
private List<Document> documents;

(no update in cfg.xml)

and the problem still appears.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 8:37 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
This is my Entite class :

Code:
@Indexed
public class Entite
{
   @DocumentId
   private Integer id;

   @Field(index=Index.TOKENIZED, store=Store.YES)
   private String titre;

   @IndexedEmbedded
   private List<Document> documents;

   public Entite() { }
   
   public Entite(String titre)
   {
      documents = new ArrayList<Document>();
      this.titre = titre;
   }

   // getters and setters
}


My Document class :
Code:
@Indexed
public class Document
{
   @DocumentId
   private Integer id;

   @Field(index=Index.TOKENIZED, store=Store.YES)
   private String titre;
   
   public Document() {}
   
   public Document(String titre)
   {
      this.titre = titre;
   }

   // getters and setters


and my mapping.hbm.xml :

Code:
<hibernate-mapping package="modele">
   <class name="Entite" table="Entite" lazy="true">
      <id name="id" column="Id">
         <generator class="increment" />
      </id>

      <property name="titre" column="Titre" />

      <list name="documents" cascade="all">
         <key column="IdEntite" />
         <index column="IdDocument" />
         <one-to-many class="Document" />
      </list>
   </class>

   <class name="Document" table="Document" lazy="true">
      <id name="id" column="Id">
         <generator class="increment" />
      </id>
      <property name="titre" column="Titre" />
   </class>
</hibernate-mapping>


My Lucene Query is
Code:
"documents.titre:do*"


And I have a Document which title is "document 1"


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:16 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try and run you app with a debugger, something in your environment is causing the issue. Also check your index with luke, it's a fantastic tool to debug lucene behavior

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 4:22 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Thank you.
I used Luke to open my index files. In "Entite" class, there isn't "documents.titre" field. There is "id" and "titre".

I opened other index files of other classes. For example, I have a field "private Type type;" in a class, and Type has a "private String mime;" attribute.
Therefore, I have "type.mime" field in my index, good ! But it doesn't work with lists.

I will try to start from scratch a new Hibernate test project.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 5:36 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I found where the problem is but i don't know why. I always delete index files to be sure.

I have "documents.titre" in indexes (it's what I want) if my code is :
Code:
Transaction tx = session.beginTransaction();            
Entite entite1 = new Entite("entite 1");
session.persist(entite1);

entite1.getDocuments().add(new Document("document 1"));
tx.commit();


I haven't "documents.titre" in indexes if my code is :
Code:
Transaction tx = session.beginTransaction();            
Entite entite1 = new Entite("entite 1");
session.persist(entite1);
tx.commit();
      
tx = session.beginTransaction();
entite1.getDocuments().add(new Document("document 1"));
tx.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 8:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah interesting.
http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-56

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 8:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the workaround is to touch the owning entity
or manually call fullTextSession.index(owningEntity);

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.