diff --git a/python/python/lancedb/query.py b/python/python/lancedb/query.py index 1d32051a..b6554de4 100644 --- a/python/python/lancedb/query.py +++ b/python/python/lancedb/query.py @@ -1495,7 +1495,7 @@ class LanceFtsQueryBuilder(LanceQueryBuilder): if self._phrase_query: if isinstance(query, str): if not query.startswith('"') or not query.endswith('"'): - query = f'"{query}"' + self._query = f'"{query}"' elif isinstance(query, FullTextQuery) and not isinstance( query, PhraseQuery ): diff --git a/python/python/tests/test_fts.py b/python/python/tests/test_fts.py index a7422823..b9a9d665 100644 --- a/python/python/tests/test_fts.py +++ b/python/python/tests/test_fts.py @@ -325,11 +325,18 @@ def test_search_fts_phrase_query(table): pass table.create_fts_index("text", use_tantivy=False, with_position=True, replace=True) results = table.search("puppy").limit(100).to_list() + + # Test with quotation marks phrase_results = table.search('"puppy runs"').limit(100).to_list() assert len(results) > len(phrase_results) assert len(phrase_results) > 0 - # Test with a query + # Test with .phrase_query() + phrase_results = table.search("puppy runs").phrase_query().limit(100).to_list() + assert len(results) > len(phrase_results) + assert len(phrase_results) > 0 + + # Test with PhraseQuery() phrase_results = ( table.search(PhraseQuery("puppy runs", "text")).limit(100).to_list() ) diff --git a/python/python/tests/test_table.py b/python/python/tests/test_table.py index cc55997a..9d40c2fa 100644 --- a/python/python/tests/test_table.py +++ b/python/python/tests/test_table.py @@ -1487,7 +1487,7 @@ def setup_hybrid_search_table(db: DBConnection, embedding_func): table.add([{"text": p} for p in phrases]) # Create a fts index - table.create_fts_index("text") + table.create_fts_index("text", with_position=True) return table, MyTable, emb