use of org.apache.lucene.index.IndexWriterConfig in project lucene-solr by apache.
the class AbstractTestCase method make1dmfIndexNA.
// make 1 doc with multi valued & not analyzed field
protected void make1dmfIndexNA(String... values) throws Exception {
IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(analyzerK).setOpenMode(OpenMode.CREATE));
Document doc = new Document();
FieldType customType = new FieldType(TextField.TYPE_STORED);
customType.setStoreTermVectors(true);
customType.setStoreTermVectorOffsets(true);
customType.setStoreTermVectorPositions(true);
for (String value : values) {
doc.add(new Field(F, value, customType));
//doc.add( new Field( F, value, Store.YES, Index.NOT_ANALYZED, TermVector.WITH_POSITIONS_OFFSETS ) );
}
writer.addDocument(doc);
writer.close();
if (reader != null)
reader.close();
reader = DirectoryReader.open(dir);
}
use of org.apache.lucene.index.IndexWriterConfig in project lucene-solr by apache.
the class TestUnifiedHighlighterRanking method testCustomB.
/**
* sets b=0 to disable passage length normalization
*/
public void testCustomB() throws Exception {
Directory dir = newDirectory();
indexAnalyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
IndexWriterConfig iwc = newIndexWriterConfig(indexAnalyzer);
iwc.setMergePolicy(newLogMergePolicy());
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
Field body = new Field("body", "", fieldType);
Document doc = new Document();
doc.add(body);
body.setStringValue("This is a test. This test is a better test but the sentence is excruiatingly long, " + "you have no idea how painful it was for me to type this long sentence into my IDE.");
iw.addDocument(doc);
IndexReader ir = iw.getReader();
iw.close();
IndexSearcher searcher = newSearcher(ir);
UnifiedHighlighter highlighter = new UnifiedHighlighter(searcher, indexAnalyzer) {
@Override
protected PassageScorer getScorer(String field) {
return new PassageScorer(1.2f, 0, 87);
}
};
Query query = new TermQuery(new Term("body", "test"));
TopDocs topDocs = searcher.search(query, 10, Sort.INDEXORDER);
assertEquals(1, topDocs.totalHits);
String[] snippets = highlighter.highlight("body", query, topDocs, 1);
assertEquals(1, snippets.length);
assertTrue(snippets[0].startsWith("This <b>test</b> is a better <b>test</b>"));
ir.close();
dir.close();
}
use of org.apache.lucene.index.IndexWriterConfig in project lucene-solr by apache.
the class TestValueSources method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
dir = newDirectory();
analyzer = new MockAnalyzer(random());
IndexWriterConfig iwConfig = newIndexWriterConfig(analyzer);
iwConfig.setMergePolicy(newLogMergePolicy());
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig);
for (String[] doc : documents) {
Document document = new Document();
document.add(new StringField("id", doc[0], Field.Store.NO));
document.add(new SortedDocValuesField("id", new BytesRef(doc[0])));
document.add(new NumericDocValuesField("double", Double.doubleToRawLongBits(Double.parseDouble(doc[1]))));
document.add(new NumericDocValuesField("float", Float.floatToRawIntBits(Float.parseFloat(doc[2]))));
document.add(new NumericDocValuesField("int", Integer.parseInt(doc[3])));
document.add(new NumericDocValuesField("long", Long.parseLong(doc[4])));
document.add(new StringField("string", doc[5], Field.Store.NO));
document.add(new SortedDocValuesField("string", new BytesRef(doc[5])));
document.add(new TextField("text", doc[6], Field.Store.NO));
document.add(new SortedNumericDocValuesField("floatMv", NumericUtils.floatToSortableInt(Float.parseFloat(doc[7]))));
document.add(new SortedNumericDocValuesField("floatMv", NumericUtils.floatToSortableInt(Float.parseFloat(doc[8]))));
document.add(new SortedNumericDocValuesField("floatMv", NumericUtils.floatToSortableInt(Float.parseFloat(doc[9]))));
document.add(new SortedNumericDocValuesField("doubleMv", NumericUtils.doubleToSortableLong(Double.parseDouble(doc[7]))));
document.add(new SortedNumericDocValuesField("doubleMv", NumericUtils.doubleToSortableLong(Double.parseDouble(doc[8]))));
document.add(new SortedNumericDocValuesField("doubleMv", NumericUtils.doubleToSortableLong(Double.parseDouble(doc[9]))));
document.add(new SortedNumericDocValuesField("intMv", Long.parseLong(doc[10])));
document.add(new SortedNumericDocValuesField("intMv", Long.parseLong(doc[11])));
document.add(new SortedNumericDocValuesField("intMv", Long.parseLong(doc[12])));
document.add(new SortedNumericDocValuesField("longMv", Long.parseLong(doc[10])));
document.add(new SortedNumericDocValuesField("longMv", Long.parseLong(doc[11])));
document.add(new SortedNumericDocValuesField("longMv", Long.parseLong(doc[12])));
iw.addDocument(document);
}
reader = iw.getReader();
searcher = newSearcher(reader);
iw.close();
}
use of org.apache.lucene.index.IndexWriterConfig in project lucene-solr by apache.
the class TestLongNormValueSource method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
dir = newDirectory();
analyzer = new MockAnalyzer(random());
IndexWriterConfig iwConfig = newIndexWriterConfig(analyzer);
iwConfig.setMergePolicy(newLogMergePolicy());
iwConfig.setSimilarity(sim);
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwConfig);
Document doc = new Document();
doc.add(new TextField("text", "this is a test test test", Field.Store.NO));
iw.addDocument(doc);
doc = new Document();
doc.add(new TextField("text", "second test", Field.Store.NO));
iw.addDocument(doc);
reader = iw.getReader();
searcher = newSearcher(reader);
iw.close();
}
use of org.apache.lucene.index.IndexWriterConfig in project lucene-solr by apache.
the class TestFunctionQuerySort method testOptimizedFieldSourceFunctionSorting.
public void testOptimizedFieldSourceFunctionSorting() throws IOException {
// index contents don't matter for this test.
Directory dir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(null);
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
IndexReader reader = writer.getReader();
writer.close();
IndexSearcher searcher = newSearcher(reader);
final boolean reverse = random().nextBoolean();
ValueSource vs;
SortField sf, vssf;
vs = new IntFieldSource("int_field");
sf = new SortField("int_field", Type.INT, reverse);
vssf = vs.getSortField(reverse);
assertEquals(sf, vssf);
sf = sf.rewrite(searcher);
vssf = vssf.rewrite(searcher);
assertEquals(sf, vssf);
vs = new FloatFieldSource("float_field");
sf = new SortField("float_field", Type.FLOAT, reverse);
vssf = vs.getSortField(reverse);
assertEquals(sf, vssf);
sf = sf.rewrite(searcher);
vssf = vssf.rewrite(searcher);
assertEquals(sf, vssf);
vs = new DoubleFieldSource("double_field");
sf = new SortField("double_field", Type.DOUBLE, reverse);
vssf = vs.getSortField(reverse);
assertEquals(sf, vssf);
sf = sf.rewrite(searcher);
vssf = vssf.rewrite(searcher);
assertEquals(sf, vssf);
vs = new LongFieldSource("long_field");
sf = new SortField("long_field", Type.LONG, reverse);
vssf = vs.getSortField(reverse);
assertEquals(sf, vssf);
sf = sf.rewrite(searcher);
vssf = vssf.rewrite(searcher);
assertEquals(sf, vssf);
reader.close();
dir.close();
}
Aggregations