Hello all

We are migrating our apps from 2.4.1 to 2.9.3, removing deprecated calls so to fast switch to 3.0.2 asap

At startup, our apps look for the min and max value of some configured fields, to let the user know the range of documents he/she is looking at and to filter them

One of these apps has a field whose min value is stored/indexed while all other values are just indexed

When looking for the min/max, StringIndexCache complains

Attached you find the test case we've used to isolate the problem.

I'm not sure whether is we that are using lucene the wrong way (in which case please give some advice) or it is a bug

Looking forward for your feedback before opening a ticket on jira

Best regards

Federico Fissore
package org.apache.lucene.search;

import static org.junit.Assert.*;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
import org.apache.lucene.search.FieldCache.StringIndex;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import org.junit.Before;
import org.junit.Test;

public class StringIndexCacheTest {

	private IndexReader reader;

	@Before
	public void setup() throws Exception {
		RAMDirectory dir = new RAMDirectory();
		IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_24), MaxFieldLength.UNLIMITED);

		Document doc = new Document();
		doc.add(new Field("date_doc", "20100101", Field.Store.YES, Field.Index.NOT_ANALYZED));
		doc.add(new Field("date_doc", "20100102", Field.Store.NO, Field.Index.NOT_ANALYZED));

		writer.addDocument(doc);
		writer.commit();
		writer.close();

		reader = IndexReader.open(dir, true);
	}

	@Test
	public void shouldReturnArrayOfSize3() throws Exception {
		StringIndex stringIndex = FieldCache.DEFAULT.getStringIndex(reader, "date_doc");
		assertEquals(3, stringIndex.lookup.length);
	}

	@Test
	public void shouldSortByDateDoc() throws Exception {
		Searcher searcher = new IndexSearcher(reader);
		TopFieldDocs topDocs = searcher.search(new MatchAllDocsQuery(), (Filter) null, 1, new Sort(new SortField("date_doc", SortField.STRING, false)));
		assertEquals(1, topDocs.scoreDocs.length);
		assertEquals("20100101", reader.document(topDocs.scoreDocs[0].doc).getField("date_doc").stringValue());
	}

}

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to