use of org.apache.lucene.analysis.SimpleAnalyzer in project collect by openforis.
the class RecordIndexManager method createQuery.
protected Query createQuery(SearchType searchType, String indexFieldKey, String searchText) throws ParseException {
String escapedSearchText = QueryParser.escape(searchText.trim().toLowerCase(Locale.ENGLISH));
String queryText = escapedSearchText;
if (StringUtils.isNotBlank(queryText)) {
switch(searchType) {
case STARTS_WITH:
queryText = escapedSearchText + "*";
break;
case CONTAINS:
// queryText = "*" + escapedSearchText + "*"; TODO support CONTAINS query
queryText = escapedSearchText + "*";
break;
default:
queryText = escapedSearchText;
}
}
SimpleAnalyzer analyzer = new SimpleAnalyzer(LUCENE_VERSION);
QueryParser queryParser = new QueryParser(LUCENE_VERSION, indexFieldKey, analyzer);
queryParser.setDefaultOperator(Operator.AND);
Query query = queryParser.parse(queryText);
return query;
}
use of org.apache.lucene.analysis.SimpleAnalyzer in project collect by openforis.
the class RecordIndexManager method createIndexWriter.
protected IndexWriter createIndexWriter() throws RecordIndexException {
try {
SimpleAnalyzer analyzer = new SimpleAnalyzer(LUCENE_VERSION);
IndexWriterConfig conf = new IndexWriterConfig(LUCENE_VERSION, analyzer);
conf.setOpenMode(OpenMode.CREATE_OR_APPEND);
IndexWriter indexWriter = new IndexWriter(indexDirectory, conf);
return indexWriter;
} catch (IOException e) {
throw new RecordIndexException(e.getMessage(), e);
}
}
Aggregations