-->
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 - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Wed Apr 20, 2011 11:41 am 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
In my hibernate object, I have annotations set related to the data. They are mostly automatically generated (custom) by a translation done from an XML schema, so we end up with cases like this:

Code:
/* SORTING FAILS! */
   @Column(name = "DateReceived")
   @Fields( { @Field(index = Index.UN_TOKENIZED),
   @Field(name = "SORT_DateReceived", index = Index.UN_TOKENIZED) })
/**
  * A date field that comes across as a string
  */
private String DateReceived;


There are other fields that are like this:
Code:
/* SORTING WORKS! */
@Column(name = "VER")
@Fields( { @Field, @Field(name = "SORT_VER", index = Index.UN_TOKENIZED) })
private String VER;



In the latter case, sorting works just fine. When trying to sort the fields from the former case (SORT_DateReceived), I get an ArrayIndexOutOfBoundsException:
Code:
java.lang.ArrayIndexOutOfBoundsException: 2
at org.apache.lucene.search.FieldCacheImpl$StringIndexCache.createValue(FieldCacheImpl.java:721)
at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:224)
at org.apache.lucene.search.FieldCacheImpl.getStringIndex(FieldCacheImpl.java:692)
at org.apache.lucene.search.FieldComparator$StringOrdValComparator.setNextReader(FieldComparator.java:667)
at org.apache.lucene.search.TopFieldCollector$MultiComparatorNonScoringCollector.setNextReader(TopFieldCollector.java:435)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:249)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:240)
at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:181)
at org.apache.lucene.search.Searcher.search(Searcher.java:90)
at org.hibernate.search.query.QueryHits.updateTopDocs(QueryHits.java:110)
at org.hibernate.search.query.QueryHits.<init>(QueryHits.java:68)
at org.hibernate.search.query.FullTextQueryImpl.getQueryHits(FullTextQueryImpl.java:408)
at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:326)
...
...


There is a lot more to the stack trace, but... I can't for the life of me figure out what is causing this.


Last edited by rehtonAesoohC on Wed Apr 20, 2011 12:50 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Hibernate Search - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Wed Apr 20, 2011 11:50 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
which version of Lucene are you using? and which version of Hibernate Search?
Can you post the query ?

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


Top
 Profile  
 
 Post subject: Re: Hibernate Search - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Wed Apr 20, 2011 12:41 pm 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
s.grinovero wrote:
Hi,
which version of Lucene are you using? and which version of Hibernate Search?
Can you post the query ?


Lucene v2.9.3
Hibernate Core 3.5.4-final
Hibernate Search 3.2.1-final
Hibernate Annotations 3.2.0-final

Here is the code that calls the sorting:
Code:
FullTextSession fullTextSession = Search.getFullTextSession(this.sessionFactory.getCurrentSession());
        MultiFieldQueryParser parser = new MultiFieldQueryParser(
                Version.LUCENE_29, fields, fullTextSession.getSearchFactory().getAnalyzer(custom-object.class));
        List<custom-object> list = null;
        try {
            org.apache.lucene.search.Query query = parser.parse(searchQuery);
            org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, custom-object.class).setMaxResults(results).setFirstResult(index);
            org.apache.lucene.search.Sort sorter = new Sort();

            if (sortFields != null && sortFields.length > 0) {
                sorter.setSort(sortFields);
            } else {
                SortField sf = new SortField(searchQuery, SortField.STRING);
                sorter.setSort(sf);
            }

            fullTextQuery.setSort(sorter);
            list = fullTextQuery.list();
        } catch (ParseException e) {
            logger.error("", e);
        }


I changed the name of the object there, just FYI :). (Not actually using 'custom-object') And the Lucene search query (all our queries are generated using a custom query-builder, this is a random query that was generated) looks like this:

Code:
(ATP:[\! TO ????????????] AND NOT ATP:[\! TO 050])


Top
 Profile  
 
 Post subject: Re: Hibernate Search - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Wed Apr 20, 2011 4:20 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
looking into the code of that version of Lucene it looks like as if this error is only possible if you are having more terms in this field than documents, but that's not possible if you use the Index.UN_TOKENIZED as on your model (which looks like correct).

Is it possible you previously indexed some entities without having this indexing option?
Try removing the index and creating a new one.

If that doesn't help, this looks like a bug in Lucene so please try upgrading to the latest Lucene 3.1.0 (which would need an upgrade to hibernate Search 3.4.0.Final); if you have no luck you can send me an executable unit test and I will have a look into it.

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


Top
 Profile  
 
 Post subject: Re: Hibernate Search - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Thu Apr 21, 2011 9:45 am 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
s.grinovero wrote:
Hi,
looking into the code of that version of Lucene it looks like as if this error is only possible if you are having more terms in this field than documents, but that's not possible if you use the Index.UN_TOKENIZED as on your model (which looks like correct).

Is it possible you previously indexed some entities without having this indexing option?
Try removing the index and creating a new one.

If that doesn't help, this looks like a bug in Lucene so please try upgrading to the latest Lucene 3.1.0 (which would need an upgrade to hibernate Search 3.4.0.Final); if you have no luck you can send me an executable unit test and I will have a look into it.


I have this error when I create a new index with no previously indexed entities :(. I'll look into Lucene 3.1.


Top
 Profile  
 
 Post subject: Re: Hibernate Search - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Thu Apr 21, 2011 6:23 pm 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
Also, note that I changed the field to this:

Code:
// The FIX_DateReceived field somehow magically fixes the ArrayIndexOutOfBoundsException
        @Column(name = "DateReceived")
   @Fields( { @Field(index = Index.UN_TOKENIZED),
         @Field(name = "FIX_DateReceived"),
         @Field(name = "SORT_DateReceived", index = Index.UN_TOKENIZED) })
   /**
    * A date field that comes across as a string
    */
   private String DateReceived;


And sorting worked again. Can use that as a work-around for now, until we can upgrade lucene (very risky at this point).


Top
 Profile  
 
 Post subject: Re: Hibernate Search - Sort Causes ArrayIndexOutOfBoundsExceptio
PostPosted: Tue Apr 26, 2011 11:13 am 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
Also, as a followup to this, the SortField object we were using was using SortField.STRING for the TYPE parameter.

Changing this to SortField.STRING_VAL completely eliminated the bug.


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.