本文整理了Java中com.yahoo.search.Query.getRanking
方法的一些代码示例,展示了Query.getRanking
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getRanking
方法的具体详情如下:
包路径:com.yahoo.search.Query
类名称:Query
方法名:getRanking
[英]Returns the ranking to be used for this query, never null
[中]返回用于此查询的排名,从不为空
代码示例来源:origin: com.yahoo.vespa/container-search
private int getFeatureInt(boolean sendSessionId) {
int features = QF_PARSEDQUERY | QF_RANKP; // this bitmask means "parsed query" in query packet.
// And rank properties. Both are always present
features |= (query.getRanking().getSorting() != null) ? QF_SORTSPEC : 0;
features |= (query.getRanking().getLocation() != null) ? QF_LOCATION : 0;
features |= (query.hasEncodableProperties()) ? QF_PROPERTIES : 0;
features |= GroupingExecutor.hasGroupingList(query) ? QF_GROUPSPEC : 0;
features |= (sendSessionId) ? QF_SESSIONID : 0;
return features;
}
代码示例来源: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 void setRankingFeature(Query query, String key, Object value) {
if (value instanceof Tensor)
query.getRanking().getFeatures().put(key, (Tensor)value);
else
query.getRanking().getFeatures().put(key, asString(value, ""));
}
代码示例来源: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
private ErrorMessage validate(Query query) {
String attribute = query.getRanking().getMatchPhase().getAttribute();
if ( attribute != null && ! validMatchPhaseAttributes.contains(attribute) ) {
return ErrorMessage.createInvalidQueryParameter("The attribute '" + attribute + "' is not available for match-phase. " +
"It must be a single value numeric attribute with fast-search.");
}
attribute = query.getRanking().getMatchPhase().getDiversity().getAttribute();
if (attribute != null && ! validDiversityAttributes.contains(attribute)) {
return ErrorMessage.createInvalidQueryParameter("The attribute '" + attribute + "' is not available for match-phase diversification. " +
"It must be a single value numeric or string attribute.");
}
return null;
}
代码示例来源: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
@Override
public Result search(Query query, Execution execution) {
List<FieldOrder> s = (query.getRanking().getSorting() != null) ? query.getRanking().getSorting().fieldOrders() : null;
if (s == null) {
return execution.search(query);
}
for (FieldOrder f : s) {
if (RANK.equals(f.getFieldName())) {
return execution.search(query);
}
}
query.getRanking().setProfile(UNRANKED);
return execution.search(query);
}
代码示例来源:origin: com.yahoo.vespa/container-search
/**
* Create an empty result.
* A source creating a result is <b>required</b> to call
* {@link #setTotalHitCount} before releasing this result.
*
* @param query the query which produced this result
* @param hits the hit container which this will return from {@link #hits()}
*/
@SuppressWarnings("deprecation")
public Result(Query query, HitGroup hits) {
super(query);
if (query==null) throw new NullPointerException("The query reference in a result cannot be null");
this.hits=hits;
hits.setQuery(query);
if (query.getRanking().getSorting() != null) {
setHitOrderer(new HitSortOrderer(query.getRanking().getSorting()));
}
}
代码示例来源:origin: com.yahoo.vespa/container-search
/** Returns the session id of this query, and creates and assigns it if not already present */
public SessionId getSessionId(String serverId) {
if (requestId == null)
requestId = UniqueRequestId.next(serverId);
return new SessionId(requestId, getRanking().getProfile());
}
代码示例来源:origin: vespa-engine/sample-apps
private void addUserProfileTensorToQuery(Query query, Hit userProfile) {
Object userItemCf = userProfile.getField("user_item_cf");
if (userItemCf != null && userItemCf instanceof Tensor) {
query.getRanking().getFeatures().put("query(user_item_cf)", (Tensor)userItemCf);
}
}
代码示例来源: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
static void removeEmptySummaryFeatureFields(Result result) {
// TODO: Move to some searcher in Vespa backend search chains
if ( ! result.hits().getQuery().getRanking().getListFeatures())
for (Iterator<Hit> i = result.hits().unorderedIterator(); i.hasNext();)
i.next().removeField(Hit.RANKFEATURES_FIELD);
}
代码示例来源:origin: com.yahoo.vespa/container-search
/**
* Returns whether we need to send the query when fetching summaries.
* This is necessary if the query requests summary features or dynamic snippeting
*/
public boolean summaryNeedsQuery(Query query) {
if (query.getRanking().getQueryCache()) return false; // Query is cached in backend
DocumentDatabase documentDb = getDocumentDatabase(query);
// Needed to generate a dynamic summary?
DocsumDefinition docsumDefinition = documentDb.getDocsumDefinitionSet().getDocsum(query.getPresentation().getSummary());
if (docsumDefinition.isDynamic()) return true;
// Needed to generate ranking features?
RankProfile rankProfile = documentDb.rankProfiles().get(query.getRanking().getProfile());
if (rankProfile == null) return true; // stay safe
if (rankProfile.hasSummaryFeatures()) return true;
if (query.getRanking().getListFeatures()) return true;
// (Don't just add other checks here as there is a return false above)
return false;
}
代码示例来源:origin: com.yahoo.vespa/container-search
public Optional<FillInvoker> getFillInvoker(Query query, VespaBackEndSearcher searcher, DocumentDatabase documentDb) {
if (query.properties().getBoolean(dispatchSummaries, true)
&& ! searcher.summaryNeedsQuery(query)
&& query.getRanking().getLocation() == null
&& ! searcher.getCacheControl().useCache(query))
{
return Optional.of(new RpcFillInvoker(this, documentDb));
} else {
return Optional.empty();
}
}
代码示例来源:origin: com.yahoo.vespa/container-search
private void setDegradation(Query query) {
query.trace("Using sorting degrading for performance - totalHits will be wrong. " +
"Turn off with sorting.degrading=false.", 2);
Sorting.FieldOrder primarySort = query.getRanking().getSorting().fieldOrders().get(0); // ensured above
MatchPhase matchPhase = query.getRanking().getMatchPhase();
matchPhase.setAttribute(primarySort.getFieldName());
matchPhase.setAscending(primarySort.getSortOrder() == Sorting.Order.ASCENDING);
if (matchPhase.getMaxHits() == null)
matchPhase.setMaxHits(decideDefaultMaxHits(query));
}
代码示例来源: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
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: com.yahoo.vespa/container-search
private Result sortAndTrimResults(Result result, Query q, int offset, int hits, Execution execution) {
if (q.getRanking().getSorting() != null) {
execution.fillAttributes(result); // Always correct as we can only sort on attributes
result.hits().sort();
}
result.hits().trim(offset, hits);
return result;
}
代码示例来源: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
@Override
public com.yahoo.search.Result search(Query query, Execution execution) {
Location location = query.getRanking().getLocation();
if (location != null && (location.getAttribute() == null)) {
IndexFacts facts = execution.context().getIndexFacts();
List<String> search = facts.newSession(query.getModel().getSources(), query.getModel().getRestrict()).documentTypes();
for (String sd : search) {
String defaultPosition = facts.getDefaultPosition(sd);
if (defaultPosition != null) {
location.setAttribute(defaultPosition);
}
}
if (location.getAttribute() == null) {
location.setAttribute(facts.getDefaultPosition(null));
}
}
return execution.search(query);
}
内容来源于网络,如有侵权,请联系作者删除!