0

this is not a duplicate of What is an "index out of range" exception, and how do I fix it? the index here definitely should NOT be out of range given the number of records that match the search criteria

Ok, so I have a query I'm running: two fields being searched and then sorted on three (other) fields. I'm only returning the top two results, so my endIndex is obviously 2.

Now this was working fine for months, but suddenly it threw an "index out of range" exception. The exception stopped if I removed the second and third sort fields. There are almost 700 records that match the two search fields.

The query is working fine again (unchanged)!

There was no write lock on the index when it happened.

The only variable I can think of is that all three of the sort fields are updated based on user input (number of comments, discussions and followers), but these would only ever increment.

So I really just want to get an understanding of why this happened and what I could do to prevent it happening again.

Here's the page where it's happening: www.ekcko.com Towards the bottom of the page there are three tabs. The query in question is the one that populates the "most discussed" tab Thanks in advance for any input

UPDATE: just an interesting note that I forgot to add: I dnowloaded the index and tested locally. Same result and no write.lock and definitely no writes happening. "index out of range" with three sort fields, but not with one sort field (same search)

UPDATE 2 I narrowed it down to the Comments field that's throwing the exception when it's included in the sort. Sorting by either or both of the other two fields yields the approx. 700 hits. I've interrogated the data in Luke and all records have either 5,4,3,2,1,0 or empty value in the comments field. The live index (which is currently not throwing the exception) has the same values for comments. just weird...


skip = 0;

take = 2;

qry = "+(ParentId:zzz) +(IsPrivate:false)" (zzz is substitute for NULL)

query code:

int endIndex = skip + take;
endIndex = endIndex > 0 ? endIndex : 1000;

StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
QueryParser parser = new QueryParser(Version.LUCENE_30, "", analyzer);
Query query = parseQuery(qry, parser);

Sort sort = null;
TopDocs results;
List<SortField> fields = new List<SortField>();
if (sortFields.IsNotNull())
{
    foreach (string field in sortFields)
    {
        fields.Add(new SortField(field, comparator, sortDesc));
    }
    sort = new Sort(fields.ToArray());
    results = searcher.Search(query, null, endIndex, sort);
}
else
    results = searcher.Search(query, null, endIndex);

ScoreDoc[] scoreDocs = results.ScoreDocs;
endIndex = results.TotalHits < endIndex ? results.TotalHits : endIndex;
List<Document> luceneDocuments = new List<Document>();

for (int i = skip; i < endIndex; i++)
{
    if (i > (skip + take) - 1)
        break;
    luceneDocuments.Add(searcher.Doc(scoreDocs[i].Doc));
}
analyzer.Close();
return luceneDocuments;
Community
  • 1
  • 1
Adam Hey
  • 1,512
  • 1
  • 20
  • 24

0 Answers0