-->
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: Search results problem
PostPosted: Mon Jul 16, 2012 1:24 pm 
Newbie

Joined: Mon Jul 16, 2012 1:11 pm
Posts: 12
Hi,

I have a problem with strange results in my Search. I have User class with indexed name and lastname fields:

Code:
@ManagedBean(name = "userBean")
@Entity
@Table(name = "user_User")
@Indexed
@AnalyzerDef(name = "searchtokenanalyzer", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = {
      @TokenFilterDef(factory = StandardFilterFactory.class),
      @TokenFilterDef(factory = LowerCaseFilterFactory.class),
      @TokenFilterDef(factory = StopFilterFactory.class, params = { @Parameter(name = "ignoreCase", value = "true") }) })
@Analyzer(definition = "searchtokenanalyzer")
public class User extends Node implements Comparable<User> {

private String name;
private String lastname;
private Post currentStatus;

@Column(name = "name", nullable = true)
   @Field
   @Analyzer(definition = "searchtokenanalyzer")
   public String getName() {
      return name;
   }
@Column(name = "lastname", nullable = true)
   @Field
   @Analyzer(definition = "searchtokenanalyzer")
   public String getLastname() {
      return lastname;
   }
@OneToOne
   public Post getCurrentStatus() {
      return currentStatus;
   }
...


Class Post has OneToOne relation to user, but it doesn't have any indexed field.

Code:
@Entity
@Table(name = "content_Post")
public class Post extends Node {


The method that has to find Users based on their names or lastnames, returns both User and Post instances.

Code:
Session session = persistence.currentManager();
FullTextSession fullTextSession=Search.getFullTextSession(session);
QueryBuilder qBuilder=fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(User.class).get();
Query query=qBuilder.keyword().wildcard().onField("name").andField("lastname").matching(searchString+"*").createQuery();
org.hibernate.Query hibQuery=fullTextSession.createFullTextQuery(query, User.class);
@SuppressWarnings("unchecked")
List<User> result=hibQuery.list();


I would expect that only User class instances are returned as result, and I don't have an idea what could be a problem here.
Could you please help me about this?


Top
 Profile  
 
 Post subject: Re: Search results problem
PostPosted: Tue Jul 17, 2012 5:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

the code looks correct an you are even restricting the search to a given class type (User). It should work. I don't see how your search would return Post instances.

The only thing I am not seeing is how you index everything. Do you have an old index which maybe contains stale data? Or is he problem occurring as part of a unit test (or something like that) using a clean index?

I would try to cut the example down to a minimum (removing analyzers, @Column annotation, etc). Just the required mappings. If you can replicate the problem in this environment and preferably provide a test case I can try to replicate it.

Another idea is to actually inspect the index using Luke (in this case it helps if you also store the actual indexed state via (@Field(store = Store.YES).

--Hardy


Top
 Profile  
 
 Post subject: Re: Search results problem
PostPosted: Tue Jul 17, 2012 8:50 am 
Newbie

Joined: Mon Jul 16, 2012 1:11 pm
Posts: 12
Hi Hardy,
hardy.ferentschik wrote:
Hi,
Do you have an old index which maybe contains stale data?
--Hardy

Yes. It seems that this was the problem. I can't reproduce it as soon as I deleted index files.

Thanks


Top
 Profile  
 
 Post subject: Re: Search results problem
PostPosted: Tue Jul 17, 2012 8:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Good :-)


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.