com.yahoo.search.Query.getRanking()方法的使用及代码示例

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

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

Query.getRanking介绍

[英]Returns the ranking to be used for this query, never null
[中]返回用于此查询的排名,从不为空

代码示例

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

  1. private int getFeatureInt(boolean sendSessionId) {
  2. int features = QF_PARSEDQUERY | QF_RANKP; // this bitmask means "parsed query" in query packet.
  3. // And rank properties. Both are always present
  4. features |= (query.getRanking().getSorting() != null) ? QF_SORTSPEC : 0;
  5. features |= (query.getRanking().getLocation() != null) ? QF_LOCATION : 0;
  6. features |= (query.hasEncodableProperties()) ? QF_PROPERTIES : 0;
  7. features |= GroupingExecutor.hasGroupingList(query) ? QF_GROUPSPEC : 0;
  8. features |= (sendSessionId) ? QF_SESSIONID : 0;
  9. return features;
  10. }

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

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

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

  1. private void setRankingFeature(Query query, String key, Object value) {
  2. if (value instanceof Tensor)
  3. query.getRanking().getFeatures().put(key, (Tensor)value);
  4. else
  5. query.getRanking().getFeatures().put(key, asString(value, ""));
  6. }

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

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

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

  1. private ErrorMessage validate(Query query) {
  2. String attribute = query.getRanking().getMatchPhase().getAttribute();
  3. if ( attribute != null && ! validMatchPhaseAttributes.contains(attribute) ) {
  4. return ErrorMessage.createInvalidQueryParameter("The attribute '" + attribute + "' is not available for match-phase. " +
  5. "It must be a single value numeric attribute with fast-search.");
  6. }
  7. attribute = query.getRanking().getMatchPhase().getDiversity().getAttribute();
  8. if (attribute != null && ! validDiversityAttributes.contains(attribute)) {
  9. return ErrorMessage.createInvalidQueryParameter("The attribute '" + attribute + "' is not available for match-phase diversification. " +
  10. "It must be a single value numeric or string attribute.");
  11. }
  12. return null;
  13. }

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

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

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

  1. @Override
  2. public Result search(Query query, Execution execution) {
  3. List<FieldOrder> s = (query.getRanking().getSorting() != null) ? query.getRanking().getSorting().fieldOrders() : null;
  4. if (s == null) {
  5. return execution.search(query);
  6. }
  7. for (FieldOrder f : s) {
  8. if (RANK.equals(f.getFieldName())) {
  9. return execution.search(query);
  10. }
  11. }
  12. query.getRanking().setProfile(UNRANKED);
  13. return execution.search(query);
  14. }

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

  1. /**
  2. * Create an empty result.
  3. * A source creating a result is <b>required</b> to call
  4. * {@link #setTotalHitCount} before releasing this result.
  5. *
  6. * @param query the query which produced this result
  7. * @param hits the hit container which this will return from {@link #hits()}
  8. */
  9. @SuppressWarnings("deprecation")
  10. public Result(Query query, HitGroup hits) {
  11. super(query);
  12. if (query==null) throw new NullPointerException("The query reference in a result cannot be null");
  13. this.hits=hits;
  14. hits.setQuery(query);
  15. if (query.getRanking().getSorting() != null) {
  16. setHitOrderer(new HitSortOrderer(query.getRanking().getSorting()));
  17. }
  18. }

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

  1. /** Returns the session id of this query, and creates and assigns it if not already present */
  2. public SessionId getSessionId(String serverId) {
  3. if (requestId == null)
  4. requestId = UniqueRequestId.next(serverId);
  5. return new SessionId(requestId, getRanking().getProfile());
  6. }

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

  1. private void addUserProfileTensorToQuery(Query query, Hit userProfile) {
  2. Object userItemCf = userProfile.getField("user_item_cf");
  3. if (userItemCf != null && userItemCf instanceof Tensor) {
  4. query.getRanking().getFeatures().put("query(user_item_cf)", (Tensor)userItemCf);
  5. }
  6. }

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

  1. private boolean shouldBeDegraded(Query query, IndexFacts.Session indexFacts) {
  2. if (query.getRanking().getSorting() == null) return false;
  3. if (query.getRanking().getSorting().fieldOrders().isEmpty()) return false;
  4. if ( ! query.getSelect().getGrouping().isEmpty()) return false;
  5. if ( ! query.properties().getBoolean(DEGRADING, true)) return false;
  6. Index index = indexFacts.getIndex(query.getRanking().getSorting().fieldOrders().get(0).getFieldName());
  7. if (index == null) return false;
  8. if ( ! index.isFastSearch()) return false;
  9. if ( ! index.isNumerical()) return false;
  10. return true;
  11. }

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

  1. static void removeEmptySummaryFeatureFields(Result result) {
  2. // TODO: Move to some searcher in Vespa backend search chains
  3. if ( ! result.hits().getQuery().getRanking().getListFeatures())
  4. for (Iterator<Hit> i = result.hits().unorderedIterator(); i.hasNext();)
  5. i.next().removeField(Hit.RANKFEATURES_FIELD);
  6. }

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

  1. /**
  2. * Returns whether we need to send the query when fetching summaries.
  3. * This is necessary if the query requests summary features or dynamic snippeting
  4. */
  5. public boolean summaryNeedsQuery(Query query) {
  6. if (query.getRanking().getQueryCache()) return false; // Query is cached in backend
  7. DocumentDatabase documentDb = getDocumentDatabase(query);
  8. // Needed to generate a dynamic summary?
  9. DocsumDefinition docsumDefinition = documentDb.getDocsumDefinitionSet().getDocsum(query.getPresentation().getSummary());
  10. if (docsumDefinition.isDynamic()) return true;
  11. // Needed to generate ranking features?
  12. RankProfile rankProfile = documentDb.rankProfiles().get(query.getRanking().getProfile());
  13. if (rankProfile == null) return true; // stay safe
  14. if (rankProfile.hasSummaryFeatures()) return true;
  15. if (query.getRanking().getListFeatures()) return true;
  16. // (Don't just add other checks here as there is a return false above)
  17. return false;
  18. }

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

  1. public Optional<FillInvoker> getFillInvoker(Query query, VespaBackEndSearcher searcher, DocumentDatabase documentDb) {
  2. if (query.properties().getBoolean(dispatchSummaries, true)
  3. && ! searcher.summaryNeedsQuery(query)
  4. && query.getRanking().getLocation() == null
  5. && ! searcher.getCacheControl().useCache(query))
  6. {
  7. return Optional.of(new RpcFillInvoker(this, documentDb));
  8. } else {
  9. return Optional.empty();
  10. }
  11. }

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

  1. private void setDegradation(Query query) {
  2. query.trace("Using sorting degrading for performance - totalHits will be wrong. " +
  3. "Turn off with sorting.degrading=false.", 2);
  4. Sorting.FieldOrder primarySort = query.getRanking().getSorting().fieldOrders().get(0); // ensured above
  5. MatchPhase matchPhase = query.getRanking().getMatchPhase();
  6. matchPhase.setAttribute(primarySort.getFieldName());
  7. matchPhase.setAscending(primarySort.getSortOrder() == Sorting.Order.ASCENDING);
  8. if (matchPhase.getMaxHits() == null)
  9. matchPhase.setMaxHits(decideDefaultMaxHits(query));
  10. }

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

  1. /** Returns whether the given query is equal to this */
  2. @Override
  3. public boolean equals(Object other) {
  4. if (this == other) return true;
  5. if ( ! (other instanceof Query)) return false;
  6. Query q = (Query) other;
  7. if (getOffset() != q.getOffset()) return false;
  8. if (getHits() != q.getHits()) return false;
  9. if ( ! getPresentation().equals(q.getPresentation())) return false;
  10. if ( ! getRanking().equals(q.getRanking())) return false;
  11. if ( ! getModel().equals(q.getModel())) return false;
  12. // TODO: Compare property settings
  13. return true;
  14. }

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

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

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

  1. private Result sortAndTrimResults(Result result, Query q, int offset, int hits, Execution execution) {
  2. if (q.getRanking().getSorting() != null) {
  3. execution.fillAttributes(result); // Always correct as we can only sort on attributes
  4. result.hits().sort();
  5. }
  6. result.hits().trim(offset, hits);
  7. return result;
  8. }

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

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

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

  1. @Override
  2. public com.yahoo.search.Result search(Query query, Execution execution) {
  3. Location location = query.getRanking().getLocation();
  4. if (location != null && (location.getAttribute() == null)) {
  5. IndexFacts facts = execution.context().getIndexFacts();
  6. List<String> search = facts.newSession(query.getModel().getSources(), query.getModel().getRestrict()).documentTypes();
  7. for (String sd : search) {
  8. String defaultPosition = facts.getDefaultPosition(sd);
  9. if (defaultPosition != null) {
  10. location.setAttribute(defaultPosition);
  11. }
  12. }
  13. if (location.getAttribute() == null) {
  14. location.setAttribute(facts.getDefaultPosition(null));
  15. }
  16. }
  17. return execution.search(query);
  18. }

相关文章