apache / apache/lucene

Sorting of search results can fail [LUCENE-2775]

Open
#3,849 0 comments 0 reactions 0 assignees View on GitHub
affects-version:3.0.1 legacy-jira-priority:Major module:core/search type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

When retrieving long values for sorting via the createValue method of the LongCache class in FieldCacheImpl.java, there are cases where there are terms for a given field that are not longs. These values have no documents associated with them so they can be safely ignored. The problem is that if the value could not be parsed into a long, as was my case, then an exception is thrown and the value 0 is returned for all documents. This causes the sort to fail.

In my case the offending value was "0-73080000". I do not know how that got into the index and as such, have no way of reproducing this bug.

The solution was to simply catch the exception and move on to the next term without bailing out of the sort.

---
Migrated from [LUCENE-2775](https://issues.apache.org/jira/browse/LUCENE-2775) by Kevin Hayen
Attachments: [sort.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-2775/sort.patch)

Contributor guide

Open the contributing guide

Research direction

Start in FieldCacheImpl.java at LongCache.createValue and inspect how terms are parsed during sorting. Review the attached sort.patch for the reported direction, then verify that a malformed term such as "0-73080000" no longer causes all-document sorting to fail while valid long terms still sort correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.