Skip to main content

sonic/executor/
list.rs

1// Sonic
2//
3// Fast, lightweight and schema-less search backend
4// Copyright: 2022, Troy Kohler <troy.kohler@zalando.de>
5// Copyright: 2026, Rémi Bardon <remi@remibardon.name>
6// License: Mozilla Public License v2.0 (MPL v2.0)
7
8use crate::query::{QuerySearchID, QuerySearchLimit, QuerySearchOffset};
9use crate::store::StoreItem;
10use crate::store::fst::StoreFSTActionBuilder;
11
12impl super::Executor {
13    pub fn list(
14        &self,
15        item: StoreItem,
16        _event_id: QuerySearchID,
17        limit: QuerySearchLimit,
18        offset: QuerySearchOffset,
19    ) -> Result<Vec<String>, ()> {
20        if let StoreItem(collection, Some(bucket), None) = item {
21            // Important: acquire graph access read lock, and reference it in context. This \
22            //   prevents the graph from being erased while using it in this block.
23            let _fst_read_guard = self.fst_pool.lock_read_access();
24
25            if let Ok(fst_store) = self.fst_pool.acquire(collection, bucket) {
26                let fst_action = StoreFSTActionBuilder::access(fst_store);
27
28                tracing::debug!("running list");
29
30                return fst_action.list_words(limit as usize, offset as usize);
31            }
32        }
33
34        Err(())
35    }
36}