-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate Search not returning results in my Spring MVC app
PostPosted: Tue Aug 19, 2008 9:08 am 
Beginner
Beginner

Joined: Tue Aug 12, 2008 9:06 am
Posts: 22
Location: Fort Washington, PA
I have implemented the hibernate search, and I'm trying to return results when someone clicks the Search button to a table. Before Hibernate search we were using the hibernate criteria against SQL Server full-text capabilities, but wanted to drop the SQL Server dependency. So currently I'm using Hibernate Annotations, Spring MVC, and JSP.

My problem, is that I've having a hard time in the final step of returning the results...


I have a jsp search page, and when the user enters search criteria and clicks Search, it bulds a SearchCriteria object containing the information. Then in the ModelandView method of my Controller, I have this code:
Code:
ModelAndView mav = new ModelAndView("redirect:recordings.jsp");
        RecordingSearchCriteria recordingSearchCriteria = ((RecordingsCommand) command).getRecordingSearchCriteria();
        if (recordingSearchCriteria.getRecordingUID() != null) {
            List list = recordingsService.getRecordingsWithLucene(recordingSearchCriteria);
            mav.addObject("recordingSearchCriteria.recordingUID", recordingSearchCriteria.getRecordingUID());
        }
        return mav;


That calls my service, which calls my hibernateDAO class. Here is the method to return the list of Recording class results...
Code:
public List getRecordingsWithLucene(RecordingSearchCriteria recordingSearchCriteria) {
        String searchQuery = "";
        if (recordingSearchCriteria != null) {
            if (recordingSearchCriteria.getRecordingUID() != null) {
                searchQuery = "recordingID:" + recordingSearchCriteria.getRecordingUID().toString();

                QueryParser parser = new QueryParser("luceneRequiredIdentifier", new StandardAnalyzer());

                org.apache.lucene.search.Query luceneQuery;
                try {
                    luceneQuery = parser.parse(searchQuery);
                }
                catch (ParseException e) {
                    throw new RuntimeException("Unable to parse query: " + searchQuery, e);
                }

                Session session = super.getSessionFactory().getCurrentSession();
                FullTextSession ftSession = Search.createFullTextSession((session));
                org.hibernate.Query query = ftSession.createFullTextQuery(luceneQuery, Recording.class);

                return query.list();
            } else
                return null;
        } else
            return null;
    }



Nothing is getting returned at all... I don't know if its getting to my index. Any help would be very grateful...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 4:12 am 
Hibernate Team
Hibernate Team

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

I just have a few suggestions on how to hunt down your problem:

* Check your configuration settings. To start with we recommend you use a FSDirectoryProvider and point out a location on the file system for the index.
* How do you create your initial index? If you start with an existing non empty database you will have to trigger an initial indexing. See the online docs for this
* Once you have confirmed your settings and triggered an initial index you can check whether and what data got indexed with Luke. See http://hibernate.org/440.html.

I hope this points you into the right direction. If you still have problems after verifying all these steps you will have to post the code for the initial indexing, you configuration file and your annotated entities.

Good luck ;-)

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 2:58 pm 
Beginner
Beginner

Joined: Tue Aug 12, 2008 9:06 am
Posts: 22
Location: Fort Washington, PA
I am still experience problems...

I am using the FSDirectoryProvider and my index has everything in it that I need. I'm executing queries in the Luke Toolbox against the created query and its returning what I want.

I have my code in a JUnit Test and it returns exactly what I'm looking for.

However, when I copy/paste that same code into my application it returns nothing!

Here is how I index:
Code:
public void CreateLuceneIndex() {
        Session session = this.hibernateTemplate.getSessionFactory().openSession();
        FullTextSession fullTextSession = Search.createFullTextSession(session);
        fullTextSession.getTransaction().begin();

        List<Utterance> utterances = session.createQuery("from Utterance").list();
        for (Utterance utterance : utterances) {
            fullTextSession.index(utterance);
        }
        fullTextSession.getTransaction().commit();
}


Here is my query Test:
Code:
String searchQuery = "line:And";
        QueryParser parser = new QueryParser("turn.tempTranscript.recordingUID", new SimpleAnalyzer());
        org.apache.lucene.search.Query luceneQuery;
        try {
            luceneQuery = parser.parse(searchQuery);
        }
        catch (ParseException e) {
            throw new RuntimeException("Unable to parse query: " + searchQuery, e);
        }
        FullTextSession ftSession = Search.createFullTextSession((session));
        org.hibernate.Query query = ftSession.createFullTextQuery(luceneQuery);

        System.out.println("Size: " + query.list().size());


