You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/12/19 20:11:59 UTC

[GitHub] [solr] dsmiley commented on a diff in pull request #1245: SOLR-16567: KnnQueryParser support for both pre-filters and post-filter

dsmiley commented on code in PR #1245:
URL: https://github.com/apache/solr/pull/1245#discussion_r1052598167


##########
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:
   This method looks suspicious.  The cost is merely a hint; it isn't explicitly an indicator about being a post-filter or not.  Maybe I'm missing the point?



-- 
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-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org