-->
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: hibernate search @IndexedEmbedded not indexing
PostPosted: Tue Jun 12, 2012 2:34 am 
Newbie

Joined: Tue Jun 12, 2012 2:12 am
Posts: 2
Code:
...
import org.hibernate.search.annotations.Boost;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;

@Entity
@Indexed
@SequenceGenerator(name="subjectSeq", sequenceName="subjectSeq")
public class AppInfo {
   
   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="subjectSeq")
   public Integer id;
   
   public Integer district;
   
   @Field
   @Boost(2.0f)
   public String appName;
   
   public String thumbnail;
   
   public Integer statistics;
   
   @Field
   public String description;
   
   public Integer publisher;
   
   public Date publishAt = new Date();
   
   @ManyToOne
   @IndexedEmbedded
   @Boost(1.5f)
   @JoinColumn(name="type")
   public AppType type;
   
   @ManyToMany
   @JoinTable(name="appInfo_appCatalog",
   joinColumns={@JoinColumn(name="info_id", referencedColumnName="id")},
   inverseJoinColumns={@JoinColumn(name="catalog_id", referencedColumnName="id")})
   @IndexedEmbedded
   @Boost(1.5f)
   public List<AppCatalog> catalogs;
   
   public Integer status = 0;
   
   public int state;
   
   public int isPopular;
}


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

import org.hibernate.search.annotations.Field;

@Entity
@SequenceGenerator(name="appTypeSeq", sequenceName="appTypeSeq")
public class AppType {

   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="appTypeSeq")
   public Integer id;
   
   @Field
   public String name;
}


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import org.hibernate.search.annotations.Field;

@Entity
@SequenceGenerator(name="appCatalogSeq", sequenceName="appCatalogSeq")
public class AppCatalog {

   @Id
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="appCatalogSeq")
   public Integer id;
   
   @Field
   public String name;
   
}

I user the following query code:
Code:
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
            .buildQueryBuilder().forEntity( AppInfo.class ).get();
org.apache.lucene.search.Query query = qb
              .keyword().fuzzy()
              .onFields("appName", "description", "type.name", "catalogs.name")
              .matching(searchString)
              .createQuery();


I use Luke to find type.id, catalogs.id indexed, but type.name and catalogs.name not indexed. I check the hibernate search document carefully and cannot find any problem with my codes.
I also check that the data inserted into database are OK, and most part of the data are indexed.
Who can help tell me why?


Top
 Profile  
 
 Post subject: Re: hibernate search @IndexedEmbedded not indexing
PostPosted: Wed Jun 13, 2012 9:47 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I wrote a quick unit test using your 3 entities, and I couldn't find any problem: it's indexing all fields as expected, including catalogs.name and type.name

Did you check that type.name and catalogs.name have a non-null and non-empty value? Keep in mind that Luke might not show fields for which no value was indexed.

Your Query might not be matching the indexed Document as you are expecting; it might be easier (for debugging purposes) to use a MatchAllDocsQuery, and then use projection to extract all stored fields (you might want to use some more stored fields for this purpose).

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: hibernate search @IndexedEmbedded not indexing
PostPosted: Wed Jun 13, 2012 11:17 pm 
Newbie

Joined: Tue Jun 12, 2012 2:12 am
Posts: 2
Hi sanne.grinovero,
Thanks a lot for your reply. I find the reason.
I insert a entity object in a wrong way as following:
Code:
curl --header "Content-type: application/json" --data "{\"district\":1, \"appName\":\"appName\" ,\"thumbnail\":\"thumbnail\", \"description\":\"description\" ,\"publisher\":1, \"type\":{\"id\":1}, \"catalogs\":[{\"id\":1},{\"id\":2}], \"status\":1, \"state\":1, \"isPopular\":1}" http://localhost:9000/app/save

type.name and catalogs.name are null. I don't allocate values to type.name, catalogs.name because I don't have to when insert data using JPA, although indexing doesn't work well. Thank you very much.


Top
 Profile  
 
 Post subject: Re: hibernate search @IndexedEmbedded not indexing
PostPosted: Thu Jun 14, 2012 6:26 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
specifically about
Quote:
I don't have to when insert data using JPA, although indexing doesn't work well.


what do you mean that it doesn't work well? Not indexing those values is correct, it just explains why you don't see those fields in Luke.

If you want to add some marker token on null values instead of "adding nothing", you could use the "indexNullAs" property of @Field to write some literal constant of your choice.

_________________
Sanne
http://in.relation.to/


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.