-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Search Results - fullTextQuery.list() problem
PostPosted: Wed Dec 05, 2007 1:55 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
Hi,

I am executing a simple query on two fields (title and description) and expect 24 results for the query.
While the resultSize that is fetched is correct, the list returned contains only two results.
Here is the piece of code that I use.

String[] q = new String[] {
advSearchCriteria.getSearchString(),
advSearchCriteria.getSearchString()};

Query luceneQuery = MultiFieldQueryParser.parse(q, new String[] {
"i_title", "i_description" }, new StandardAnalyzer());

org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession
.createFullTextQuery(luceneQuery, FaculteClass.class);
fullTextQuery.setFirstResult(0);

// execute search
List list = fullTextQuery.list(); //list contains only two objects.
resultCount = fullTextQuery.getResultSize(); //this value is 24
// parse result
return parseClassResult(list);

Any help will be greatly appreciated
Thanks,
-rahul


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 6:06 am 
Newbie

Joined: Wed Nov 28, 2007 10:04 pm
Posts: 10
You can try to use getResultList method of FullTextQuery class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 7:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Are you setting somewhere setMaxResult()? This could influence the size of the returned list. getResultSize() in returns the total number of hits independent of 'pagination'.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 8:23 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
Nope, aint using setMaxResults anywhere...actually, tried to explicitly set that to around 25 as well but still the same result.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 8:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you don't mess with setCriteriaQuery, do you? And you're using the latest version?
After those questions, try and create a minimal test case and post it to JIRA

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 11:16 am 
Newbie

Joined: Thu Nov 29, 2007 7:15 am
Posts: 7
nope, no messing with setCriteriaQuery and am using release 3.0.0 ga.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 11:43 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah I know :)
You have emptied your database without emptying your index (for a test maybe).

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Problem in org.hibernate.search.engine.QueryLoader.load
PostPosted: Tue Dec 11, 2007 4:14 am 
Newbie

Joined: Tue Dec 11, 2007 2:57 am
Posts: 3
Hi Emmanuel, Hardy,

I think the problem mentioned above is due to the following piece of code in org.hibernate.search.engine.QueryLoader.load(EntityInfo... entityInfos) :

criteria.add( disjunction );
criteria.list(); //load all objects

//mandatory to keep the same ordering
List result = new ArrayList(entityInfos.length);
for (EntityInfo entityInfo : entityInfos) {
Object element = session.load( entityInfo.clazz, entityInfo.id );
if ( Hibernate.isInitialized( element ) ) {
//all existing elements should have been loaded by the query,
//the other ones are missing ones
result.add( element );
}
}
return result;

The session.load does not load the object and if its not initialized then its not added to the final result list. I was able to find this out by debugging the Hibernate Search source code.

Also this behavior is not consistent. It varies with the no. of records being fetched. For example here are few use cases:

1. In my DB I have 5 records with "Class_<no>" in the 'title' field. The <no> is is an integer(Class_1, Class_2, etc.). It sometimes returns me 1, sometimes 2 records when the search criteria is "class*". The resultListCount returned by fullTextQuery.getResultSize() is 5 which is as expected.

2. I have 20 records with "Indoor Photography_<no>" in the title field. On firing a search with either "indoor*" or "photo*", the result list is empty although the resultListCount returned by fullTextQuery.getResultSize() is 20 which is as expected.

Awaiting to hear something from you guys.

--Regards,
Rakesh Shete


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 9:45 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
This also sounds to me as if your index is not in sync with the actual objects you have in the db. If you get a list of EntityInfo objects, but load.session() keeps returning null it somehow indicates that the object does not exist in the database.

How do you index your data? Do you rely on the automated indexing or do you trigger a manual indexing of the data. Try using a RAMDirectoryProvider. This would prevent having a stale index. That's just an idea to narrow down you problem.

The only case where I had a similar problem was when setting up JUnit tests for Hibernate Search within a Spring environment using Spring's AbstractJpaTests.

AbstractJpaTests creates a transaction for each test, but in each test I had to first index and commit the transaction before being able to test searches. Not sure if the following lines of codes are toom uch out of context, but the idea is:

