use of org.apache.lucene.analysis.standard.StandardAnalyzer 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.analysis.standard.StandardAnalyzer in project jforum2 by rafaelsteil.
the class LuceneSearch method performSearch.
private SearchResult performSearch(SearchArgs args, LuceneResultCollector resultCollector, Filter filter) {
SearchResult result;
try {
StringBuffer criteria = new StringBuffer(256);
this.filterByForum(args, criteria);
this.filterByKeywords(args, criteria);
this.filterByDateRange(args, criteria);
Query query = new QueryParser("", new StandardAnalyzer()).parse(criteria.toString());
if (logger.isDebugEnabled()) {
logger.debug("Generated query: " + query);
}
Hits hits = filter == null ? this.search.search(query, this.getSorter(args)) : this.search.search(query, filter, this.getSorter(args));
if (hits != null && hits.length() > 0) {
result = new SearchResult(resultCollector.collect(args, hits, query), hits.length());
} else {
result = new SearchResult(new ArrayList(), 0);
}
} catch (Exception e) {
throw new SearchException(e);
}
return result;
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer in project elasticsearch-suggest-plugin by spinscale.
the class AbstractCacheLoaderSuggester method load.
@Override
public T load(ShardSuggestService.FieldType fieldType) throws Exception {
MapperService.SmartNameFieldMappers fieldMappers = mapperService.smartName(fieldType.field(), fieldType.types());
Analyzer queryAnalyzer = null;
Analyzer indexAnalyzer = null;
if (fieldMappers != null) {
FieldMapper fieldMapper = mapperService.smartName(fieldType.field(), fieldType.types()).mapper();
queryAnalyzer = fieldMapper.searchAnalyzer();
if (Strings.hasLength(fieldType.indexAnalyzer())) {
NamedAnalyzer namedAnalyzer = analysisService.analyzer(fieldType.queryAnalyzer());
if (namedAnalyzer == null) {
throw new ElasticsearchException("Query analyzer[" + fieldType.queryAnalyzer() + "] does not exist.");
}
queryAnalyzer = namedAnalyzer.analyzer();
}
indexAnalyzer = fieldMapper.searchAnalyzer();
if (Strings.hasLength(fieldType.indexAnalyzer())) {
NamedAnalyzer namedAnalyzer = analysisService.analyzer(fieldType.indexAnalyzer());
if (namedAnalyzer == null) {
throw new ElasticsearchException("Index analyzer[" + fieldType.indexAnalyzer() + "] does not exist.");
}
indexAnalyzer = namedAnalyzer.analyzer();
}
}
if (queryAnalyzer == null) {
queryAnalyzer = new StandardAnalyzer(org.elasticsearch.Version.CURRENT.luceneVersion);
}
if (indexAnalyzer == null) {
indexAnalyzer = new StandardAnalyzer(org.elasticsearch.Version.CURRENT.luceneVersion);
}
return getSuggester(indexAnalyzer, queryAnalyzer, fieldType);
}
use of org.apache.lucene.analysis.standard.StandardAnalyzer 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.analysis.standard.StandardAnalyzer in project titan by thinkaurelius.
the class LuceneExample method example1.
@Test
public void example1() throws Exception {
Directory dir = FSDirectory.open(path);
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_4_10_4, analyzer);
iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
IndexWriter writer = new IndexWriter(dir, iwc);
indexDocs(writer, "doc1", ImmutableMap.of("name", "The laborious work of John Doe as we know it", "city", "Blumenkamp", "location", Geoshape.point(51.687882, 6.612053), "time", 1000342034));
indexDocs(writer, "doc2", ImmutableMap.of("name", "Life as we know it or not", "city", "Essen", "location", Geoshape.point(51.787882, 6.712053), "time", 1000342034 - 500));
indexDocs(writer, "doc3", ImmutableMap.of("name", "Berlin - poor but sexy and a display of the extraordinary", "city", "Berlin", "location", Geoshape.circle(52.509535, 13.425293, 50), "time", 1000342034 + 2000));
writer.close();
//Search
IndexReader reader = DirectoryReader.open(FSDirectory.open(path));
IndexSearcher searcher = new IndexSearcher(reader);
analyzer = new StandardAnalyzer();
//Auesee
BooleanFilter filter = new BooleanFilter();
//filter.add(new TermsFilter(new Term("name_txt","know")), BooleanClause.Occur.MUST);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, Geoshape.circle(51.666167, 6.58905, 450).convert2Spatial4j());
//filter.add(getSpatialStrategy("location").makeFilter(args), BooleanClause.Occur.MUST);
filter.add(NumericRangeFilter.newLongRange("time", (long) 1000342034, (long) 1000342034, true, true), BooleanClause.Occur.MUST);
// filter.add(NumericRangeFilter.newLongRange("time",(long)1000342034-100,Long.MAX_VALUE,true,true), BooleanClause.Occur.MUST);
// filter.add(NumericRangeFilter.newLongRange("time",Long.MIN_VALUE,(long)1000342034+300,true,true), BooleanClause.Occur.MUST);
filter.add(new PrefixFilter(new Term("city_str", "B")), BooleanClause.Occur.MUST);
TopDocs docs = searcher.search(new MatchAllDocsQuery(), filter, MAX_RESULT);
if (docs.totalHits >= MAX_RESULT)
throw new RuntimeException("Max results exceeded: " + MAX_RESULT);
Set<String> result = getResults(searcher, docs);
System.out.println(result);
}
Aggregations