deniskuzZ commented on code in PR #6595:
URL: https://github.com/apache/hive/pull/6595#discussion_r4587993845


##########
standalone-metastore/metastore-search/src/main/java/org/apache/hive/search/search/Searcher.java:
##########
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hive.search.search;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hive.search.config.SearchOptions;
+import org.apache.hive.search.exception.InferenceException;
+import org.apache.hive.search.exception.SearchException;
+import org.apache.hive.search.mapping.FieldSchema;
+import org.apache.hive.search.mapping.IndexMapping;
+import org.apache.hive.search.mapping.TableDocument;
+import org.apache.hive.search.mapping.TextFieldSchema;
+import org.apache.hive.search.metastore.MetastoreTableMapper;
+import org.apache.hive.search.metastore.TableBlobCodec;
+import org.apache.hive.search.index.IndexManager;
+import org.apache.hive.search.inference.Embedder;
+import org.apache.hive.search.inference.EmbedderRegistry;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.queryparser.simple.SimpleQueryParser;
+import org.apache.lucene.search.BayesianScoreEstimator;
+import org.apache.lucene.search.BayesianScoreQuery;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BoostQuery;
+import org.apache.lucene.search.ConstantScoreQuery;
+import org.apache.lucene.search.DisjunctionMaxQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.KnnFloatVectorQuery;
+import org.apache.lucene.search.LogOddsFusionQuery;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.SearcherManager;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.PrefixQuery;
+import org.apache.lucene.search.TopDocs;
+
+public final class Searcher implements AutoCloseable {
+  private final EmbedderRegistry embedderRegistry;
+  private final IndexSearcher indexSearcher;
+  private final SearcherManager searcherManager;
+  private final IndexMapping mapping;
+  private final SearchOptions searchConfig;
+  private final BayesianScoreEstimator.Parameters parameters;
+  private final long processedEventId;
+
+  public Searcher(SearcherManager manager,
+      IndexManager indexManager,
+      EmbedderRegistry registry,
+      SearchOptions searchConfig,
+      BayesianScoreEstimator.Parameters parameters) throws IOException {
+    this.searcherManager = manager;
+    this.processedEventId = indexManager.getProcessedEventId();
+    this.indexSearcher = manager.acquire();
+    this.mapping = indexManager.mapping();
+    this.searchConfig = searchConfig;
+    this.parameters = parameters;
+    this.embedderRegistry = Objects.requireNonNull(registry, "Embedder 
registry");
+  }
+
+  public TableSearchResult search(SearchQuery request)
+      throws SearchException, IOException {
+    if (StringUtils.isBlank(request.body().queryText())) {
+      throw new SearchException("query text is required");
+    }
+    Query filter = compileScopeFilter(request.catalogName(), 
request.databaseName());
+    int size = request.limit() > 0 ? request.limit() : 
searchConfig.getDefaultLimit();
+    Query query =
+        switch (request.body()) {
+          case MatchQuery match -> compileMatchQuery(match.resolve(mapping), 
filter);
+          case SemanticQuery semantic -> 
compileSemanticQuery(semantic.resolve(mapping), size, filter);

Review Comment:
   Removing the semanticK multiplier makes k = limit. Moving the filter into 
the kNN query fixes scoping, but for hybrid queries LogOddsFusionQuery now sees 
only limit semantic candidates per field, which lowers fusion recall. 
   
   Was that intended? I’d keep oversampling (max(limit, limit * multiplier)) at 
least for the hybrid branch.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to