• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java QParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.solr.search.QParser的典型用法代码示例。如果您正苦于以下问题:Java QParser类的具体用法?Java QParser怎么用?Java QParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



QParser类属于org.apache.solr.search包,在下文中一共展示了QParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: test_singleTerm

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Test
public void test_singleTerm() throws SyntaxError {

    // arrange
    QParser parser = new SimilarityParser("first",new ModifiableSolrParams(),mockCorrectParams,req("first"));

    // act
    Query luceneQuery = parser.parse();

    // assert
    AugmentedTermQuery expected = new AugmentedTermQuery(
            AugmentedTermQuery.ModelMethod.Generalized, new Term("text", "first"),
            new TermWeightTuple[]{SimilarityApiMock.similarTerm("text")}
            );

    Assert.assertEquals(expected, luceneQuery);
}
 
开发者ID:sebastian-hofstaetter,项目名称:ir-generalized-translation-models,代码行数:18,代码来源:SimilarityParserTest.java


示例2: olderDocumentsExists

import org.apache.solr.search.QParser; //导入依赖的package包/类
/**
 * Searches the index, if older documents exists. Updates the solr query response.
 *
 * @param req - the solr query request information
 * @param rsp - the solr query response information
 * @return true if the hit count is greater zero, otherwise false
 * @throws SyntaxError, IOException if bad things happen
 */
private boolean olderDocumentsExists(String queryString, SolrQueryRequest req, SolrQueryResponse rsp) throws SyntaxError, IOException {
    String defType = req.getParams().get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);

    QParser queryParser = QParser.getParser(queryString, defType, req);
    Query query = queryParser.getQuery();

    TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
    req.getSearcher().search(query, totalHitCountCollector);

    rsp.add("query", String.format("%s:[* TO NOW-%s]", queryField, timeSeriesAge));
    rsp.add("queryTechnical", queryString);
    rsp.add("removedDocuments", totalHitCountCollector.getTotalHits());

    return totalHitCountCollector.getTotalHits() != 0;
}
 
开发者ID:ChronixDB,项目名称:chronix.server,代码行数:24,代码来源:ChronixRetentionHandler.java


