use of org.apache.lucene.document.TextField in project OpenGrok by OpenGrok.
the class UuencodeAnalyzer method analyze.
@Override
public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
//this is to explicitely use appropriate analyzers tokenstream to workaround #1376 symbols search works like full text search
TextField full = new TextField(QueryBuilder.FULL, SymbolTokenizer);
this.SymbolTokenizer.setReader(getReader(src.getStream()));
doc.add(full);
if (xrefOut != null) {
try (Reader in = getReader(src.getStream())) {
writeXref(in, xrefOut);
}
}
}
use of org.apache.lucene.document.TextField in project orientdb by orientechnologies.
the class LuceneVsLuceneTest method testLuceneVsLucene.
@Test
public void testLuceneVsLucene() throws IOException, ParseException {
for (ODocument oDocument : db.browseClass("Song")) {
String title = oDocument.field("title");
if (title != null) {
Document d = new Document();
d.add(new TextField("title", title, Field.Store.YES));
d.add(new TextField("Song.title", title, Field.Store.YES));
indexWriter.addDocument(d);
}
}
indexWriter.commit();
indexWriter.close();
IndexReader reader = DirectoryReader.open(getDirectory());
assertThat(reader.numDocs()).isEqualTo(Long.valueOf(db.countClass("Song")).intValue());
IndexSearcher searcher = new IndexSearcher(reader);
Query query = new MultiFieldQueryParser(new String[] { "title" }, analyzer).parse("down the");
final TopDocs docs = searcher.search(query, Integer.MAX_VALUE);
ScoreDoc[] hits = docs.scoreDocs;
List<ODocument> oDocs = db.query(new OSQLSynchQuery<ODocument>("select *,$score from Song where title LUCENE \"down the\""));
Assert.assertEquals(oDocs.size(), hits.length);
int i = 0;
for (ScoreDoc hit : hits) {
Assert.assertEquals(oDocs.get(i).field("$score"), hit.score);
i++;
}
reader.close();
}
use of org.apache.lucene.document.TextField in project querydsl by querydsl.
the class LuceneQueryTest method createDocument.
private Document createDocument(final String docTitle, final String docAuthor, final String docText, final int docYear, final double docGross) {
Document doc = new Document();
// Reusing field for performance
if (titleField == null) {
titleField = new TextField("title", docTitle, Store.YES);
doc.add(titleField);
titleSortedField = new SortedDocValuesField("title", new BytesRef(docTitle));
doc.add(titleSortedField);
} else {
titleField.setStringValue(docTitle);
titleSortedField.setBytesValue(new BytesRef(docTitle));
doc.add(titleField);
doc.add(titleSortedField);
}
if (authorField == null) {
authorField = new TextField("author", docAuthor, Store.YES);
doc.add(authorField);
authorSortedField = new SortedDocValuesField("author", new BytesRef(docAuthor));
doc.add(authorSortedField);
} else {
authorField.setStringValue(docAuthor);
authorSortedField.setBytesValue(new BytesRef(docAuthor));
doc.add(authorField);
doc.add(authorSortedField);
}
if (textField == null) {
textField = new TextField("text", docText, Store.YES);
doc.add(textField);
textSortedField = new SortedDocValuesField("text", new BytesRef(docText));
doc.add(textSortedField);
} else {
textField.setStringValue(docText);
textSortedField.setBytesValue(new BytesRef(docText));
doc.add(textField);
doc.add(textSortedField);
}
if (yearField == null) {
yearField = new IntField("year", docYear, Store.YES);
doc.add(yearField);
yearSortedField = new NumericDocValuesField("year", docYear);
doc.add(yearSortedField);
} else {
yearField.setIntValue(docYear);
yearSortedField.setLongValue(docYear);
doc.add(yearField);
doc.add(yearSortedField);
}
if (grossField == null) {
grossField = new DoubleField("gross", docGross, Store.YES);
doc.add(grossField);
grossSortedField = new DoubleDocValuesField("gross", docGross);
doc.add(grossSortedField);
} else {
grossField.setDoubleValue(docGross);
grossSortedField.setDoubleValue(docGross);
doc.add(grossField);
doc.add(grossSortedField);
}
return doc;
}
use of org.apache.lucene.document.TextField in project languagetool by languagetool-org.
the class SimilarWordFinder method createIndex.
private void createIndex(List<String> words, File indexDir) throws IOException {
FSDirectory dir = FSDirectory.open(indexDir.toPath());
IndexWriterConfig indexWriterConfig = new IndexWriterConfig(new StandardAnalyzer());
System.out.println("Creating index...");
int docs = 0;
try (IndexWriter writer = new IndexWriter(dir, indexWriterConfig)) {
for (String word : words) {
Document doc = new Document();
doc.add(new TextField("word", word, Field.Store.YES));
writer.addDocument(doc);
docs++;
}
}
System.out.println("Index created: " + docs + " docs");
}
use of org.apache.lucene.document.TextField in project languagetool by languagetool-org.
the class LuceneSimpleIndexCreator method main.
public static void main(String[] args) throws IOException {
IndexWriterConfig conf = new IndexWriterConfig(new KeywordAnalyzer());
try (IndexWriter iw1 = new IndexWriter(FSDirectory.open(new File("/tmp/1grams").toPath()), conf)) {
addDoc(iw1, "the", 55);
addDoc(iw1, "nice", 10);
addDoc(iw1, "building", 1);
Document document = new Document();
document.add(new TextField("totalTokenCount", String.valueOf(3), Field.Store.YES));
iw1.addDocument(document);
}
IndexWriterConfig conf2 = new IndexWriterConfig(new KeywordAnalyzer());
try (IndexWriter iw2 = new IndexWriter(FSDirectory.open(new File("/tmp/2grams").toPath()), conf2)) {
addDoc(iw2, "the nice", 3);
addDoc(iw2, "nice building", 2);
}
IndexWriterConfig conf3 = new IndexWriterConfig(new KeywordAnalyzer());
try (IndexWriter iw3 = new IndexWriter(FSDirectory.open(new File("/tmp/3grams").toPath()), conf3)) {
addDoc(iw3, "the nice building", 1);
}
}
Aggregations