mirror of https://github.com/apache/lucene.git
LUCENE-5401: Field.StringTokenStream#end() calls super.end() now.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1558876 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7b34ac5c61
commit
26070d936d
|
@ -169,6 +169,10 @@ Bug fixes
|
|||
when the parent query incorrectly returns child documents, and throw
|
||||
a clear exception saying so. (Dr. Oleg Savrasov via Mike McCandless)
|
||||
|
||||
* LUCENE-5401: Field.StringTokenStream#end() calls super.end() now,
|
||||
preventing wrong term positions for fields that use
|
||||
StringTokenStream. (Michael Busch)
|
||||
|
||||
API Changes
|
||||
|
||||
* LUCENE-5339: The facet module was simplified/reworked to make the
|
||||
|
|
|
@ -588,7 +588,8 @@ public class Field implements IndexableField, StorableField {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
public void end() throws IOException {
|
||||
super.end();
|
||||
final int finalOffset = value.length();
|
||||
offsetAttribute.setOffset(finalOffset, finalOffset);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.lucene.index.StorableField;
|
|||
import org.apache.lucene.index.StoredDocument;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.PhraseQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.ScoreDoc;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
|
@ -101,28 +102,31 @@ public class TestDocument extends LuceneTestCase {
|
|||
*/
|
||||
public void testRemoveForNewDocument() throws Exception {
|
||||
Document doc = makeDocumentWithFields();
|
||||
assertEquals(8, doc.getFields().size());
|
||||
assertEquals(10, doc.getFields().size());
|
||||
doc.removeFields("keyword");
|
||||
assertEquals(6, doc.getFields().size());
|
||||
assertEquals(8, doc.getFields().size());
|
||||
doc.removeFields("doesnotexists"); // removing non-existing fields is
|
||||
// siltenlty ignored
|
||||
doc.removeFields("keyword"); // removing a field more than once
|
||||
assertEquals(8, doc.getFields().size());
|
||||
doc.removeField("text");
|
||||
assertEquals(7, doc.getFields().size());
|
||||
doc.removeField("text");
|
||||
assertEquals(6, doc.getFields().size());
|
||||
doc.removeField("text");
|
||||
assertEquals(5, doc.getFields().size());
|
||||
doc.removeField("text");
|
||||
assertEquals(4, doc.getFields().size());
|
||||
doc.removeField("text");
|
||||
assertEquals(4, doc.getFields().size());
|
||||
assertEquals(6, doc.getFields().size());
|
||||
doc.removeField("doesnotexists"); // removing non-existing fields is
|
||||
// siltenlty ignored
|
||||
assertEquals(4, doc.getFields().size());
|
||||
assertEquals(6, doc.getFields().size());
|
||||
doc.removeFields("unindexed");
|
||||
assertEquals(2, doc.getFields().size());
|
||||
assertEquals(4, doc.getFields().size());
|
||||
doc.removeFields("unstored");
|
||||
assertEquals(0, doc.getFields().size());
|
||||
assertEquals(2, doc.getFields().size());
|
||||
doc.removeFields("doesnotexists"); // removing non-existing fields is
|
||||
// siltenlty ignored
|
||||
assertEquals(2, doc.getFields().size());
|
||||
|
||||
doc.removeFields("indexed_not_tokenized");
|
||||
assertEquals(0, doc.getFields().size());
|
||||
}
|
||||
|
||||
|
@ -151,14 +155,14 @@ public class TestDocument extends LuceneTestCase {
|
|||
|
||||
public void testClearDocument() {
|
||||
Document doc = makeDocumentWithFields();
|
||||
assertEquals(8, doc.getFields().size());
|
||||
assertEquals(10, doc.getFields().size());
|
||||
doc.clear();
|
||||
assertEquals(0, doc.getFields().size());
|
||||
}
|
||||
|
||||
public void testGetFieldsImmutable() {
|
||||
Document doc = makeDocumentWithFields();
|
||||
assertEquals(8, doc.getFields().size());
|
||||
assertEquals(10, doc.getFields().size());
|
||||
List<Field> fields = doc.getFields();
|
||||
try {
|
||||
fields.add( new StringField("name", "value", Field.Store.NO) );
|
||||
|
@ -226,10 +230,33 @@ public class TestDocument extends LuceneTestCase {
|
|||
doc.getValues("nope"));
|
||||
}
|
||||
|
||||
public void testPositionIncrementMultiFields() throws Exception {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
|
||||
writer.addDocument(makeDocumentWithFields());
|
||||
IndexReader reader = writer.getReader();
|
||||
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
PhraseQuery query = new PhraseQuery();
|
||||
query.add(new Term("indexed_not_tokenized", "test1"));
|
||||
query.add(new Term("indexed_not_tokenized", "test2"));
|
||||
|
||||
ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs;
|
||||
assertEquals(1, hits.length);
|
||||
|
||||
doAssert(searcher.doc(hits[0].doc));
|
||||
writer.close();
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
||||
private Document makeDocumentWithFields() {
|
||||
Document doc = new Document();
|
||||
FieldType stored = new FieldType();
|
||||
stored.setStored(true);
|
||||
FieldType indexedNotTokenized = new FieldType();
|
||||
indexedNotTokenized.setIndexed(true);
|
||||
indexedNotTokenized.setTokenized(false);
|
||||
doc.add(new StringField("keyword", "test1", Field.Store.YES));
|
||||
doc.add(new StringField("keyword", "test2", Field.Store.YES));
|
||||
doc.add(new TextField("text", "test1", Field.Store.YES));
|
||||
|
@ -240,6 +267,8 @@ public class TestDocument extends LuceneTestCase {
|
|||
.add(new TextField("unstored", "test1", Field.Store.NO));
|
||||
doc
|
||||
.add(new TextField("unstored", "test2", Field.Store.NO));
|
||||
doc.add(new Field("indexed_not_tokenized", "test1", indexedNotTokenized));
|
||||
doc.add(new Field("indexed_not_tokenized", "test2", indexedNotTokenized));
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue