Developer forum

Forum » Development » Query with sort order throwing IndexOutOfBounds

Query with sort order throwing IndexOutOfBounds

Kasper Laursen
Reply

I am having an issue with the below code.

The code throws the following exception:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Lucene.Net.Search.AnonymousClassLongParser1.ParseLong(String val)
   at Lucene.Net.Search.FieldCacheImpl.LongCache.CreateValue(IndexReader reader, Entry entryKey)
   at Lucene.Net.Search.FieldCacheImpl.Cache.Get(IndexReader reader, Entry key)
   at Lucene.Net.Search.FieldCacheImpl.GetLongs(IndexReader reader, String field, LongParser parser)
   at Lucene.Net.Search.FieldCacheImpl.LongCache.CreateValue(IndexReader reader, Entry entryKey)
   at Lucene.Net.Search.FieldCacheImpl.Cache.Get(IndexReader reader, Entry key)
   at Lucene.Net.Search.FieldCacheImpl.GetLongs(IndexReader reader, String field, LongParser parser)
   at Lucene.Net.Search.FieldComparator.LongComparator.SetNextReader(IndexReader reader, Int32 docBase)
   at Lucene.Net.Search.TopFieldCollector.OneComparatorNonScoringCollector.SetNextReader(IndexReader reader, Int32 docBase)
   at Lucene.Net.Search.IndexSearcher.Search(Weight weight, Filter filter, Collector collector)
   at Lucene.Net.Search.IndexSearcher.Search(Weight weight, Filter filter, Int32 nDocs, Sort sort, Boolean fillFields)
   at Lucene.Net.Search.IndexSearcher.Search(Weight weight, Filter filter, Int32 nDocs, Sort sort)
   at Lucene.Net.Search.Searcher.Search(Query query, Filter filter, Int32 n, Sort sort)
   at Dynamicweb.Indexing.Lucene.LuceneIndexProvider.SearchInternal(IQuery query, QuerySettings settings)
   at Dynamicweb.Indexing.Lucene.LuceneIndexProvider.Query(IQuery query, QuerySettings settings)
   at Dynamicweb.Indexing.Queries.IndexQueryProvider.Query(IQuery query, QuerySettings settings)
   at Dynamicweb.Indexing.Querying.QueryService.Query(IQuery query, QuerySettings settings)
   at Backend.Repositories.<snip>()

However, if I remove the sortOrder from the query, everything runs just fine.

I'm on a time constraint and will probably just handle this in memory, but I'd like to know the reason why this is happening so I can avoid it in the future.

Is anyone able to explain to me what is happening?

Best Regards,
Kasper


Replies

 
Nicolai Pedersen
Reply

Hi Kasper

The "IndexOutOfRangeException" exception could indicate that you are using a fieldname that does not exist in the index for your sort. Or it is not indexed? Did you add a field and did no rebuild?

NP

 
Kasper Laursen
Reply

I spent quite some time going back and forth and ensure that the field i am referencing actually exists. It is in the index and has a value on my results when i remove the sort.

 

You must be logged in to post in the forum