mirror of
https://github.com/lancedb/lancedb.git
synced 2026-01-10 13:52:58 +00:00
Better handle empty results from tantivy (#155)
Closes #154 --------- Co-authored-by: Chang She <chang@lancedb.com>
This commit is contained in:
@@ -118,6 +118,8 @@ def search_index(
|
||||
query = index.parse_query(query)
|
||||
# get top results
|
||||
results = searcher.search(query, limit)
|
||||
if results.count == 0:
|
||||
return tuple(), tuple()
|
||||
return tuple(
|
||||
zip(
|
||||
*[
|
||||
|
||||
@@ -164,6 +164,8 @@ class LanceFtsQueryBuilder(LanceQueryBuilder):
|
||||
index = tantivy.Index.open(index_path)
|
||||
# get the scores and doc ids
|
||||
row_ids, scores = search_index(index, self._query, self._limit)
|
||||
if len(row_ids) == 0:
|
||||
return pd.DataFrame()
|
||||
scores = pa.array(scores)
|
||||
output_tbl = self._table.to_lance().take(row_ids, columns=self._columns)
|
||||
output_tbl = output_tbl.append_column("score", scores)
|
||||
|
||||
Reference in New Issue
Block a user