..and when I debug that test is prints out the same result size as when I execute it in the Luke toolbox. Does it have anything to do with how I am using Session??


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:29 am 
Hibernate Team
Hibernate Team

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

I am a little confused regarding the document fields you are trying to search against. The query in you initial posting is not the same as the query in the test code you just posted. In the former you used recordingID and in the latter line:And. I am also a little confused that in your QueryParser constructor you always specify a completely different default field. Depending on your use case that might be ok, but ...
To get more help you really have to post your annotated classes and the exact query you want to execute against them.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:34 am 
Beginner
Beginner

Joined: Tue Aug 12, 2008 9:06 am
Posts: 22
Location: Fort Washington, PA
The code I have in a JUnit Test class passes fine and returns the size of the results to what I expect...
That is this code, with a lucene query string hard-coded to get some results.
Code:
String searchQuery = "line:And";
        QueryParser parser = new QueryParser("turn.tempTranscript.recordingUID", new SimpleAnalyzer());
        org.apache.lucene.search.Query luceneQuery;
        try {
            luceneQuery = parser.parse(searchQuery);
        }
        catch (ParseException e) {
            throw new RuntimeException("Unable to parse query: " + searchQuery, e);
        }
        FullTextSession ftSession = Search.createFullTextSession((session));
        org.hibernate.Query query = ftSession.createFullTextQuery(luceneQuery);

        System.out.println("Size: " + query.list().size());
       
        session.close();


For example sake, I'm taking out the recordingID, and just keeping the same hard-coded value. In my application, I have the exact same code, and when this code runs without errors, it returns no results!

I notice that in my test, I open a new Session, but in my application code, I'm using a getter from my super class to get the session and I'm using that. But that shouldn't make any different.

I'm sorry for the confusion. Do you have any ideas??
And thanks for your replies so far.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:37 am 
Beginner
Beginner

Joined: Tue Aug 12, 2008 9:06 am
Posts: 22
Location: Fort Washington, PA
the "line:And" is a lucene query that I'm using against my index. It returns 4 results from my index where the "line" property has data in it like "I'm fine, and you?" or "I am going here and there". Its data based on transcripts, so its mainly sentences, and I'm looking for those sentences by entering a search word.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 9:12 am 
Hibernate Team
Hibernate Team

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

There is one more difference I can see. In your main code you explicitly search against the Recording index. Whereas in your test you search over all indexes. Looking at your indexing code it seems that the class you are indexing is Utterance. If this is the only class you are indexing you will have to use
Code:
ftSession.createFullTextQuery(luceneQuery, Utterance.class);



--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 9:20 am 
Beginner
Beginner

Joined: Tue Aug 12, 2008 9:06 am
Posts: 22
Location: Fort Washington, PA
I agree with your point, but since I made my first post, I've made that change to just say
Code:
ftSession.createFullTextQuery(luceneQuery);

So that it will search is all indexes. (I only have one index though to make life easier)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 9:50 am 
Beginner
Beginner

Joined: Tue Aug 12, 2008 9:06 am
Posts: 22
Location: Fort Washington, PA
I'm walking through a Debug of both my test and my application side by side in Intellij, and having all the variables open and tracing through them, they seem like completely identical situations. Every object has the same variables and properties set, and yet one produces a result set of size 4 and the other a result set of size 0...

Makes no sense at all...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 22, 2008 1:12 am 
Beginner
Beginner

Joined: Wed Aug 24, 2005 5:32 am
Posts: 23
Hi

If I understand correctly the question it looks to me that there is one small, but important, different between your JUnit and application code. In the Junit code your parser uses the SimpleAnalyzer:

Code:
QueryParser parser = new QueryParser("turn.tempTranscript.recordingUID", new SimpleAnalyzer());


While our application code uses the StandardAnalyzer:

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


This is a big different: the standard analyzer includes the StopFilter, since your query is 'line:And' when using the StandardAnalyzer the query is actually empty ('and' is a stop word).

You can see more at the end of that entry on my blog: http://www.jroller.com/eyallupu/entry/an_introduction_to_hibernate_search

Hope it helps,
Eyal Lupu


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