Skip to content

Commit 40fedd2

Browse files
michaeljmarshalldriftx
authored andcommitted
CNDB-13696: Add BM25 hybrid search test on collections (#1701)
### What is the issue This is a follow up test for riptano/cndb#13696. ### What does this PR fix and why was it fixed The fix was already merged, but this confirms that without the fix, collections are affected by the NoSuchElementException bug.
1 parent a55f060 commit 40fedd2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/unit/org/apache/cassandra/index/sai/cql/BM25Test.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,37 @@ public void testCollections() throws Throwable
749749
});
750750
}
751751

752+
@Test
753+
public void testOrderingSeveralSSTablesWithMapPredicate() throws Throwable
754+
{
755+
// Force search-then-sort
756+
QueryController.QUERY_OPT_LEVEL = 0;
757+
createTable("CREATE TABLE %s (id int PRIMARY KEY, category text, map_category map<int, int>)");
758+
createAnalyzedIndex("category", true);
759+
createIndex("CREATE CUSTOM INDEX ON %s (entries(map_category)) USING 'StorageAttachedIndex'");
760+
// We don't want compaction to merge the two sstables since they are key to testing this code path.
761+
disableCompaction();
762+
763+
// Insert documents so that they all have the same bm25 score and are easy to query across sstables
764+
for (int i = 0; i < 10; i++)
765+
{
766+
execute("INSERT INTO %s (id, category, map_category) VALUES (?, ?, ?)",
767+
i, "Health", map(0, i));
768+
if (i == 4)
769+
flush();
770+
}
771+
772+
// Confirm that the memtable/sstable and sstable/sstable pairings work as expected.
773+
beforeAndAfterFlush(() -> {
774+
// Submit a query that will fetch keys from 2 overlapping sstables. The key is that they are overlapping
775+
// because we have optimizations that will skip keys that are out of the sstable's range. In this case,
776+
// the actual bm25 data doesn't matter because we are covering the edge case of mapping PrK back to
777+
// its value here.
778+
assertRowsIgnoringOrder(execute("SELECT id FROM %s WHERE map_category[0] >= 4 AND map_category[0] <= 6 ORDER BY category BM25 OF 'health' LIMIT 10"),
779+
row(4), row(5), row(6));
780+
});
781+
}
782+
752783
@Test
753784
public void testOrderingSeveralSegments() throws Throwable
754785
{

0 commit comments

Comments
 (0)