com.yahoo.search.Query类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(209)

本文整理了Java中com.yahoo.search.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:com.yahoo.search.Query
类名称:Query

Query介绍

[英]A search query containing all the information required to produce a Result.

The Query contains:

  • the selection criterion received in the request - which may be a structured boolean tree of operators, an annotated piece of natural language text received from a user, or a combination of both
  • a set of field containing the additional general parameters of a query - number of hits, ranking, presentation etc.
  • a Map of properties, which can be of any object type

The properties has three sources

  1. They may be set in some Searcher component already executed for this Query - the properties acts as a blackboard for communicating arbitrary objects between Searcher components.
  2. Properties set in the search Request received - the properties acts as a way to parametrize Searcher components from the Request.
  3. Properties defined in the selected com.yahoo.search.query.profile.QueryProfile - this provides defaults for the parameters to Searcher components. Note that by using query profile types, the components may define the set of parameters they support.
    When looked up, the properties are accessed in the priority order listed above.

The identity of a query is determined by its content.
[中]包含生成结果所需的所有信息的搜索查询。
该查询包含:
*请求中接收到的选择标准——可能是一个结构化的布尔运算符树、从用户处接收到的一段带注释的自然语言文本,或者两者的组合
*一组字段,包含查询的附加常规参数——点击数、排名、表示等。
*属性映射,可以是任何对象类型
这些房产有三个来源
1.这些属性可能在已经为此查询执行的某些搜索器组件中设置——这些属性充当黑板,用于在搜索器组件之间通信任意对象。
1.在接收到的搜索请求中设置的属性-这些属性充当从请求中参数化搜索器组件的方法。
1.在所选com中定义的属性。雅虎。搜索查询轮廓QueryProfile——这为Searcher组件的参数提供了默认值。请注意,通过使用查询配置文件类型,组件可以定义它们支持的参数集。
查找时,将按上面列出的优先级顺序访问属性。
查询的标识由其内容决定。

代码示例

代码示例来源:origin: com.yahoo.vespa/container-search

private void copyPropertiesTo(Query clone) {
  clone.model = model.cloneFor(clone);
  clone.select = select.cloneFor(clone);
  clone.ranking = (Ranking) ranking.clone();
  clone.presentation = (Presentation) presentation.clone();
  clone.context = getContext(true).cloneFor(clone);
  // Correct the Query instance in properties
  clone.properties().setParentQuery(clone);
  assert (clone.properties().getParentQuery() == clone);
  clone.setTraceLevel(getTraceLevel());
  clone.setHits(getHits());
  clone.setOffset(getOffset());
  clone.setNoCache(getNoCache());
  clone.setGroupingSessionCache(getGroupingSessionCache());
  clone.requestId = null; // Each clone should have their own requestId.
}

代码示例来源:origin: com.yahoo.vespa/container-search

