#[non_exhaustive]pub struct KeywordSearchStrategy;Expand description
Keyword search by token overlap (KeywordSearchStrategy), the default for every shipped
backend.
Tokenizes the query and each entry (the key without its file extension, then the content) and
scores by the number of distinct query tokens the entry contains. Stop words in the query
(the, is, what, …) are ignored. Works on any backend through list and read, with no
index. Entries are read in concurrent batches of 8, each result carries the bytes read, and
entries whose read fails are skipped and logged at debug level.
use strands::storage::search::{KeywordSearchStrategy, SearchStrategy};
use strands::storage::{InMemoryStorage, Storage};
let storage = InMemoryStorage::new();
storage.write("notes/theme.md", b"enable dark mode").await?;
let results = KeywordSearchStrategy::new().search(&storage, "dark mode toggle").await?;
assert_eq!((results[0].key.as_str(), results[0].score), ("notes/theme.md", 2.0));Implementations§
Trait Implementations§
Source§impl Clone for KeywordSearchStrategy
impl Clone for KeywordSearchStrategy
impl Copy for KeywordSearchStrategy
Source§impl Debug for KeywordSearchStrategy
impl Debug for KeywordSearchStrategy
Source§impl Default for KeywordSearchStrategy
impl Default for KeywordSearchStrategy
Source§impl SearchStrategy for KeywordSearchStrategy
impl SearchStrategy for KeywordSearchStrategy
Source§fn search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
storage: &'life1 dyn Storage,
query: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<StorageSearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
storage: &'life1 dyn Storage,
query: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<StorageSearchResult>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn index<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_storage: &'life1 dyn Storage,
_key: &'life2 str,
_data: &'life3 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn index<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_storage: &'life1 dyn Storage,
_key: &'life2 str,
_data: &'life3 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Indexes one entry for later searches; called on each write. Strategies that search on the
fly (keyword) or manage their own index keep the default no-op. Read more
Source§fn requires_host_fs(&self) -> bool
fn requires_host_fs(&self) -> bool
Whether the strategy reads or writes the host filesystem itself, so it
cannot work on storage routed through a sandbox.
false by default.Auto Trait Implementations§
impl Freeze for KeywordSearchStrategy
impl RefUnwindSafe for KeywordSearchStrategy
impl Send for KeywordSearchStrategy
impl Sync for KeywordSearchStrategy
impl Unpin for KeywordSearchStrategy
impl UnsafeUnpin for KeywordSearchStrategy
impl UnwindSafe for KeywordSearchStrategy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.