org.apache.lucene.queryparser.flexible.standard.StandardQueryParser Java Examples
The following examples show how to use
org.apache.lucene.queryparser.flexible.standard.StandardQueryParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SolrSuggester.java From lucene-solr with Apache License 2.0 | 6 votes |
private BooleanQuery parseContextFilterQuery(String contextFilter) { if(contextFilter == null){ return null; } Query query = null; try { query = new StandardQueryParser(contextFilterQueryAnalyzer).parse(contextFilter, CONTEXTS_FIELD_NAME); if (query instanceof BooleanQuery) { return (BooleanQuery) query; } return new BooleanQuery.Builder().add(query, BooleanClause.Occur.MUST).build(); } catch (QueryNodeException e) { throw new IllegalArgumentException("Failed to parse query: " + query); } }
Example #2
Source File: FullTextIndexInfosImpl.java From sql-layer with GNU Affero General Public License v3.0 | 6 votes |
@Override public Query parseQuery(QueryContext context, IndexName name, String defaultField, String query) { FullTextIndexInfo index = getIndex(context.getSession(), name, null); if (defaultField == null) { defaultField = index.getDefaultFieldName(); } StandardQueryParser parser = index.getParser(); try { synchronized (parser) { return parser.parse(query, defaultField); } } catch (QueryNodeException ex) { throw new FullTextQueryParseException(ex); } }
Example #3
Source File: LuceneStoreImpl.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void eviction() throws Exception { StandardQueryParser queryParser = new StandardQueryParser(); queryParser.setAllowLeadingWildcard(true); queryParser.setPointsConfigMap(points); Query query = queryParser.parse("alertUUID:* AND NOT alertRule:*", ""); indexWriter.deleteDocuments(query); indexWriter.commit(); }
Example #4
Source File: LuceneStoreImpl.java From karaf-decanter with Apache License 2.0 | 5 votes |
@Override public void delete(String queryString) throws Exception { StandardQueryParser queryParser = new StandardQueryParser(); queryParser.setAllowLeadingWildcard(true); queryParser.setPointsConfigMap(points); Query query = queryParser.parse(queryString, ""); indexWriter.deleteDocuments(query); indexWriter.commit(); }
Example #5
Source File: SearchImpl.java From lucene-solr with Apache License 2.0 | 4 votes |
private Query parseByStandardParser(String expression, String defField, Analyzer analyzer, QueryParserConfig config) { StandardQueryParser parser = new StandardQueryParser(analyzer); switch (config.getDefaultOperator()) { case OR: parser.setDefaultOperator(StandardQueryConfigHandler.Operator.OR); break; case AND: parser.setDefaultOperator(StandardQueryConfigHandler.Operator.AND); break; } parser.setEnablePositionIncrements(config.isEnablePositionIncrements()); parser.setAllowLeadingWildcard(config.isAllowLeadingWildcard()); parser.setDateResolution(config.getDateResolution()); parser.setFuzzyMinSim(config.getFuzzyMinSim()); parser.setFuzzyPrefixLength(config.getFuzzyPrefixLength()); parser.setLocale(config.getLocale()); parser.setTimeZone(config.getTimeZone()); parser.setPhraseSlop(config.getPhraseSlop()); if (config.getTypeMap() != null) { Map<String, PointsConfig> pointsConfigMap = new HashMap<>(); for (Map.Entry<String, Class<? extends Number>> entry : config.getTypeMap().entrySet()) { String field = entry.getKey(); Class<? extends Number> type = entry.getValue(); PointsConfig pc; if (type == Integer.class || type == Long.class) { pc = new PointsConfig(NumberFormat.getIntegerInstance(Locale.ROOT), type); } else if (type == Float.class || type == Double.class) { pc = new PointsConfig(NumberFormat.getNumberInstance(Locale.ROOT), type); } else { log.warn(String.format(Locale.ENGLISH, "Ignored invalid number type: %s.", type.getName())); continue; } pointsConfigMap.put(field, pc); } parser.setPointsConfigMap(pointsConfigMap); } try { return parser.parse(expression, defField); } catch (QueryNodeException e) { throw new LukeException(String.format(Locale.ENGLISH, "Failed to parse query expression: %s", expression), e); } }
Example #6
Source File: FullTextIndexShared.java From sql-layer with GNU Affero General Public License v3.0 | 4 votes |
public StandardQueryParser getParser() { return parser; }
Example #7
Source File: FullTextIndexShared.java From sql-layer with GNU Affero General Public License v3.0 | 4 votes |
public void setParser(StandardQueryParser parser) { this.parser = parser; }