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; }
private Result doSearch(Searcher searcher, Query query, Execution execution) { Result result; if (documentTypes.size() > 1) { result = searchMultipleDocumentTypes(searcher, query, execution); } else { String docType = documentTypes.iterator().next(); Result invalidRankProfile = checkValidRankProfiles(query, documentTypes); if (invalidRankProfile != null) { return invalidRankProfile; } query.getModel().setRestrict(docType); result = searcher.search(query, execution); } updateCacheHitRatio(result, query); return result; }
private Hit retrieveUserProfile(String userId, Execution execution) { Query query = new Query(); query.getModel().setRestrict("user"); query.getModel().getQueryTree().setRoot(new WordItem(userId, "user_id")); query.setHits(1); SearchChain vespaChain = execution.searchChainRegistry().getComponent("vespa"); Result result = new Execution(vespaChain, execution.context()).search(query); execution.fill(result); // This is needed to get the actual summary data Iterator<Hit> hiterator = result.hits().deepIterator(); return hiterator.hasNext() ? hiterator.next() : null; }
public Result search(Query query, Execution execution) { // Get tensor and read items from user profile Object userIdProperty = query.properties().get("user_id"); if (userIdProperty != null) { Hit userProfile = retrieveUserProfile(userIdProperty.toString(), execution); if (userProfile != null) { addUserProfileTensorToQuery(query, userProfile); NotItem notItem = new NotItem(); notItem.addItem(new IntItem(1, "has_user_item_cf")); for (String item : getReadItems(userProfile.getField("has_read_items"))){ notItem.addItem(new WordItem(item, "post_id")); } QueryTreeUtil.andQueryItemWithRoot(query, notItem); } } // Restrict to search in blog_posts query.getModel().setRestrict("blog_post"); // Rank blog posts using tensor rank profile if(query.properties().get("ranking") == null) { query.properties().set(new CompoundName("ranking"), "tensor"); } return execution.search(query); }
model.setSources(asString(value,"")); else if (key.last().equals(Model.RESTRICT)) model.setRestrict(asString(value,"")); else throwIllegalParameter(key.last(),Model.MODEL);