Code:
// load some test data usinf dbunit
DbUnitHelper.loadTestData("/testIndexCompanies.xml");

// index the test data
indexService().indexAll();

// now make sure that the 'indexing' transaction completes before doing any searches
setComplete(); // make sure the transaction commits instead of rolling back.
endTransaction();
startNewTransaction();

// do some searching


Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 10:35 am 
Newbie

Joined: Tue Dec 11, 2007 2:57 am
Posts: 3
Hi Hardy,

The indexing is done only once for my application through an load-on-startup servlet and only once. Here is the code for the same:

public void indexClasses() {
SessionFactory sessionFactory = getSessionFactory();
Session session = sessionFactory.openSession();
FullTextSession fullTextSession = Search.createFullTextSession(session);
fullTextSession.setFlushMode(FlushMode.MANUAL);
fullTextSession.setCacheMode(CacheMode.IGNORE);
Transaction transaction = fullTextSession.beginTransaction();
// Scrollable results will avoid loading too many objects in memory

ScrollableResults results = fullTextSession.createCriteria(
FaculteClass.class).scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while (results.next()) {
index++;
fullTextSession.index(results.get(0)); // index each element
}
transaction.commit();
}

Also I have again debugged through the QueryLoader.load. I do not get null objects for session.load() but proxies which are uninitialized and thats why they are not added to the final result list. I also checked the 'id' value that is passed to the session.load() method. A record for every 'id' exists.

So I do not believe that it is problem of the indexes being out of sync.

Do we have any problem using session.get()?

I understand that session.load() must be used to improve performance and allow lazy initialization.

I think if this is a concern then we could provide an API where we provide the option lazy loading the objects that would be part of the result. Thoughts?

--Regards,
Rakesh Shete


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 12, 2007 2:02 am 
Newbie

Joined: Tue Dec 11, 2007 2:57 am
Posts: 3
Can anyone help me here?

I am stuck at the moment


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 9:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The code in HSearch is I believe correct.
I load the object list using the criteria API,
Then get the object using load(). The objects should by then be loaded unless they are not present in the DB. This behavior is what is expected in most cases. In other words, I do not use load to optimize things, but just to have the correct behavior (this is what is explained in the comments BTW).

Try and check to see the reason wht the criteria.list() does not load all the objects, you should find the problem.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: similar problem but the other way round :)
PostPosted: Mon Jan 07, 2008 7:59 am 
Newbie

Joined: Thu Dec 20, 2007 10:07 am
Posts: 2
I am facing similar problem, the difference is that fullTextQuery.list() returns the correct number of rows, but fullTextQuery.getResultSize() does not.

I am using criteria with the search query (I have to narrow down my result set). The code follows:

Code:
Criteria criteria = fullTextSession.createCriteria(getPersistentClass()).add(
                  Expression.eq("blabla.id", blablaIdValue));
fullTextQuery.setCriteriaQuery(criteria);


The list() method works perfectly (as before mentioned), it seems as if the getResultSize() does not take the criteria into account when returning row count.

Am I doing anything wrong here? The Hibernate Search manual says
Quote:
The Hibernate query built on top of the Lucene query is a regular org.hibernate.Query , you are in the same paradigm as the other Hibernate query facilities (HQL, Native or Criteria)

so in my opinion it should work. Should I post a bug in JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 9:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Criteria used in fullTextQuery.setCriteriaQuery(criteria);
must not be constrained. it should only be used to change the fetching strategy.

I believe it's written both in the Javadoc and the reference documentation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 11:09 am 
Newbie

Joined: Thu Dec 20, 2007 10:07 am
Posts: 2
emmanuel wrote:
Criteria used in fullTextQuery.setCriteriaQuery(criteria);
must not be constrained. it should only be used to change the fetching strategy.

I believe it's written both in the Javadoc and the reference documentation

Constrained Criteria work when I fetch the results with list(), it just does not work with getResultSize().

I understand it can be hard to change this behaviour in Hibernate Search right now but is there any reasonable workaround for this problem? I am searching through a really large number of entities and using pagination. I need to display search result count (the constrained one) on each result page.

Fetching ALL search results by list() and calling size() on the big List seems to be a performance bottleneck.

What would you choose if you were facing such problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.