-->
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.  [ 2 posts ] 
Author Message
 Post subject: No results returned
PostPosted: Mon Dec 19, 2011 4:16 pm 
Newbie

Joined: Thu Dec 08, 2011 5:43 pm
Posts: 7
When I open up my index with Luke, I can query on the subjectDN field with the string "subjectdn1", and get 10+ results back. When I do it in code... I don't get anything back. I think I'm missing something.
Code:
  @Test
  public void searchForUsers() throws Exception {
     ftem = Search.getFullTextEntityManager(em);  // em is initialized in setup()

     QueryBuilder qb = ftem.getSearchFactory().buildQueryBuilder().forEntity(JPAUser.class).get();

     org.apache.lucene.search.Query qry = qb.keyword().onField("subjectDN").matching("subjectdn1").createQuery();

     javax.persistence.Query JPAftq = ftem.createFullTextQuery(qry, JPAUser.class);
    
     List<?> result = JPAftq.getResultList();

     System.out.println(result.toString());
     if(result.isEmpty())
        System.out.println("empty result set");
     else
        System.out.println("non-empty result set");
  }

output is:
[]
empty result set

I THINK the above code is properly setup. I have a feeling my mistake may lay in my JPAUser class:
Code:
@Indexed(index = "fulltext")
@Entity
@Table(name = "USER")
public class JPAUser extends User implements java.io.Serializable {

  // there are no global variables
  // left out constructors for the sake of space

  @Override
  @DocumentId
  @Id
  @Column(name = "user_id")
  @GeneratedValue(strategy = GenerationType.SEQUENCE)
  public long getUserId() {
    return super.getUserId();
  }

  @Override
  public void setUserId(long userId) {
    super.setUserId(userId);
  }

  @Override
  @Field(analyze = Analyze.YES, index = Index.YES, store = Store.YES)
  @Boost(value=2.0f)
  public String getEmail() {
    return super.getEmail();
  }

  @Override
  public void setEmail(String email) {
    super.setEmail(email);
  }

  @Override
  @Field(analyze = Analyze.YES, index = Index.YES, store = Store.YES)
  public String getSubjectDN() {
    return super.getSubjectDN();
  }

  @Override
  public void setSubjectDN(String subjectDN) {
    super.setSubjectDN(subjectDN);
  }
}

I'm not convinced I have this annotated properly.


Anyways, any ideas why I'm not getting anything?
Thanks.


Top
 Profile  
 
 Post subject: Re: No results returned
PostPosted: Wed Dec 21, 2011 11:44 am 
Hibernate Team
Hibernate Team

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

is the example you are given an actual example of your data? Using the approach you have shown the standard analyzer will be applied on your search string "subjectdn1" and the resulting tokens used in a term query. Is this what you want? And are you using the same type of query in Luke? Or are you maybe using wildcard search there?
Also remember the values you see in Luke are the field values as is (store = Store.YES), not the actual searchable tokens. Have you tried adding '.ignoreAnalyzer()' between onField() and matching().
This are only some tips. It all depends how EXACTLY your values look like, but in most cases where people mentioned a mismatch between Lucke and a fulltext query, the problem was that in fact not the same query was applied (think analyzer here).

--Hardy


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