alessandrobenedetti commented on code in PR #1245: URL: https://github.com/apache/solr/pull/1245#discussion_r1052909492
########## solr/core/src/java/org/apache/solr/search/neural/KnnQParser.java: ########## @@ -80,44 +82,60 @@ public Query parse() { float[] parsedVectorToSearch = parseVector(vectorToSearch, denseVectorType.getDimension()); return denseVectorType.getKnnVectorQuery( - schemaField.getName(), parsedVectorToSearch, topK, getFilterQuery()); + schemaField.getName(), parsedVectorToSearch, topK, buildPreFilter()); } - private Query getFilterQuery() throws SolrException { - if (!isFilter()) { + private Query buildPreFilter() throws SolrException { + boolean isSubQuery = recurseCount != 0; + if (!isFilter() && !isSubQuery) { String[] filterQueries = req.getParams().getParams(CommonParams.FQ); if (filterQueries != null && filterQueries.length != 0) { - List<Query> filters; + List<Query> preFilters; try { - filters = QueryUtils.parseFilterQueries(req, true); + preFilters = acceptPreFiltersOnly(QueryUtils.parseFilterQueries(req, true)); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); } - if (filters.size() == 1) { - return filters.get(0); + if (preFilters.size() == 0) { + return null; + } else if (preFilters.size() == 1) { + return preFilters.get(0); + } else { + BooleanQuery.Builder builder = new BooleanQuery.Builder(); + for (Query query : preFilters) { + builder.add(query, BooleanClause.Occur.FILTER); + } + return builder.build(); } - - BooleanQuery.Builder builder = new BooleanQuery.Builder(); - for (Query query : filters) { - builder.add(query, BooleanClause.Occur.FILTER); - } - - return builder.build(); } } - return null; } + private List<Query> acceptPreFiltersOnly(List<Query> filters) { Review Comment: Hi @dsmiley , you are right, it is a "hint" (https://solr.apache.org/guide/solr/latest/query-guide/common-query-parameters.html#cache-local-parameter) but I was wondering how to separate filter queries for the Knn search between pre-filters(should be the default and it is right now) and filters that are better to be executed after the knn search. It seems users are already using 'cost' in some scenarios to distinguish pre and post-filters so I thought it was a good way to discriminate. But if you have better ideas they are more than welcome! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org