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, "")); }
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); } }
public boolean hasEncodableProperties() { if ( ! ranking.getProperties().isEmpty()) return true; if ( ! ranking.getFeatures().isEmpty()) return true; if ( ranking.getFreshness() != null) return true; if ( model.getSearchPath() != null) return true; if ( model.getDocumentDb() != null) return true; if ( presentation.getHighlight() != null && ! presentation.getHighlight().getHighlightItems().isEmpty()) return true; return false; }
@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); }
if ( ! query.getRanking().getFeatures().isEmpty()) { s.append(" rankfeatures=") .append(query.getRanking().getFeatures().toString());
/** * Encodes properties of this query. * * @param buffer the buffer to encode to * @param encodeQueryData true to encode all properties, false to only include session information, not actual query data * @return the encoded length */ public int encodeAsProperties(ByteBuffer buffer, boolean encodeQueryData) { // Make sure we don't encode anything here if we have turned the property feature off // Due to sendQuery we sometimes end up turning this feature on and then encoding a 0 int as the number of // property maps - that's ok (probably we should simplify by just always turning the feature on) if (! hasEncodableProperties()) return 0; int start = buffer.position(); int mapCountPosition = buffer.position(); buffer.putInt(0); // map count will go here int mapCount = 0; // TODO: Push down mapCount += ranking.getProperties().encode(buffer, encodeQueryData); if (encodeQueryData) mapCount += ranking.getFeatures().encode(buffer); // TODO: Push down if (encodeQueryData && presentation.getHighlight() != null) mapCount += MapEncoder.encodeStringMultiMap(Highlight.HIGHLIGHTTERMS, presentation.getHighlight().getHighlightTerms(), buffer); // TODO: Push down if (encodeQueryData) mapCount += MapEncoder.encodeSingleValue("model", "searchpath", model.getSearchPath(), buffer); mapCount += MapEncoder.encodeSingleValue(DocumentDatabase.MATCH_PROPERTY, DocumentDatabase.SEARCH_DOC_TYPE_KEY, model.getDocumentDb(), buffer); mapCount += MapEncoder.encodeMap("caches", createCacheSettingMap(), buffer); buffer.putInt(mapCountPosition, mapCount); return buffer.position() - start; }
if (key.get(1).equals(Ranking.FEATURES)) return ranking.getFeatures().getObject(key.rest().rest().toString()); if (key.get(1).equals(Ranking.PROPERTIES)) return ranking.getProperties().get(key.rest().rest().toString()); return query.getRanking().getFeatures().getObject(key.rest().toString()); } else if (key.first().equals("rankproperty")) { return query.getRanking().getProperties().get(key.rest().toString());