use of org.apache.lucene.index.IndexWriterConfig in project querydsl by querydsl.
the class LuceneSerializerNotTokenizedTest method before.
@Before
public void before() throws Exception {
serializer = new LuceneSerializer(false, false);
idx = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31, new StandardAnalyzer(Version.LUCENE_30)).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(idx, config);
writer.addDocument(createDocument(clooney));
writer.addDocument(createDocument(pitt));
Document document = new Document();
for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) {
document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED));
}
writer.addDocument(document);
writer.close();
IndexReader reader = IndexReader.open(idx);
searcher = new IndexSearcher(reader);
}
use of org.apache.lucene.index.IndexWriterConfig in project querydsl by querydsl.
the class LuceneSerializerNotTokenizedTest method before.
@Before
public void before() throws Exception {
serializer = new LuceneSerializer(false, false);
idx = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(idx, config);
writer.addDocument(createDocument(clooney));
writer.addDocument(createDocument(pitt));
Document document = new Document();
for (String movie : Arrays.asList("Interview with the Vampire", "Up in the Air")) {
document.add(new Field("movie", movie, Store.YES, Index.NOT_ANALYZED));
}
writer.addDocument(document);
writer.close();
IndexReader reader = DirectoryReader.open(idx);
searcher = new IndexSearcher(reader);
}
use of org.apache.lucene.index.IndexWriterConfig in project querydsl by querydsl.
the class LuceneSerializerTest method setUp.
@Before
public void setUp() throws Exception {
serializer = new LuceneSerializer(true, true);
entityPath = new PathBuilder<Object>(Object.class, "obj");
title = entityPath.getString("title");
author = entityPath.getString("author");
text = entityPath.getString("text");
publisher = entityPath.getString("publisher");
year = entityPath.getNumber("year", Integer.class);
rating = entityPath.getString("rating");
gross = entityPath.getNumber("gross", Double.class);
titles = entityPath.getCollection("title", String.class, StringPath.class);
longField = entityPath.getNumber("longField", Long.class);
shortField = entityPath.getNumber("shortField", Short.class);
byteField = entityPath.getNumber("byteField", Byte.class);
floatField = entityPath.getNumber("floatField", Float.class);
idx = new RAMDirectory();
config = new IndexWriterConfig(Version.LUCENE_42, new StandardAnalyzer(Version.LUCENE_42)).setOpenMode(IndexWriterConfig.OpenMode.CREATE);
writer = new IndexWriter(idx, config);
writer.addDocument(createDocument());
writer.close();
IndexReader reader = IndexReader.open(idx);
searcher = new IndexSearcher(reader);
}
use of org.apache.lucene.index.IndexWriterConfig in project elasticsearch by elastic.
the class AbstractTermVectorsTestCase method indexDocsWithLucene.
protected DirectoryReader indexDocsWithLucene(TestDoc[] testDocs) throws IOException {
Map<String, Analyzer> mapping = new HashMap<>();
for (TestFieldSetting field : testDocs[0].fieldSettings) {
if (field.storedPayloads) {
mapping.put(field.name, new Analyzer() {
@Override
protected TokenStreamComponents createComponents(String fieldName) {
Tokenizer tokenizer = new StandardTokenizer();
TokenFilter filter = new LowerCaseFilter(tokenizer);
filter = new TypeAsPayloadTokenFilter(filter);
return new TokenStreamComponents(tokenizer, filter);
}
});
}
}
PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(CharArraySet.EMPTY_SET), mapping);
Directory dir = new RAMDirectory();
IndexWriterConfig conf = new IndexWriterConfig(wrapper);
conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
IndexWriter writer = new IndexWriter(dir, conf);
for (TestDoc doc : testDocs) {
Document d = new Document();
d.add(new Field("id", doc.id, StringField.TYPE_STORED));
for (int i = 0; i < doc.fieldContent.length; i++) {
FieldType type = new FieldType(TextField.TYPE_STORED);
TestFieldSetting fieldSetting = doc.fieldSettings[i];
type.setStoreTermVectorOffsets(fieldSetting.storedOffset);
type.setStoreTermVectorPayloads(fieldSetting.storedPayloads);
type.setStoreTermVectorPositions(fieldSetting.storedPositions || fieldSetting.storedPayloads || fieldSetting.storedOffset);
type.setStoreTermVectors(true);
type.freeze();
d.add(new Field(fieldSetting.name, doc.fieldContent[i], type));
}
writer.updateDocument(new Term("id", doc.id), d);
writer.commit();
}
writer.close();
return DirectoryReader.open(dir);
}
use of org.apache.lucene.index.IndexWriterConfig in project elasticsearch by elastic.
the class TermVectorsUnitTests method writeEmptyTermVector.
private void writeEmptyTermVector(TermVectorsResponse outResponse) throws IOException {
Directory dir = newDirectory();
IndexWriterConfig conf = new IndexWriterConfig(new StandardAnalyzer());
conf.setOpenMode(OpenMode.CREATE);
IndexWriter writer = new IndexWriter(dir, conf);
FieldType type = new FieldType(TextField.TYPE_STORED);
type.setStoreTermVectorOffsets(true);
type.setStoreTermVectorPayloads(false);
type.setStoreTermVectorPositions(true);
type.setStoreTermVectors(true);
type.freeze();
Document d = new Document();
d.add(new Field("id", "abc", StringField.TYPE_STORED));
writer.updateDocument(new Term("id", "abc"), d);
writer.commit();
writer.close();
DirectoryReader dr = DirectoryReader.open(dir);
IndexSearcher s = new IndexSearcher(dr);
TopDocs search = s.search(new TermQuery(new Term("id", "abc")), 1);
ScoreDoc[] scoreDocs = search.scoreDocs;
int doc = scoreDocs[0].doc;
Fields fields = dr.getTermVectors(doc);
EnumSet<Flag> flags = EnumSet.of(Flag.Positions, Flag.Offsets);
outResponse.setFields(fields, null, flags, fields);
outResponse.setExists(true);
dr.close();
dir.close();
}
Aggregations