Set<String> sources = getModel().getSources();
Set<String> fields = getPresentation().getSummaryFields();
StringBuilder yql = new StringBuilder("select ");
if (fields.isEmpty()) {
  yql.append('*');
} else {
  commaSeparated(yql, fields);
    yql.append("sources ");
  commaSeparated(yql, sources);
if (getRanking().getSorting() != null && getRanking().getSorting().fieldOrders().size() > 0) {
  serializeSorting(yql);
  if (getOffset() != 0) {
    yql.append(" limit ").append(getHits() + getOffset())
      .append(" offset ").append(getOffset());
  } else if (getHits() != 10) {
    yql.append(" limit ").append(getHits());
if (getTimeout() != defaultTimeout) {
  yql.append(" timeout ").append(getTimeout());

代码示例来源:origin: com.yahoo.vespa/container-search

/**
 * Creates a new query from another query, but with time sensitive fields reset.
 */
public static Query createNewQuery(Query query) {
  return new Query(query, System.currentTimeMillis());
}

代码示例来源:origin: com.yahoo.vespa/container-search

/** Convenience method to set both the offset and the number of hits to return */
public void setWindow(int offset,int hits) {
  setOffset(offset);
  setHits(hits);
}

代码示例来源:origin: com.yahoo.vespa/container-search

private void validateQueryCache(Query query) {
  if ( ! query.getRanking().getQueryCache() ) return;
  if (query.getTimeout() <= maxQueryCacheTimeout) return;
  if (query.isTraceable(2)) {
    query.trace("Query timeout (" + query.getTimeout() + " ms) > max query cache timeout (" +
          maxQueryCacheTimeout + " ms). Disabling query cache.", 2);
  }
  query.getRanking().setQueryCache(false);
}

代码示例来源:origin: com.yahoo.vespa/container-search

/** Returns whether the given query is equal to this */
@Override
public boolean equals(Object other) {
  if (this == other) return true;
  if ( ! (other instanceof Query)) return false;
  Query q = (Query) other;
  if (getOffset() != q.getOffset()) return false;
  if (getHits() != q.getHits()) return false;
  if ( ! getPresentation().equals(q.getPresentation())) return false;
  if ( ! getRanking().equals(q.getRanking())) return false;
  if ( ! getModel().equals(q.getModel())) return false;
  // TODO: Compare property settings
  return true;
}

代码示例来源:origin: com.yahoo.vespa/container-search

/**
 * Sets the list of {@link Grouping} objects assigned to the given query. This method overwrites any grouping
 * objects already assigned to the query.
 *
 * @param query The query whose grouping list to set.
 * @param lst   The grouping list to set.
 */
public static void setGroupingList(Query query, List<Grouping> lst) {
  query.properties().set(PROP_GROUPINGLIST, lst);
}

代码示例来源:origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  if (query.properties().get(YQL) == null) {
    return execution.search(query);
  QueryTree newTree;
  try {
    newTree = parser.parse(Parsable.fromQueryModel(query.getModel())
                    .setQuery(query.properties().getString(YQL)));
  } catch (RuntimeException e) {
    return new Result(query, ErrorMessage.createInvalidQueryParameter(
    int maxHits = query.properties().getInteger(MAX_HITS);
    int maxOffset = query.properties().getInteger(MAX_OFFSET);
    if (parser.getOffset() > maxOffset) {
      return new Result(query, ErrorMessage.createInvalidQueryParameter("Requested offset " + parser.getOffset()
  query.getModel().getQueryTree().setRoot(newTree.getRoot());
  query.getPresentation().getSummaryFields().addAll(parser.getYqlSummaryFields());
  for (VespaGroupingStep step : parser.getGroupingSteps()) {
    GroupingRequest.newInstance(query)
    query.getModel().getSources().clear();
  } else {
    query.getModel().getSources().addAll(parser.getYqlSources());
    query.setOffset(parser.getOffset());
    query.setHits(parser.getHits());
    query.setTimeout(parser.getTimeout().longValue());

代码示例来源:origin: com.yahoo.vespa/container-search

Model model = query.getModel();
  if (key.last().equals(Model.QUERY_STRING))
    model.setQueryString(asString(value, ""));
  Ranking ranking = query.getRanking();
  if (key.size()==2) {
    if (key.last().equals(Ranking.LOCATION))
    query.getPresentation().setBolding(asBoolean(value, true));
  else if (key.last().equals(Presentation.SUMMARY))
    query.getPresentation().setSummary(asString(value, ""));
  else if (key.last().equals(Presentation.FORMAT))
    query.getPresentation().setFormat(asString(value,""));
  else if (key.last().equals(Presentation.TIMING))
    query.getPresentation().setTiming(asBoolean(value, true));
  else if (key.last().equals(Presentation.SUMMARY_FIELDS))
    query.getPresentation().setSummaryFields(asString(value,""));
  else
    throwIllegalParameter(key.last(), Presentation.PRESENTATION);
    query.getSelect().setWhereString(asString(value, ""));
  } else if (key.last().equals(Select.GROUPING)) {
    query.getSelect().setGroupingString(asString(value, ""));
  setRankingFeature(query, key.rest().toString(), toSpecifiedType(key.rest().toString(), value, profileRegistry.getTypeRegistry().getComponent("features")));
} else if (key.first().equals("rankproperty")) {
  query.getRanking().getProperties().put(key.rest().toString(), toSpecifiedType(key.rest().toString(), value, profileRegistry.getTypeRegistry().getComponent("properties")));
} else if (key.size()==1) {
  if (key.equals(Query.HITS))

代码示例来源:origin: com.yahoo.vespa/container-search

/**
 * Sets the document selection criterion of the query.
 *
 * @param where the documents to select as a JSON string on the format specified in
 *        <a href="https://docs.vespa.ai/documentation/reference/select-reference.html">the select reference doc</a>
 */
public void setWhereString(String where) {
  this.where = where;
  parent.getModel().setType(SELECT);
  // This replaces the current query
  parent.getModel().clearQueryTree();
}

代码示例来源:origin: com.yahoo.vespa/container-search

private List<Query> createQueries(Query query, Set<String> docTypes) {
  query.getModel().getQueryTree(); // performance: parse query before cloning such that it is only done once
  List<Query> retval = new ArrayList<>(docTypes.size());
  if (docTypes.size() == 1) {
    query.getModel().setRestrict(docTypes.iterator().next());
    retval.add(query);
  } else if ( ! docTypes.isEmpty() ) {
    for (String docType : docTypes) {
      Query q = query.clone();
      q.setOffset(0);
      q.setHits(query.getOffset() + query.getHits());
      q.getModel().setRestrict(docType);
      retval.add(q);
    }
  }
  return retval;
}

代码示例来源:origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  List<PhraseMatcher.Phrase> phrases = phraseMatcher.matchPhrases(query.getModel().getQueryTree().getRoot());
  if (phrases != null && !query.properties().getBoolean(suggestonly, false)) {
    remove(phrases);
    query.trace("Removing stop words",true,2);
  }
  return execution.search(query);
}

代码示例来源:origin: com.yahoo.vespa/container-search

Sorting sorting = query.getRanking().getSorting();
if (sorting != null && sorting.fieldOrders().size() > 1) {
  query.trace("Can not use grouping for deduping with multi-level sorting.", 3);
int hits = query.getHits();
int offset = query.getOffset();
int groupingHits = hits + offset;
        dedupField,
        groupingHits,
        query.getPresentation().getSummary(),
        sorting));
query.setHits(0);
query.setOffset(0);
Result result = execution.search(query);
query.setHits(hits);
query.setOffset(offset);
  query.trace(msg, 3);
  log.log(LogLevel.WARNING, msg);
  throw new IllegalStateException("Failed to produce deduped result set.");
  query.trace("Deduping grouping request returned no hits, returning empty result.", 3);
  return result;

代码示例来源:origin: com.yahoo.vespa/container-search

static int getQueryFlags(Query query) {
  int flags = 0;
  boolean requestCoverage=true; // Always request coverage information
  flags |= 0; // was collapse
  flags |= query.properties().getBoolean(Model.ESTIMATE) ? 0x00000080 : 0;
  flags |= (query.getRanking().getFreshness() != null) ? 0x00002000 : 0;
  flags |= requestCoverage ? 0x00008000 : 0;
  flags |= query.getNoCache() ? 0x00010000 : 0;
  flags |= 0x00020000;                         // was PARALLEL
  flags |= query.properties().getBoolean(Ranking.RANKFEATURES,false) ? 0x00040000 : 0;
  return flags;
}

代码示例来源:origin: vespa-engine/sample-apps

@Override
public Result search(Query query, Execution execution) {
  Object tensorProperty = query.properties().get("tensor");
  if (tensorProperty != null) {
    // Construct a Tensor object based on the query parameter
    Tensor tensor = Tensor.from(tensorProperty.toString());
    // Create a new rank feature using this tensor
    query.getRanking().getFeatures().put("query(tensor)", tensor);
    // Set the rank profile to use
    query.properties().set(new CompoundName("ranking"), "simple_tensor_ranking");
  }
  return execution.search(query);
}

代码示例来源:origin: com.yahoo.vespa/container-search

/** Returns the session id of this query, or null if none is assigned */
public SessionId getSessionId() {
  if (requestId == null) return null;
  return new SessionId(requestId, getRanking().getProfile());
}

代码示例来源:origin: com.yahoo.vespa/container-search

private boolean shouldBeDegraded(Query query, IndexFacts.Session indexFacts) {
  if (query.getRanking().getSorting() == null) return false;
  if (query.getRanking().getSorting().fieldOrders().isEmpty()) return false;
  if ( ! query.getSelect().getGrouping().isEmpty()) return false;
  if ( ! query.properties().getBoolean(DEGRADING, true)) return false;
  Index index = indexFacts.getIndex(query.getRanking().getSorting().fieldOrders().get(0).getFieldName());
  if (index == null) return false;
  if ( ! index.isFastSearch()) return false;
  if ( ! index.isNumerical()) return false;
  return true;
}

代码示例来源:origin: com.yahoo.vespa/container-search

/**
 * Prepares this for binary serialization.
 * <p>
 * This must be invoked after all changes have been made to this query before it is passed
 * on to a receiving backend. Calling it is somewhat expensive, so it should only happen once.
 * If a prepared query is cloned, it stays prepared.
 */
public void prepare() {
  getModel().prepare(getRanking());
  getPresentation().prepare();
  getRanking().prepare();
}

代码示例来源:origin: com.yahoo.vespa/container-search

/** Send a getDocsums request to a node. Responses will be added to the given receiver. */
private void sendGetDocsumsRequest(int nodeId, List<FastHit> hits, String summaryClass, CompressionType compression,
                  Result result, GetDocsumsResponseReceiver responseReceiver) {
  Client.NodeConnection node = resourcePool.nodeConnections().get(nodeId);
  if (node == null) {
    String error = "Could not fill hits from unknown node " + nodeId;
    responseReceiver.receive(Client.GetDocsumsResponseOrError.fromError(error));
    result.hits().addError(ErrorMessage.createEmptyDocsums(error));
    log.warning("Got hits with partid " + nodeId + ", which is not included in the current dispatch config");
    return;
  }
  Query query = result.getQuery();
  String rankProfile = query.getRanking().getProfile();
  byte[] serializedSlime = BinaryFormat
      .encode(toSlime(rankProfile, summaryClass, query.getModel().getDocumentDb(), query.getSessionId(), hits));
  double timeoutSeconds = ((double) query.getTimeLeft() - 3.0) / 1000.0;
  Compressor.Compression compressionResult = resourcePool.compressor().compress(compression, serializedSlime);
  resourcePool.client().getDocsums(hits, node, compressionResult.type(), serializedSlime.length, compressionResult.data(),
      responseReceiver, timeoutSeconds);
}

代码示例来源:origin: com.yahoo.vespa/container-search

@Override
public Result search(Query query, Execution execution) {
  String bb = query.properties().getString(posBb);
  String ll = query.properties().getString(posLl);
  String xy = query.properties().getString(posXy);
  if (query.getRanking().getLocation() != null) {
    query.trace("query already has a location set, not processing 'pos' params", false, 1);
    return execution.search(query);
  String posAttribute = query.properties().getString(posAttributeName);
  loc.setAttribute(posAttribute);
  query.getRanking().setLocation(loc);
  return execution.search(query);

相关文章