Skip to content

Commit 9a5709e

Browse files
dadaa0c0w3
authored andcommitted
Revert "Bug 1953666: Add prefix matching for Yelp modifiers"
This reverts commit adc7143.
1 parent 3694cea commit 9a5709e

File tree

2 files changed

+16
-66
lines changed

2 files changed

+16
-66
lines changed

components/suggest/src/store.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,38 +2068,6 @@ pub(crate) mod tests {
20682068
.has_location_sign(false)
20692069
.subject_exact_match(false)],
20702070
);
2071-
// Test for prefix match.
2072-
assert_eq!(
2073-
store.fetch_suggestions(SuggestionQuery::yelp("ramen D")),
2074-
vec![ramen_suggestion(
2075-
"ramen Delivery",
2076-
"https://www.yelp.com/search?find_desc=ramen+Delivery"
2077-
)
2078-
.has_location_sign(false)],
2079-
);
2080-
assert_eq!(
2081-
store.fetch_suggestions(SuggestionQuery::yelp("ramen I")),
2082-
vec![ramen_suggestion(
2083-
"ramen In",
2084-
"https://www.yelp.com/search?find_desc=ramen"
2085-
)],
2086-
);
2087-
assert_eq!(
2088-
store.fetch_suggestions(SuggestionQuery::yelp("ramen Y")),
2089-
vec![
2090-
ramen_suggestion("ramen", "https://www.yelp.com/search?find_desc=ramen")
2091-
.has_location_sign(false)
2092-
],
2093-
);
2094-
// Prefix match is available only for last words.
2095-
assert_eq!(
2096-
store.fetch_suggestions(SuggestionQuery::yelp("ramen I Tokyo")),
2097-
vec![ramen_suggestion(
2098-
"ramen I Tokyo",
2099-
"https://www.yelp.com/search?find_desc=ramen&find_loc=I+Tokyo"
2100-
)
2101-
.has_location_sign(false)],
2102-
);
21032071

21042072
Ok(())
21052073
}

components/suggest/src/yelp.rs

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,20 @@ impl SuggestDao<'_> {
237237
let candidate = candidate_chunk
238238
.map(|chunk| chunk.join(" "))
239239
.unwrap_or_default();
240-
if let Some(keyword_lowercase) = self.conn.try_query_one::<String, _>(
241-
if n == query_words.len() {
242-
"
243-
SELECT keyword FROM yelp_modifiers
244-
WHERE type = :type AND keyword BETWEEN :word AND :word || x'FFFF'
245-
LIMIT 1
246-
"
247-
} else {
248-
"
249-
SELECT keyword FROM yelp_modifiers
250-
WHERE type = :type AND keyword = :word
251-
LIMIT 1
252-
"
253-
},
240+
if self.conn.query_row_and_then_cachable(
241+
"
242+
SELECT EXISTS (
243+
SELECT 1 FROM yelp_modifiers WHERE type = :type AND keyword = :word LIMIT 1
244+
)
245+
",
254246
named_params! {
255247
":type": modifier_type,
256248
":word": candidate.to_lowercase(),
257249
},
250+
|row| row.get::<_, bool>(0),
258251
true,
259252
)? {
260-
// Preserve the query as the user typed it including its case.
261-
let keyword = format!("{}{}", candidate, &keyword_lowercase[candidate.len()..]);
262-
return Ok(Some((keyword, n)));
253+
return Ok(Some((candidate, n)));
263254
}
264255
}
265256

@@ -345,28 +336,19 @@ impl SuggestDao<'_> {
345336
.next()
346337
.map(|chunk| chunk.join(" "))
347338
.unwrap_or_default();
348-
if let Some(keyword_lowercase) = self.conn.try_query_one::<String, _>(
349-
if n == query_words.len() {
350-
"
351-
SELECT keyword FROM yelp_location_signs
352-
WHERE keyword BETWEEN :word AND :word || x'FFFF'
353-
LIMIT 1
354-
"
355-
} else {
356-
"
357-
SELECT keyword FROM yelp_location_signs
358-
WHERE keyword = :word
359-
LIMIT 1
360-
"
361-
},
339+
if self.conn.query_row_and_then_cachable(
340+
"
341+
SELECT EXISTS (
342+
SELECT 1 FROM yelp_location_signs WHERE keyword = :word LIMIT 1
343+
)
344+
",
362345
named_params! {
363346
":word": candidate.to_lowercase(),
364347
},
348+
|row| row.get::<_, bool>(0),
365349
true,
366350
)? {
367-
// Preserve the query as the user typed it including its case.
368-
let keyword = format!("{}{}", candidate, &keyword_lowercase[candidate.len()..]);
369-
return Ok(Some((keyword, n)));
351+
return Ok(Some((candidate, n)));
370352
}
371353
}
372354

0 commit comments

Comments
 (0)