-->
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.  [ 7 posts ] 
Author Message
 Post subject: [Hibernate Search] FullTextQuery not returning all results
PostPosted: Wed Oct 24, 2007 6:10 pm 
Newbie

Joined: Wed Oct 24, 2007 6:02 pm
Posts: 3
Hi,

I am having some trouble getting list() to return all my results in a Hibernate Search query. If I call query.getResultSize() I get a number like 13. But when I call the list() method, I often get either nothing or only a single result in the returned List. Has anybody seen this problem before?

I've run the exact query against the native Lucene index using an IndexSearcher and that returns all the hits that I expect to find. However, going through the FullTextQuery, I run into the problem described above.

Thanks,
Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 11:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Maybe you are running your test over and over by cleaning your database without cleaning your index between each test

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 11:22 am 
Newbie

Joined: Wed Oct 24, 2007 6:02 pm
Posts: 3
Emmanuel,

Thanks for the quick response. I don't believe that this is the problem because in a test I've also successfully loaded each the corresponding objects found through native lucene index from the database through hibernate. So I know the records are there.

I am using a TwoWayFieldBridge for the documentid field of my indexed class. I've added some logging into the get and stringToObject methods of the class and they're both being called as expected. Any other ideas as to why I'm experiencing this behavior?

Thanks,
Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 11:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Nothing obvious, I still think it's something related to the diff between the index and the DB, but maybe the custom fieldbridge has some issue. Can you post the field bridge impl?
If it's not that, will you be able to create a minimal test case that reproduce the issue? One that create the data, index it ( ftSession.index() ) and then show the behavior. It must be something trivial but I can't see it now :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 25, 2007 12:29 pm 
Newbie

Joined: Wed Oct 24, 2007 6:02 pm
Posts: 3
Here is the code for my bridge. If you don't see anything obvious I'll see if I can create the test case for it.

public class CompositeIdBridge implements TwoWayFieldBridge
{
private static Log log = LogFactory.getLog(CompositeIdBridge.class);

public String objectToString(Object object)
{
//log.info("objectToString received object " + object);
if (object == null)
return "";

Id compId = (Id) object;
return compId.getSiteCode() + "-" + compId.getExternalId();
}

public Object stringToObject(String value)
{
//log.info("stringToObject received value " + value);
Id id = null;

if (StringHelper.isNotEmpty(value))
{
try
{
String[] keyComponents = value.split("-");
if (keyComponents.length == 2)
{
id = new Id();

id.setSiteCode(Integer.parseInt(keyComponents[0]));
id.setSite(ExternalSite.findByCode(id.getSiteCode()));
id.setExternalId(keyComponents[1]);
}
else
{
log.error("ERROR - could not convert id string to object [" + value + "]");
}
}
catch (Exception e)
{
log.error("ERROR - Could not translate the following string to object [" + value + "]");
}
}

//log.info("stringToObject returning value " + id);
return id;
}

public Object get(String name, Document document)
{
//log.info("get received value " + name + " from document " + document);
Field field = document.getField(name);
if (field == null)
{
return stringToObject(null);
}

return stringToObject(field.stringValue());
}

public void set(String name, Object value, Document document, Field.Store store,
Field.Index index, Float boost)
{
//log.info("set received name " + name + " value " + value + " document " + document + " Store " + store + " Index " + index + " boost " + boost);
String indexedString = objectToString( value );

//Do not add fields on empty strings, seems a sensible default in most situations
//TODO if Store, probably also save empty ones
if (StringHelper.isNotEmpty( indexedString ))
{
Field field = new Field(name, indexedString, store, index);
if (boost != null)
{
field.setBoost(boost);
}
document.add(field);
}
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 27, 2007 12:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I might know what is going wrong. I would appreciate a small test case to confirm and fix.
Can you try to create query by filtering 2 classes instead of one
ftSession.createFullTextQuery(luceneQuery, MyEntity1.class, MyEntity2.class)

Since you're using a composite id, the query using 'in' probably fails.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: FullTextQuery.list always return empty list
PostPosted: Wed Dec 31, 2008 4:24 pm 
Newbie

Joined: Wed Dec 31, 2008 4:13 pm
Posts: 3
I have the following code snippet where in some cases the call to ftQuery.getResultSize() returns > 0 but the ftQuery.list() actually returns an empty list. I have several test cases and only in some cases does this situation arise.

Code:
            // wrap Lucene query in a org.hibernate.Query
            FullTextQuery ftQuery = fullTextSession.createFullTextQuery(query, returnTypes);
           
            // Log the query we are using
            logQuery(ftQuery);

            // execute search
            retObj = ftQuery.list();

            logger.debug("### results size: " + ftQuery.getResultSize() + ", results: " + retObj);


when I output the actual query hibernate is running and run it in TOAD the query works fine given the values from the ID field. I ran the lucene query in Luke and the number of results matches the ones from the sysout above.

I should mention that on my entity the ID is a composite class.

Here is the FieldBridge I wrote for the composite key.
Code:
public class SearchTermsViewIdFieldBridge implements TwoWayStringBridge {
   
   @Override
   public String objectToString(Object arg0) {
      
      String retString = null;
      
      if (arg0 instanceof SearchTermsViewId) {
         SearchTermsViewId id = (SearchTermsViewId)arg0;
         StringBuilder sb = new StringBuilder();
         retString = sb.append(id.getSearchRef()).append("_")
                     .append(id.getSearchRefId()).append("_")
                     .append(id.getXSearchTermId())
                     .toString();
      }
      
      return retString;
   }

   @Override
   public Object stringToObject(String arg0) {
      
      String[] fields = arg0.split("_");
      
      SearchTermsViewId id = new SearchTermsViewId();
      id.setSearchRef(fields[0]);
      id.setSearchRefId(fields[1]);
      id.setXSearchTermId(fields[2]);
      
      return id;
   }


Any suggestions?


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