@@ -416,7 +416,12 @@ private void createSimpleTable()
416
416
417
417
private String createAnalyzedIndex ()
418
418
{
419
- return createIndex ("CREATE CUSTOM INDEX ON %s(v) " +
419
+ return createAnalyzedIndex ("v" );
420
+ }
421
+
422
+ private String createAnalyzedIndex (String column )
423
+ {
424
+ return createIndex ("CREATE CUSTOM INDEX ON %s(" + column + ") " +
420
425
"USING 'org.apache.cassandra.index.sai.StorageAttachedIndex' " +
421
426
"WITH OPTIONS = {" +
422
427
"'index_analyzer': '{" +
@@ -628,4 +633,63 @@ public void cannotHaveAggregationOnBM25Query()
628
633
.isInstanceOf (InvalidRequestException .class )
629
634
.hasMessage (SelectStatement .TOPK_AGGREGATION_ERROR );
630
635
}
636
+
637
+ @ Test
638
+ public void testBM25andFilterz () throws Throwable
639
+ {
640
+ createTable ("CREATE TABLE %s (id int PRIMARY KEY, category text, score int, title text, body text)" );
641
+ createAnalyzedIndex ("body" );
642
+ createIndex ("CREATE CUSTOM INDEX ON %s (score) USING 'StorageAttachedIndex'" );
643
+ insertArticle ();
644
+ beforeAndAfterFlush (
645
+ () -> {
646
+ // 10 docs have score 3 and 3 of those have "health"
647
+ var result = execute ("SELECT * FROM %s WHERE score = 3 ORDER BY body BM25 OF ? LIMIT 10" ,
648
+ "health" );
649
+ assertThat (result ).hasSize (3 );
650
+
651
+ // 4 docs have score 2 and one of those has "discussed"
652
+ result = execute ("SELECT * FROM %s WHERE score = 2 ORDER BY body BM25 OF ? LIMIT 10" ,
653
+ "discussed" );
654
+ assertThat (result ).hasSize (1 );
655
+ });
656
+ }
657
+
658
+ private void insertArticle ()
659
+ {
660
+ Object [][] dataset = {
661
+ { 1 , "Climate" , 5 , "Climate change is a pressing issue. Climate patterns are shifting globally. Scientists study climate data daily." },
662
+ { 2 , "Technology" , 3 , "Technology is advancing. New technology in AI and robotics is groundbreaking." },
663
+ { 3 , "Economy" , 4 , "The economy is recovering. Economy experts are optimistic. However, the global economy still faces risks." },
664
+ { 4 , "Health" , 3 , "Health is wealth. Health policies need to be improved to ensure better public health outcomes." },
665
+ { 5 , "Education" , 2 , "Education is the foundation of success. Online education is booming." },
666
+ { 6 , "Climate" , 4 , "Climate and health are closely linked. Climate affects air quality and health outcomes." },
667
+ { 7 , "Education" , 3 , "Technology and education go hand in hand. EdTech is revolutionizing education through technology." },
668
+ { 8 , "Economy" , 3 , "The global economy is influenced by technology. Fintech is a key part of the economy today." },
669
+ { 9 , "Health" , 3 , "Education and health programs must be prioritized. Health education is vital in schools." },
670
+ { 10 , "Mixed" , 3 , "Technology, economy, and education are pillars of development." },
671
+ { 11 , "Climate" , 5 , "Climate climate climate. It's everywhere. Climate drives political and economic decisions." },
672
+ { 12 , "Health" , 2 , "Health concerns rise with climate issues. Health organizations are sounding the alarm." },
673
+ { 13 , "Economy" , 3 , "The economy is fluctuating. Uncertainty looms over the economy." },
674
+ { 14 , "Health" , 3 , "Cutting-edge technology is transforming healthcare. Healthtech merges health and technology." },
675
+ { 15 , "Education" , 2 , "Education reforms are underway. Education experts suggest holistic changes." },
676
+ { 16 , "Climate" , 4 , "Climate affects the economy and health. Climate events cost billions annually." },
677
+ { 17 , "Technology" , 3 , "Technology is the backbone of the modern economy. Without technology, economic growth stagnates." },
678
+ { 18 , "Health" , 2 , "Health is discussed less than economy or climate, but health matters deeply." },
679
+ { 19 , "Climate" , 5 , "Climate change, climate policies, climate research—climate is the buzzword of our time." },
680
+ { 20 , "Mixed" , 3 , "Investments in education and technology will shape the future of the global economy." }
681
+ };
682
+
683
+ for (Object [] article : dataset )
684
+ {
685
+ execute (
686
+ "INSERT INTO %s (id, category, score, body) VALUES (?, ?, ?, ?)" ,
687
+ article [0 ],
688
+ article [1 ],
689
+ article [2 ],
690
+ article [3 ]
691
+ );
692
+ }
693
+ }
694
+
631
695
}
0 commit comments