Skip to content

Commit 1257c10

Browse files
Ngalstyan4var77
authored andcommitted
Quote table name identifiers in bm25 queries
1 parent 92096e8 commit 1257c10

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lantern_extras/src/bm25_agg.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::bloom::Bloom as PGBloom;
22
use crate::{BM25_DEFAULT_APPROXIMATION_THRESHHOLD, BM25_DEFAULT_B, BM25_DEFAULT_K1};
33
use fastbloom::BloomFilter;
4+
use lantern_cli::utils::quote_ident;
45
use std::collections::HashMap;
56

67
use pgrx::datum::Internal;
@@ -64,7 +65,9 @@ fn bm25_score(table_fqn: String, document: String, query: String) -> f32 {
6465
.expect("Failed to get stemmed document")
6566
.expect("Stemmed document was NULL");
6667
let table_fqn = table_fqn.to_string();
67-
let (corpus_size, avg_doc_len) = match Spi::get_two::<i32, f32>(&format!("SELECT term_freq AS corpus_size, (doc_ids_len / 100.0)::real AS avg_doc_len FROM {}_bm25 WHERE term IS NULL;", table_fqn))
68+
let table_bm25_fqn = format!("{}_bm25", table_fqn);
69+
let (corpus_size, avg_doc_len) = match Spi::get_two::<i32, f32>(&format!("SELECT term_freq AS corpus_size, (doc_ids_len / 100.0)::real AS avg_doc_len FROM {} WHERE term IS NULL;",
70+
quote_ident(&table_bm25_fqn)))
6871
.expect("Failed to get corpus size") {
6972
(Some(corpus_size), Some(avg_doc_len)) => (corpus_size as u64, avg_doc_len),
7073
_ => panic!("Failed to get corpus size and avg doc len"),
@@ -73,9 +76,10 @@ fn bm25_score(table_fqn: String, document: String, query: String) -> f32 {
7376
client
7477
.select(
7578
&format!(
76-
"SELECT term, term_freq FROM {}_bm25 WHERE term = ANY(text_to_stem_array('{}'));",
77-
table_fqn, query
78-
),
79+
"SELECT term, term_freq FROM {} WHERE term = ANY(text_to_stem_array('{}'));",
80+
quote_ident(&table_bm25_fqn),
81+
query
82+
),
7983
None,
8084
None,
8185
)

0 commit comments

Comments
 (0)