File tree 2 files changed +48
-0
lines changed 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -2376,6 +2376,7 @@ def search_sql(
2376
2376
limit : Optional [int ] = None ,
2377
2377
offset : Optional [int ] = None ,
2378
2378
where : Optional [str ] = None ,
2379
+ include_rank : bool = False ,
2379
2380
) -> str :
2380
2381
""" "
2381
2382
Return SQL string that can be used to execute searches against this table.
@@ -2385,6 +2386,7 @@ def search_sql(
2385
2386
:param limit: SQL limit
2386
2387
:param offset: SQL offset
2387
2388
:param where: Extra SQL fragment for the WHERE clause
2389
+ :param include_rank: Select the search rank column in the final query
2388
2390
"""
2389
2391
# Pick names for table and rank column that don't clash
2390
2392
original = "original_" if self .name == "original" else "original"
@@ -2427,6 +2429,8 @@ def search_sql(
2427
2429
rank_implementation = "rank_bm25(matchinfo([{}], 'pcnalx'))" .format (
2428
2430
fts_table
2429
2431
)
2432
+ if include_rank :
2433
+ columns_with_prefix_sql += ",\n " + rank_implementation + " rank"
2430
2434
limit_offset = ""
2431
2435
if limit is not None :
2432
2436
limit_offset += " limit {}" .format (limit )
Original file line number Diff line number Diff line change @@ -556,6 +556,50 @@ def test_enable_fts_error_message_on_views():
556
556
" rank_bm25(matchinfo([books_fts], 'pcnalx'))"
557
557
),
558
558
),
559
+ (
560
+ {"include_rank" : True },
561
+ "FTS5" ,
562
+ (
563
+ "with original as (\n "
564
+ " select\n "
565
+ " rowid,\n "
566
+ " *\n "
567
+ " from [books]\n "
568
+ ")\n "
569
+ "select\n "
570
+ " [original].*,\n "
571
+ " [books_fts].rank rank\n "
572
+ "from\n "
573
+ " [original]\n "
574
+ " join [books_fts] on [original].rowid = [books_fts].rowid\n "
575
+ "where\n "
576
+ " [books_fts] match :query\n "
577
+ "order by\n "
578
+ " [books_fts].rank"
579
+ ),
580
+ ),
581
+ (
582
+ {"include_rank" : True },
583
+ "FTS4" ,
584
+ (
585
+ "with original as (\n "
586
+ " select\n "
587
+ " rowid,\n "
588
+ " *\n "
589
+ " from [books]\n "
590
+ ")\n "
591
+ "select\n "
592
+ " [original].*,\n "
593
+ " rank_bm25(matchinfo([books_fts], 'pcnalx')) rank\n "
594
+ "from\n "
595
+ " [original]\n "
596
+ " join [books_fts] on [original].rowid = [books_fts].rowid\n "
597
+ "where\n "
598
+ " [books_fts] match :query\n "
599
+ "order by\n "
600
+ " rank_bm25(matchinfo([books_fts], 'pcnalx'))"
601
+ ),
602
+ ),
559
603
],
560
604
)
561
605
def test_search_sql (kwargs , fts , expected ):
You can’t perform that action at this time.
0 commit comments