apache / apache/lucene

cannot re-use Field in 4.7.2 [LUCENE-5923]

Open
#6,985 1 comment 0 reactions 0 assignees View on GitHub
legacy-jira-priority:Major type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

I get an exception "first position increment must be > 0 (got 0) for field ..." when I try to re-use a Field as an entry in a Document. Snippet below.

This works ok on lucene 4.9, but I have to go back to 4.7 for Java 6 compatibility.

Workaround is to not re-use the same object in each Document.

(this is Scala)

private val TypeField = new StringField("TYPE", clazz.getSimpleName, Store.YES)

final def toDocument(t: T): Document = {
val doc = new Document
// Lucene 4.7.2 bug: re-using the common object gives
// "first position increment must be > 0 (got 0) for field 'TYPE'"
//doc.add(TypeField)
doc.add(new StringField("TYPE", clazz.getSimpleName, Store.YES))
doc.add(new StringField("ID", id(t), Store.NO))
doc
}

---
Migrated from [LUCENE-5923](https://issues.apache.org/jira/browse/LUCENE-5923) by Sam Halliday

Contributor guide

Open the contributing guide

Research direction

Start with the supplied toDocument reproduction and compare Field reuse behavior between Lucene 4.7.2 and 4.9. Trace the first-position-increment exception from the StringField entry point, then add a regression test demonstrating reuse across Documents and verify the failure is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, scala
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.