当前位置: 首页>>代码示例>>Java>>正文


Java StandardQueryParser.parse方法代码示例

本文整理汇总了Java中org.apache.lucene.queryparser.flexible.standard.StandardQueryParser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java StandardQueryParser.parse方法的具体用法?Java StandardQueryParser.parse怎么用?Java StandardQueryParser.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.queryparser.flexible.standard.StandardQueryParser的用法示例。


在下文中一共展示了StandardQueryParser.parse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: qs

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
/**
 * Tries to parse a query string in order to check if it is valid.
 * @param query a Lucene query string
 * @return the query if valid, or '*' if invalid
 */
static String qs(String query) {
	if (StringUtils.isBlank(query) || "*".equals(query.trim())) {
		return "*";
	}
	query = query.trim();
	if (query.length() > 1 && query.startsWith("*")) {
		query = query.substring(1);
	}
	try {
		StandardQueryParser parser = new StandardQueryParser();
		parser.setAllowLeadingWildcard(false);
		parser.parse(query, "");
	} catch (Exception ex) {
		logger.warn("Failed to parse query string '{}'.", query);
		query = "*";
	}
	return query.trim();
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:24,代码来源:ElasticSearchUtils.java

示例2: parseQuery

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:18,代码来源:FullTextIndexInfosImpl.java

示例3: testRangeParsing

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
@Test
public void testRangeParsing() throws Exception {
    NumericConfig numericConfig = new NumericConfig(8, NumberFormat.getNumberInstance(Locale.ENGLISH), FieldType.NumericType.FLOAT);
    HashMap<String, NumericConfig> numericConfigMap = new HashMap<String, NumericConfig>();
    numericConfigMap.put("reflec_7", numericConfig);
    numericConfigMap.put("reflec_8", numericConfig);
    numericConfigMap.put("reflec_9", numericConfig);
    StandardQueryParser parser = new StandardQueryParser();
    parser.setNumericConfigMap(numericConfigMap);

    Query query1 = parser.parse("reflec_8:[0.0 TO 1.0]", "x");
    assertEquals(NumericRangeQuery.class, query1.getClass());

    Query query2 = parser.parse("reflec_8:[0.0 TO 1.0] AND reflec_9:[0.2 TO 0.6]^3.1", "x");
    assertEquals(BooleanQuery.class, query2.getClass());
    BooleanClause clause1 = ((BooleanQuery) query2).getClauses()[0];
    BooleanClause clause2 = ((BooleanQuery) query2).getClauses()[1];
    NumericRangeQuery<Float> nrq1 = NumericRangeQuery.newFloatRange("reflec_8", 8, 0.0F, 1.0F, true, true);
    NumericRangeQuery<Float> nrq2 = NumericRangeQuery.newFloatRange("reflec_9", 8, 0.2F, 0.6F, true, true);
    nrq2.setBoost(3.1F);
    assertEquals(nrq1, clause1.getQuery());
    assertEquals(BooleanClause.Occur.MUST, clause1.getOccur());
    assertEquals(nrq2, clause2.getQuery());
    assertEquals(BooleanClause.Occur.MUST, clause2.getOccur());
}
 
开发者ID:bcdev,项目名称:esa-pfa,代码行数:26,代码来源:StandardQueryParserTest.java

示例4: ExpertRevisionSearchCommand

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
private ExpertRevisionSearchCommand(DirectoryManager.DirectoryPath path, String qry, Configuration configuration)
        throws QueryNodeException {
    super(path, ResultList.ResultType.REVISION);
    setLanguage(extractLanguage(qry));
    Map<String, NumericConfig> nums = new HashMap<>();

    /*StandardQueryParser parser = new StandardQueryParser(getAnalyzer());*/
    StandardQueryParser parser = new StandardQueryParser();
    parser.setAllowLeadingWildcard(true);
    parser.setAnalyzer(getAnalyzer());
    if(!StringUtils.hasText(qry)) {
        throw new ParseException(new MessageImpl("EMPTY_QUERY"));
    }
    query = parser.parse(qry, "general");

    // No matter if we have configuraion or not we'll parse the query twice. This second parsing will add analyzers for known keys like key.id
    // as well as fields found from configuration if configuration is provided
    addAnalyzersAndConfigs(query, nums, configuration);
    parser.setAnalyzer(getAnalyzer());
    parser.setNumericConfigMap(nums);
    query = parser.parse(qry, "general");
}
 
开发者ID:Tietoarkisto,项目名称:metka,代码行数:23,代码来源:ExpertRevisionSearchCommand.java

示例5: qsParsed

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
static Query qsParsed(String query) {
	if (StringUtils.isBlank(query) || "*".equals(query.trim())) {
		return null;
	}
	try {
		StandardQueryParser parser = new StandardQueryParser();
		parser.setAllowLeadingWildcard(false);
		return parser.parse(query, "");
	} catch (Exception ex) {
		logger.warn("Failed to parse query string '{}'.", query);
	}
	return null;
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:14,代码来源:ElasticSearchUtils.java

示例6: testSimple

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
public void testSimple() throws Exception {
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
    StandardQueryParser parser = new StandardQueryParser(analyzer);
    Query q = null;
    try {
        q = parser.parse("(agile OR extreme) AND methodology", "subject");
    }
    catch (QueryNodeException exc) {
        // TODO: handle exc
    }
    LOGGER.info("parsed " + q);
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:13,代码来源:FlexibleQueryParserTest.java

示例7: testPhraseQuery

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
public void testPhraseQuery() throws Exception {
    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
    StandardQueryParser parser = new CustomFlexibleQueryParser(analyzer);

    Query query = parser.parse("singleTerm", "subject");
    assertTrue("TermQuery", query instanceof TermQuery);

    query = parser.parse("\"a phrase test\"", "subject");
    LOGGER.info("got query=" + query);
    assertTrue("SpanNearQuery", query instanceof SpanNearQuery);
}
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:12,代码来源:FlexibleQueryParserTest.java

示例8: testTermQuery

import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser; //导入方法依赖的package包/类
@Test
public void testTermQuery() throws CorruptIndexException, IOException,
    QueryNodeException {
  
  Document doc = new Document();
  doc.add(new Field("content", "I work for the united nations",
      TextField.TYPE_STORED));
  
  writer.addDocument(doc);
  
  searcher = new IndexSearcher(DirectoryReader.open(writer, false));
  
  StandardQueryParser parser = new StandardQueryParser(new SimpleAnalyzer(
      matchVersion));
  
  Query query = parser.parse("united nations", "content");
  
  Assert.assertEquals(1, TestUtil.hitCount(searcher, query));
  
}
 
开发者ID:KepaJRodriguez,项目名称:lucene-skos-ehri,代码行数:21,代码来源:SKOSLabelFilterTest.java


注:本文中的org.apache.lucene.queryparser.flexible.standard.StandardQueryParser.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。