-->
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.  [ 12 posts ] 
Author Message
 Post subject: Search returning no results
PostPosted: Tue Apr 27, 2010 3:23 pm 
Newbie

Joined: Tue Apr 27, 2010 3:17 pm
Posts: 4
I'm trying to get a simple Hibernate searcher set up, and while my objects are being indexed correctly, no results are returned with any query. Here's my
code:
Code:
      EntityManager em = entityManagerFactory.createEntityManager();
      EntityTransaction tx = em.getTransaction();
      tx.begin();
      
      FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);

      QueryParser parser = new QueryParser("questiontext", new SimpleAnalyzer());
      org.apache.lucene.search.Query query = null;
      
      try
      {
         query = parser.parse("test");
      }
      catch(ParseException p)
               {
                       System.out.println("exception parsing text...");
                }
      javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, Questions.class);
      List<Questions> result = persistenceQuery.getResultList();
      tx.commit();
      em.close();
      return result;


If I run a query through Luke that says questiontext:test, I get a bunch of expected results, so I know that the index is good and there are items in there that should be returned.

Any ideas? Thanks.


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Tue Apr 27, 2010 5:22 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Are you using the same analyzer for indexing and searching?


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Tue Apr 27, 2010 6:43 pm 
Newbie

Joined: Tue Apr 27, 2010 3:17 pm
Posts: 4
I don't set up an analyzer for indexing, I guess I'm using whatever default analyzer is there?

Here's my indexing:
Code:
      EntityManager em = entityManagerFactory.createEntityManager();
      EntityTransaction tx = em.getTransaction();
      tx.begin();
      
      FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em);
      List<Questions> questions = em.createQuery("SELECT question FROM Questions AS question").getResultList();
      for (Questions question : questions)
      {
         fullTextEntityManager.index(question);
      }

      
      tx.commit();
      em.close();


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Wed Apr 28, 2010 1:36 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Can you try new StandardAnalyzer(), if you are using Lucene 2.9 then you'll need to pass the version into the constructor. I presume Question object is very simple with one field questiontext?


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Wed Apr 28, 2010 4:22 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Can you try this:

Code:
@Entity
@Table(name = "QUESTION")
@Analyzer(impl = StandardAnalyzer.class)
@Indexed
public class Question {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "QUESTION_ID")
    @DocumentId
    private Long id;

    @Column(name = "QUESTION_TEXT")
    @Field(name = "questiontext", store = Store.YES, index = Index.TOKENIZED)
    private String questionText;

   ...getters and setters
}


for searching i used hibernate
Code:
    QueryParser parser = new QueryParser(Version.LUCENE_29, "questiontext", new StandardAnalyzer(Version.LUCENE_29));
                org.apache.lucene.search.Query query = null;
                try {
                    query = parser.parse(term);
                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }

                FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, Question.class);
                org.hibernate.Query hibQuery = fullTextQuery;

                return hibQuery.list();



I've tested the above and get results back.

Cheers
Amin


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Mon May 03, 2010 11:08 am 
Newbie

Joined: Tue Apr 27, 2010 3:17 pm
Posts: 4
Trying to construct the QueryParser as you did throws an error for me:

"The constructer QueryParser(Version, String, Analyzer) is undefined."

If I get rid of the first argument, then I get the error

"The constructor StandardAnalyzer(Version) is undefined."

I am using Lucene-core-2.9.0, so I don't think its a versioning issue...Thoughts?

Sol


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Tue May 04, 2010 4:32 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
I was using 2.9.1

For 2.9.0 You need to do the following:

Code:
QueryParser parser = new QueryParser("questiontext", new StandardAnalyzer());


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Tue May 04, 2010 2:31 pm 
Newbie

Joined: Tue Apr 27, 2010 3:17 pm
Posts: 4
Cool, it's now returning results as it should. I've been playing with the analyzers and this is amazingly powerful stuff!

Question: I noted that in Luke, each result of a query has a relevance "Score." Is there a way to set a cut off for the Score in my java query, so that only highly relevant results will be returned? I'm having an issue with somewhat irrelevant results being returned when I query. I've improved it with StopWordsFilter and that sort of thing, but I'm curious if I can do better...

Sol


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Wed May 05, 2010 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
you can't directly set a threshold, but instead of returning the entities in a query you could use projection to return pairs (score,entity) and hide what's too low.

Generally, it's not considered a good idea: it might happen that the score is lower than usually, still the results on top should be the most relevant you can find for a given query, so best strategy is usually to let the user decide if the results are ok or not.
improving relevance by using smart analyzers like stopword filters and stemmers is your best option

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


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Fri May 10, 2013 5:45 am 
Newbie

Joined: Fri May 10, 2013 5:35 am
Posts: 2
Hello,
I have the same problem with the query result display. But, I have another error message:

Exception in thread "main" java.lang.VerifyError: class org.apache.lucene.analysis.SimpleAnalyzer overrides final method tokenStream.(Ljava/lang/String;Ljava/io/Reader;)Lorg/apache/lucene/analysis/TokenStream;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at TestTagInDocument.main(TestTagInDocument.java:54)

I don't understand this error !
Note that I use the lucene 4.2.1 version and the error is in this line:
[code] org.apache.lucene.queryParser.QueryParser q1 = new QueryParser("path",TextFileIndexer.luceneAnalyzer);

Note also that I can display the result of the indexing process without any error.
Thanks.


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Fri May 10, 2013 6:05 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, you should use Lucene version 3.6.2 with latest Hibernate Search: support for versions 4 isn't integrated yet.

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


Top
 Profile  
 
 Post subject: Re: Search returning no results
PostPosted: Fri May 10, 2013 8:27 am 
Newbie

Joined: Fri May 10, 2013 5:35 am
Posts: 2
sanne.grinovero wrote:
Hi, you should use Lucene version 3.6.2 with latest Hibernate Search: support for versions 4 isn't integrated yet.


Thanks.. It Works !!


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