@Override public Object get(CompoundName name,Map<String,String> context, com.yahoo.processing.request.Properties substitution) { return super.get(name, context == null ? requestMap : context, substitution); }
@Override public void set(CompoundName name,Object value,Map<String,String> context) { super.set(name, value, context == null ? requestMap : context); }
private String createQuerySelectionString() { String s = query.properties().getString(streamingUserid); if (s != null) { return "id.user==" + s; } s = query.properties().getString(streamingGroupname); if (s != null) { return "id.group==\"" + s + "\""; } return query.properties().getString(streamingSelection); }
/** * Invoked during deep cloning of the parent query. */ public void setParentQuery(Query query) { if (chained() != null) chained().setParentQuery(query); } }
/** The query owning this property object. * Only guaranteed to work if this instance is accessible as query.properties() */ public Query getParentQuery() { if (chained() == null) { throw new RuntimeException("getParentQuery should only be called on a properties instance accessible as query.properties()"); } else { return chained().getParentQuery(); } }
/** * Returns the set of properties set for the source or provider given in the query (if any). * * If the query has not set sourceName or providerName, null will be returned */ public static Properties getSourceProperties(Query query) { String sourceName = query.properties().getString(SOURCENAME); String providerName = query.properties().getString(PROVIDERNAME); if (sourceName == null || providerName == null) return null; Properties sourceProperties = new SubProperties("source." + sourceName, query.properties()); Properties providerProperties = new SubProperties("provider." + providerName, query.properties()); sourceProperties.chain(providerProperties); return sourceProperties; }
@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); }
String fullName = prefix + field.getName(); if (field.getType() == FieldType.genericQueryProfileType) { // Generic map for (Map.Entry<String, Object> entry : originalProperties.listProperties(fullName, context).entrySet()) { try { properties().set(fullName + "." + entry.getKey(), entry.getValue(), context); } catch (IllegalArgumentException e) { throw new QueryException("Invalid request parameter", e); Object value = originalProperties.get(fullName, context); if (value != null) { try { properties().set(fullName, value, context); } catch (IllegalArgumentException e) { throw new QueryException("Invalid request parameter", e);
String collapseField = query.properties().getString(collapsefield); int collapseSize = query.properties().getInteger(collapsesize,defaultCollapseSize); query.properties().set(collapse, "0"); int performedQueries = 0; Result resultSource; String collapseSummary = query.properties().getString(collapseSummaryName); query.properties().set(collapse, "1"); return result;
@Override public Result search(Query query, Execution execution) { if (query.properties().get(YQL) == null) { return execution.search(query); 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()
/** * Returns the list of page templates specified in the query, or the default if none, or the * empty list if no default, never null. */ private List<PageElement> selectPageTemplates(Query query) { // Determine the list of page template ids @SuppressWarnings("unchecked") List<String> pageIds = (List<String>) query.properties().get(pageIdListName); if (pageIds==null) { String pageIdString=query.properties().getString(pageIdName,"").trim(); if (pageIdString.length()>0) pageIds=Arrays.asList(pageIdString.split(" ")); } // If none set, just return the default or null if none if (pageIds==null) { PageElement defaultPage=templateRegistry.getComponent("default"); return (defaultPage==null ? Collections.<PageElement>emptyList() : Collections.singletonList(defaultPage)); } // Resolve the id list to page templates List<PageElement> pages=new ArrayList<>(pageIds.size()); for (String pageId : pageIds) { PageTemplate page=templateRegistry.getComponent(pageId); if (page==null) query.errors().add(ErrorMessage.createInvalidQueryParameter("Could not resolve requested page template '" + pageId + "'")); else pages.add(page); } return pages; }
/** * Returns the number of milliseconds to wait for a response from a search backend * before timing it out. Default is 500. * <p> * Note: If Ranking.RANKFEATURES is turned on, this is hardcoded to 6 minutes. * * @return timeout in milliseconds. */ public long getTimeout() { return properties().getBoolean(Ranking.RANKFEATURES, false) ? dumpTimeout : timeout; }
if (traceLevel == 0) return; CompiledQueryProfile profile = null; QueryProfileProperties profileProperties = properties().getInstance(QueryProfileProperties.class); if (profileProperties != null) profile = profileProperties.getQueryProfile(); Set<String> mentioned = new HashSet<>(); for (Map.Entry<String,String> requestProperty : requestProperties().entrySet() ) { Object resolvedValue = properties().get(requestProperty.getKey(), requestProperties()); if (resolvedValue == null && requestProperty.getKey().equals("queryProfile")) resolvedValue = requestProperty.getValue();
@Override public Result search(Query query, Execution execution) { String id = query.properties().getString(idKey); Double rate = query.properties().getDouble(quotaKey); if (id == null || rate == null) { query.trace(false, 6, "Skipping rate limiting check. Need both " + idKey + " and " + quotaKey + " set"); String idDim = query.properties().getString(idDimensionKey, null); if (idDim == null) { overQuotaCounter.add(1); overQuotaCounter.add(1, createContext(idDim, id)); if ( ! query.properties().getBoolean(dryRunKey, false)) return new Result(query, new ErrorMessage(429, "Too many requests", "Allowed rate: " + rate + "/s")); addAllocatedCapacity(id, - query.properties().getDouble(costKey, 1.0));
protected QueryPacket createQueryPacket(String serverId, Query query) { QueryPacket queryPacket = QueryPacket.create(serverId, query); int compressionLimit = query.properties().getInteger(PACKET_COMPRESSION_LIMIT, 0); queryPacket.setCompressionLimit(compressionLimit); if (compressionLimit != 0) queryPacket.setCompressionType(query.properties().getString(PACKET_COMPRESSION_TYPE, "lz4")); return queryPacket; }
/** * Look at a "reasonable" number of this by default. We don't want to set this too low because it impacts * the totalHits value returned. * <p> * If maxhits/offset is set high, use that as the default instead because it means somebody will want to be able to * get lots of hits. We could use hits+offset instead of maxhits+maxoffset but that would destroy pagination * with large values because totalHits is wrong. * <p> * If we ever get around to estimate totalhits we can rethink this. */ private long decideDefaultMaxHits(Query query) { int maxHits; int maxOffset; if (query.properties().getBoolean(PAGINATION, true)) { maxHits = query.properties().getInteger(DefaultProperties.MAX_HITS); maxOffset = query.properties().getInteger(DefaultProperties.MAX_OFFSET); } else { maxHits = query.getHits(); maxOffset = query.getOffset(); } return maxHits + maxOffset; }
params.setVisitorLibrary("searchvisitor"); params.setLocalDataHandler(this); if (query.properties().getDouble(streamingFromtimestamp) != null) { params.setFromTimestamp(query.properties().getDouble(streamingFromtimestamp).longValue()); if (query.properties().getDouble(streamingTotimestamp) != null) { params.setToTimestamp(query.properties().getDouble(streamingTotimestamp).longValue()); if (query.properties().getString(streamingLoadtype) != null) { LoadType loadType = visitorSessionFactory.getLoadTypeSet().getNameMap().get(query.properties().getString(streamingLoadtype)); if (loadType != null) { params.setLoadType(loadType); if (query.properties().getString(streamingPriority) != null) { params.setPriority(DocumentProtocol.getPriorityByName( query.properties().getString(streamingPriority))); String ordering = query.properties().getString(streamingOrdering); if (ordering != null) { params.setVisitorOrdering(getOrdering(ordering)); String maxbuckets = query.properties().getString(streamingMaxbucketspervisitor); if (maxbuckets != null) { params.setMaxBucketsPerVisitor(Integer.parseInt(maxbuckets));
private void init(Map<String, String> requestMap, CompiledQueryProfile queryProfile) { startTime = System.currentTimeMillis(); if (queryProfile != null) { // Move all request parameters to the query profile just to validate that the parameter settings are legal Properties queryProfileProperties = new QueryProfileProperties(queryProfile); properties().chain(queryProfileProperties); // TODO: Just checking legality rather than actually setting would be faster setPropertiesFromRequestMap(requestMap, properties()); // Adds errors to the query for illegal set attempts // Create the full chain properties().chain(new QueryProperties(this, queryProfile.getRegistry())). chain(new ModelObjectMap()). chain(new RequestContextProperties(requestMap)). chain(queryProfileProperties). chain(new DefaultProperties()); // Pass the values from the query profile which maps through a field in the Query object model // through the property chain to cause those values to be set in the Query object model setFieldsFrom(queryProfileProperties, requestMap); } else { // bypass these complications if there is no query profile to get values from and validate against properties(). chain(new QueryProperties(this, CompiledQueryProfileRegistry.empty)). chain(new PropertyMap()). chain(new DefaultProperties()); setPropertiesFromRequestMap(requestMap, properties()); } properties().setParentQuery(this); traceProperties(); }
@Override public PropertyMap clone() { PropertyMap clone = (PropertyMap)super.clone(); clone.properties = new HashMap<>(); for (Map.Entry<CompoundName, Object> entry : this.properties.entrySet()) { Object cloneValue = cloneHelper.clone(entry.getValue()); if (cloneValue == null) cloneValue = entry.getValue(); // Shallow copy objects which does not support cloning clone.properties.put(entry.getKey(), cloneValue); } return clone; }