示例3: getRangeQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  String f = field.getName();
  BytesRef low = part1 == null ? null : getCollationKey(f, part1);
  BytesRef high = part2 == null ? null : getCollationKey(f, part2);
  if (!field.indexed() && field.hasDocValues()) {
    if (field.multiValued()) {
        return new ConstantScoreQuery(DocTermOrdsRangeFilter.newBytesRefRange(
            field.getName(), low, high, minInclusive, maxInclusive));
      } else {
        return new ConstantScoreQuery(FieldCacheRangeFilter.newBytesRefRange(
            field.getName(), low, high, minInclusive, maxInclusive));
      } 
  } else {
    return new TermRangeQuery(field.getName(), low, high, minInclusive, maxInclusive);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:ICUCollationField.java


示例4: getQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
private Query getQuery(DeleteUpdateCommand cmd) {
  Query q;
  try {
    // move this higher in the stack?
    QParser parser = QParser.getParser(cmd.getQuery(), "lucene", cmd.req);
    q = parser.getQuery();
    q = QueryUtils.makeQueryable(q);

    // Make sure not to delete newer versions
    if (ulog != null && cmd.getVersion() != 0 && cmd.getVersion() != -Long.MAX_VALUE) {
      BooleanQuery bq = new BooleanQuery();
      bq.add(q, Occur.MUST);
      SchemaField sf = ulog.getVersionInfo().getVersionField();
      ValueSource vs = sf.getType().getValueSource(sf, null);
      ValueSourceRangeFilter filt = new ValueSourceRangeFilter(vs, null, Long.toString(Math.abs(cmd.getVersion())), true, true);
      FunctionRangeQuery range = new FunctionRangeQuery(filt);
      bq.add(range, Occur.MUST);
      q = bq;
    }

    return q;

  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:DirectUpdateHandler2.java


示例5: parse

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public Query parse() throws SyntaxError {
  String filter = localParams.get(getParentFilterLocalParamName());
  QParser parentParser = subQuery(filter, null);
  Query parentQ = parentParser.getQuery();

  String queryText = localParams.get(QueryParsing.V);
  // there is no child query, return parent filter from cache
  if (queryText == null || queryText.length()==0) {
                SolrConstantScoreQuery wrapped = new SolrConstantScoreQuery(getFilter(parentQ));
                wrapped.setCache(false);
                return wrapped;
  }
  QParser childrenParser = subQuery(queryText, null);
  Query childrenQuery = childrenParser.getQuery();
  return createQuery(parentQ, childrenQuery);
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:BlockJoinParentQParser.java


示例6: prepare

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException {
  SolrParams params = rb.req.getParams();
  rb.doHighlights = highlighter.isHighlightingEnabled(params);
  if(rb.doHighlights){
    String hlq = params.get(HighlightParams.Q);
    String hlparser = Objects.firstNonNull(params.get(HighlightParams.QPARSER),
                                            params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE));
    if(hlq != null){
      try {
        QParser parser = QParser.getParser(hlq, hlparser, rb.req);
        rb.setHighlightQuery(parser.getHighlightQuery());
      } catch (SyntaxError e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:HighlightComponent.java


示例7: doSimpleQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
/**
 * Executes a basic query
 */
public static DocList doSimpleQuery(String sreq,
                                    SolrQueryRequest req,
                                    int start, int limit) throws IOException {
  List<String> commands = StrUtils.splitSmart(sreq,';');

  String qs = commands.size() >= 1 ? commands.get(0) : "";
  try {
  Query query = QParser.getParser(qs, null, req).getQuery();

  // If the first non-query, non-filter command is a simple sort on an indexed field, then
  // we can use the Lucene sort ability.
  Sort sort = null;
  if (commands.size() >= 2) {
    sort = QueryParsing.parseSortSpec(commands.get(1), req).getSort();
  }

  DocList results = req.getSearcher().getDocList(query,(DocSet)null, sort, start, limit);
  return results;
  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing query: " + qs);
  }

}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:SolrPluginUtils.java


示例8: getRangeQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
/**
 * Care should be taken in calling this with higher order dimensions for performance reasons.
 */
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  //Query could look like: [x1,y1 TO x2,y2] for 2 dimension, but could look like: [x1,y1,z1 TO x2,y2,z2], and can be extrapolated to n-dimensions
  //thus, this query essentially creates a box, cube, etc.
  String[] p1 = parseCommaSeparatedList(part1, dimension);
  String[] p2 = parseCommaSeparatedList(part2, dimension);

  BooleanQuery result = new BooleanQuery(true);
  for (int i = 0; i < dimension; i++) {
    SchemaField subSF = subField(field, i, schema);
    // points must currently be ordered... should we support specifying any two opposite corner points?
    result.add(subSF.getType().getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
  }
  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:PointType.java


示例9: getValueSource

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
  field.checkFieldCacheSource(qparser);
  switch (type) {
    case INTEGER:
      return new IntFieldSource( field.getName(), FieldCache.NUMERIC_UTILS_INT_PARSER );
    case FLOAT:
      return new FloatFieldSource( field.getName(), FieldCache.NUMERIC_UTILS_FLOAT_PARSER );
    case DATE:
      return new TrieDateFieldSource( field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER );        
    case LONG:
      return new LongFieldSource( field.getName(), FieldCache.NUMERIC_UTILS_LONG_PARSER );
    case DOUBLE:
      return new DoubleFieldSource( field.getName(), FieldCache.NUMERIC_UTILS_DOUBLE_PARSER );
    default:
      throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + field.name);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TrieField.java


示例10: getQueryFromSpatialArgs

import org.apache.solr.search.QParser; //导入依赖的package包/类
private Query getQueryFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs) {
  T strategy = getStrategy(field.getName());

  SolrParams localParams = parser.getLocalParams();
  String scoreParam = (localParams == null ? null : localParams.get(SCORE_PARAM));

  //We get the valueSource for the score then the filter and combine them.

  ValueSource valueSource = getValueSourceFromSpatialArgs(parser, field, spatialArgs, scoreParam, strategy);
  if (valueSource == null) {
    //FYI Solr FieldType doesn't have a getFilter(). We'll always grab
    // getQuery() but it's possible a strategy has a more efficient getFilter
    // that could be wrapped -- no way to know.
    //See SOLR-2883 needScore
    return strategy.makeQuery(spatialArgs); //ConstantScoreQuery
  }

  FunctionQuery functionQuery = new FunctionQuery(valueSource);

  if (localParams != null && !localParams.getBool(FILTER_PARAM, true))
    return functionQuery;

  Filter filter = strategy.makeFilter(spatialArgs);
  return new FilteredQuery(functionQuery, filter);
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:AbstractSpatialFieldType.java


示例11: getValueSourceFromSpatialArgs

import org.apache.solr.search.QParser; //导入依赖的package包/类
protected ValueSource getValueSourceFromSpatialArgs(QParser parser, SchemaField field, SpatialArgs spatialArgs, String score, T strategy) {
  if (score == null) {
    return null;
  }
  switch (score) {
    case NONE:
    case "":
      return null;
    case DISTANCE:
      double multiplier = 1.0;//TODO support units=kilometers
      return strategy.makeDistanceValueSource(spatialArgs.getShape().getCenter(), multiplier);
    case RECIP_DISTANCE:
      return strategy.makeRecipDistanceValueSource(spatialArgs.getShape());
    default:
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
          "'score' local-param must be one of " + supportedScoreModes);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:AbstractSpatialFieldType.java


示例12: getRangeQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
public Query getRangeQuery(QParser parser, SchemaField field, final CurrencyValue p1, final CurrencyValue p2, final boolean minInclusive, final boolean maxInclusive) {
  String currencyCode = (p1 != null) ? p1.getCurrencyCode() :
                        (p2 != null) ? p2.getCurrencyCode() : defaultCurrency;

  // ValueSourceRangeFilter doesn't check exists(), so we have to
  final Filter docsWithValues = new FieldValueFilter(getAmountField(field).getName());
  final Filter vsRangeFilter = new ValueSourceRangeFilter
    (new RawCurrencyValueSource(field, currencyCode, parser),
     p1 == null ? null : p1.getAmount() + "", 
     p2 == null ? null : p2.getAmount() + "",
     minInclusive, maxInclusive);
  final Filter docsInRange = new ChainedFilter
    (new Filter [] { docsWithValues, vsRangeFilter }, ChainedFilter.AND);

  return new SolrConstantScoreQuery(docsInRange);
  
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:CurrencyField.java


示例13: getRangeQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) {
  Integer minValue = stringValueToIntValue(min);
  Integer maxValue = stringValueToIntValue(max);

  if (field.multiValued() && field.hasDocValues() && !field.indexed()) {
    // for the multi-valued dv-case, the default rangeimpl over toInternal is correct
    return super.getRangeQuery(parser, field, minValue.toString(), maxValue.toString(), minInclusive, maxInclusive);
  }
  Query query = null;
  final boolean matchOnly = field.hasDocValues() && !field.indexed();
  if (matchOnly) {
    query = new ConstantScoreQuery(FieldCacheRangeFilter.newIntRange(field.getName(),
            min == null ? null : minValue,
            max == null ? null : maxValue,
            minInclusive, maxInclusive));
  } else {
    query = NumericRangeQuery.newIntRange(field.getName(), DEFAULT_PRECISION_STEP,
            min == null ? null : minValue,
            max == null ? null : maxValue,
            minInclusive, maxInclusive);
  }

  return query;
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:EnumField.java


示例14: parse

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public Query parse() throws SyntaxError {

	SolrParams localParams = getLocalParams();
	SolrParams params = getParams();
	SolrParams solrParams = SolrParams.wrapDefaults(localParams, params);
	QParser baseParser = subQuery(solrParams.get(QueryParsing.V), null);
       Query startNodesQuery = baseParser.getQuery();	
       String fromField = localParams.get("from", "node_id");
	String toField = localParams.get("to", "edge_ids");
	
	QParser traversalBaseParser = subQuery(localParams.get("traversalFilter"), null);		
       Query traversalFilter = traversalBaseParser.getQuery();	
       
       // TODO: un-invert this logic
	boolean onlyLeafNodes = Boolean.valueOf(localParams.get("returnOnlyLeaf", "false"));
	boolean returnStartNodes = Boolean.valueOf(localParams.get("returnRoot", "true"));
	int maxDepth = Integer.valueOf(localParams.get("maxDepth", "-1"));
	
	GraphQuery gq = new GraphQuery(startNodesQuery, fromField, toField, traversalFilter);
	gq.setMaxDepth(maxDepth);
	gq.setOnlyLeafNodes(onlyLeafNodes);
	gq.setReturnStartNodes(returnStartNodes);
	return gq;
}
 
开发者ID:kwatters,项目名称:solrgraph,代码行数:26,代码来源:GraphQueryParser.java


示例15: prepare

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public void prepare(ResponseBuilder rb) throws IOException {
  SolrParams params = rb.req.getParams();
  rb.doHighlights = highlighter.isHighlightingEnabled(params);
  if(rb.doHighlights){
    String hlq = params.get(HighlightParams.Q);
    if(hlq != null){
      try {
        QParser parser = QParser.getParser(hlq, null, rb.req);
        rb.setHighlightQuery(parser.getHighlightQuery());
      } catch (SyntaxError e) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
      }
    }
  }
}
 
开发者ID:netboynb,项目名称:search-core,代码行数:17,代码来源:HighlightComponent.java


示例16: LocalGraph

import org.apache.solr.search.QParser; //导入依赖的package包/类
/**
 * Builds a new {@link LocalGraph} with the given data.
 * 
 * @param graphNode the graph name.
 * @param request the Solr query request.
 * @param response the Solr query response.
 * @param qparser the query parser.
 * @param fetchSize the fetch size that will be used in reads.
 * @param consumer the Graph event consumer that will be notified on relevant events.
 */
private LocalGraph(
	final Node graphNode, 
	final SolrQueryRequest request, 
	final SolrQueryResponse response, 
	final QParser qparser, 
	final int fetchSize, 
	final GraphEventConsumer consumer) {
	super(graphNode, consumer, fetchSize);
	this.graphTermQuery = new TermQuery(new Term(Field.C, graphNodeStringified));
	this.request = request;
	this.updateCommand = new AddUpdateCommand(request);
	this.updateProcessor = request.getCore().getUpdateProcessingChain(null).createProcessor(request, response);
	this.searcher = request.getSearcher();
	this.qParser = qparser;
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:26,代码来源:LocalGraph.java


示例17: getRangeQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  int dimension = 2;

  String[] p1;
  String[] p2;
  try {
    p1 = ParseUtils.parsePoint(null, part1, dimension);
    p2 = ParseUtils.parsePoint(null, part2, dimension);
  } catch (InvalidShapeException e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
  BooleanQuery result = new BooleanQuery(true);
  for (int i = 0; i < dimension; i++) {
    SchemaField subSF = subField(field, i);
    // points must currently be ordered... should we support specifying any two opposite corner points?
    result.add(subSF.getType().getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
  }
  return result;

}
 
开发者ID:netboynb,项目名称:search-core,代码行数:22,代码来源:LatLonType.java


示例18: getRangeQuery

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
/**
 * Care should be taken in calling this with higher order dimensions for performance reasons.
 */
public Query getRangeQuery(QParser parser, SchemaField field, String part1, String part2, boolean minInclusive, boolean maxInclusive) {
  //Query could look like: [x1,y1 TO x2,y2] for 2 dimension, but could look like: [x1,y1,z1 TO x2,y2,z2], and can be extrapolated to n-dimensions
  //thus, this query essentially creates a box, cube, etc.
  String[] p1;
  String[] p2;
  try {
    p1 = ParseUtils.parsePoint(null, part1, dimension);
    p2 = ParseUtils.parsePoint(null, part2, dimension);
  } catch (InvalidShapeException e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
  BooleanQuery result = new BooleanQuery(true);
  for (int i = 0; i < dimension; i++) {
    SchemaField subSF = subField(field, i);
    // points must currently be ordered... should we support specifying any two opposite corner points?
    result.add(subSF.getType().getRangeQuery(parser, subSF, p1[i], p2[i], minInclusive, maxInclusive), BooleanClause.Occur.MUST);
  }
  return result;
}
 
开发者ID:netboynb,项目名称:search-core,代码行数:24,代码来源:PointType.java


示例19: createParser

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Override
public QParser createParser(String qStr, SolrParams localParams, SolrParams params,
                            SolrQueryRequest req) {
  answerTypeMap = new HashMap<String, String>();//<co id="qqpp.atm"/>
  answerTypeMap.put("L", "NE_LOCATION");
  answerTypeMap.put("T", "NE_TIME|NE_DATE");
  answerTypeMap.put("P", "NE_PERSON");
  answerTypeMap.put("M", "NE_MONEY");
  answerTypeMap.put("O", "NE_ORGANIZATION");
  answerTypeMap.put("L", "NE_LOCATION");
  answerTypeMap.put("C", "NE_PERCENT");
  answerTypeMap.put("F", "DESCRIPTION");
  answerTypeMap.put("X", "OTHERS");
  QParser qParser;
  if (params.getBool(OWLParams.COMPONENT_NAME, false) == true //<co id="qqpp.explainif"/>
          && qStr.equals("*:*") == false) {
    AnswerTypeClassifier atc =
            new AnswerTypeClassifier(model, probs, atcg);//<co id="qqpp.atc"/>
    Parser parser = new ChunkParser(chunker, tagger);//<co id="qqpp.parser"/>
    qParser = new WiseOwlQParser(qStr, localParams, //<co id="qqpp.construct"/>
            params, req, parser, atc, answerTypeMap);
  } else {
    //just do a regular query if OWL is turned off
    qParser = req.getCore().getQueryPlugin("edismax")
            .createParser(qStr, localParams, params, req);
  }
  return qParser;
}
 
开发者ID:asmehra95,项目名称:wiseowl,代码行数:29,代码来源:WiseOwlQParserPlugin.java


示例20: test_missingParamsCompletely

import org.apache.solr.search.QParser; //导入依赖的package包/类
@Test(expected = RuntimeException.class)
public void test_missingParamsCompletely() throws SyntaxError {

    // arrange
    ModifiableSolrParams emptyParams = new ModifiableSolrParams();

    // act - expect: exception
    QParser parser = new SimilarityParser("query",new ModifiableSolrParams(), emptyParams, req("query"));
}
 
开发者ID:sebastian-hofstaetter,项目名称:ir-generalized-translation-models,代码行数:10,代码来源:SimilarityParserTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Operation类代码示例发布时间:2022-05-21
下一篇:
Java Issuer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap