2023-04-04 21:38:30 +08:00
|
|
|
use itertools::Itertools;
|
|
|
|
|
|
|
|
use crate::{search::new::interner::Interned, SearchContext};
|
|
|
|
|
|
|
|
/// A phrase in the user's search query, consisting of several words
|
|
|
|
/// that must appear side-by-side in the search results.
|
|
|
|
#[derive(Default, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Phrase {
|
|
|
|
pub words: Vec<Option<Interned<String>>>,
|
|
|
|
}
|
|
|
|
impl Interned<Phrase> {
|
|
|
|
pub fn description(self, ctx: &SearchContext) -> String {
|
|
|
|
let p = ctx.phrase_interner.get(self);
|
|
|
|
p.words.iter().flatten().map(|w| ctx.word_interner.get(*w)).join(" ")
|
|
|
|
}
|
2023-04-12 17:40:44 +08:00
|
|
|
pub fn words(self, ctx: &SearchContext) -> Vec<Option<Interned<String>>> {
|
|
|
|
let p = ctx.phrase_interner.get(self);
|
|
|
|
p.words.clone()
|
|
|
|
}
|
2023-04-04 21:38:30 +08:00
|
|
|
}
|