use of org.apache.lucene.analysis.standard.StandardAnalyzer in project elasticsearch by elastic.
the class SamplerAggregatorTests method testSampler.
/**
* Uses the sampler aggregation to find the minimum value of a field out of the top 3 scoring documents in a search.
*/
public void testSampler() throws IOException {
TextFieldType textFieldType = new TextFieldType();
textFieldType.setIndexAnalyzer(new NamedAnalyzer("foo", AnalyzerScope.GLOBAL, new StandardAnalyzer()));
MappedFieldType numericFieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG);
numericFieldType.setName("int");
IndexWriterConfig indexWriterConfig = newIndexWriterConfig();
indexWriterConfig.setMaxBufferedDocs(100);
// flush on open to have a single segment with predictable docIds
indexWriterConfig.setRAMBufferSizeMB(100);
try (Directory dir = newDirectory();
IndexWriter w = new IndexWriter(dir, indexWriterConfig)) {
for (long value : new long[] { 7, 3, -10, -6, 5, 50 }) {
Document doc = new Document();
StringBuilder text = new StringBuilder();
for (int i = 0; i < value; i++) {
text.append("good ");
}
doc.add(new Field("text", text.toString(), textFieldType));
doc.add(new SortedNumericDocValuesField("int", value));
w.addDocument(doc);
}
SamplerAggregationBuilder aggBuilder = new SamplerAggregationBuilder("sampler").shardSize(3).subAggregation(new MinAggregationBuilder("min").field("int"));
try (IndexReader reader = DirectoryReader.open(w)) {
assertEquals("test expects a single segment", 1, reader.leaves().size());
IndexSearcher searcher = new IndexSearcher(reader);
Sampler sampler = searchAndReduce(searcher, new TermQuery(new Term("text", "good")), aggBuilder, textFieldType, numericFieldType);
Min min = sampler.getAggregations().get("min");
assertEquals(5.0, min.getValue(), 0);
}
}
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project elasticsearch by elastic.
the class FunctionScoreTests method initSearcher.
@Before
public void initSearcher() throws IOException {
dir = newDirectory();
w = new IndexWriter(dir, newIndexWriterConfig(new StandardAnalyzer()));
Document d = new Document();
d.add(new TextField(FIELD, TEXT, Field.Store.YES));
d.add(new TextField("_uid", "1", Field.Store.YES));
w.addDocument(d);
w.commit();
reader = DirectoryReader.open(w);
searcher = newSearcher(reader);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project elasticsearch by elastic.
the class CustomUnifiedHighlighterTests method testCommonTermsQuery.
public void testCommonTermsQuery() throws Exception {
final String[] inputs = { "The quick brown fox." };
final String[] outputs = { "The <b>quick</b> <b>brown</b> <b>fox</b>." };
CommonTermsQuery query = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 128);
query.add(new Term("text", "quick"));
query.add(new Term("text", "brown"));
query.add(new Term("text", "fox"));
assertHighlightOneDoc("text", inputs, new StandardAnalyzer(), query, Locale.ROOT, BreakIterator.getSentenceInstance(Locale.ROOT), 0, outputs);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project elasticsearch by elastic.
the class CustomUnifiedHighlighterTests method testNoMatchSize.
public void testNoMatchSize() throws Exception {
final String[] inputs = { "This is a test. Just a test highlighting from unified. Feel free to ignore." };
Query query = new TermQuery(new Term("body", "highlighting"));
assertHighlightOneDoc("text", inputs, new StandardAnalyzer(), query, Locale.ROOT, BreakIterator.getSentenceInstance(Locale.ROOT), 100, inputs);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project elasticsearch by elastic.
the class CustomUnifiedHighlighterTests method testAllTermQuery.
public void testAllTermQuery() throws Exception {
final String[] inputs = { "The quick brown fox." };
final String[] outputs = { "The quick brown <b>fox</b>." };
AllTermQuery query = new AllTermQuery(new Term("text", "fox"));
assertHighlightOneDoc("text", inputs, new StandardAnalyzer(), query, Locale.ROOT, BreakIterator.getSentenceInstance(Locale.ROOT), 0, outputs);
}
Aggregations