### Union Query Example Source: https://docs.rs/seekstorm/latest/seekstorm/search/trait.Search.html Shows how to perform a union (OR) query using QueryType::Union. This is often the default behavior. ```rust use seekstorm::search::QueryType; let query_type=QueryType::Union; let query_string="red apple".to_string(); ``` -------------------------------- ### GET /index/synonyms Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Retrieves the current list of synonyms configured for the index. ```APIDOC ## GET /index/synonyms ### Description Get synonyms from index. ### Method GET ### Endpoint /index/synonyms ### Response #### Success Response (200) - **synonyms** (Vec) - A list of configured synonyms. ``` -------------------------------- ### Project Setup and Async Runtime Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Instructions on how to add the SeekStorm crate to your project and set up an asynchronous Rust runtime using Tokio. ```APIDOC ## Project Setup ### Add required crates to your project ```rust cargo add seekstorm cargo add tokio cargo add serde_json ``` ### Use an asynchronous Rust runtime ```rust use std::error::Error; #[tokio::main] async fn main() -> Result<(), Box> { // your SeekStorm code here Ok(()) } ``` ``` -------------------------------- ### Creating a SchemaField Instance Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.SchemaField.html Example of how to create a new SchemaField instance with specified properties. Ensure FieldType is correctly imported. ```rust use seekstorm::index::{SchemaField, FieldType}; let schema_field = SchemaField::new("title".to_string(), true, true, FieldType::String16, false, false, 1.0, false, false); ``` -------------------------------- ### Vec with Custom Allocator Example Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Demonstrates creating a Vec with a specific allocator and its behavior with different element types. Shows initial capacity and length, and how push operations affect capacity and length. ```rust #![feature(allocator_api)] use std::alloc.System; let mut vec = Vec::with_capacity_in(10, System); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); // These are all done without reallocating... for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); // ...but this may make the vector reallocate vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); // A vector of a zero-sized type will always over-allocate, since no // allocation is necessary let vec_units = Vec::<(), System>::with_capacity_in(10, System); assert_eq!(vec_units.capacity(), usize::MAX); ``` -------------------------------- ### Get first entry Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Retrieves the first key-value pair in the map. ```rust pub fn first(&self) -> Option<(&K, &V)> ``` -------------------------------- ### GET /version Source: https://docs.rs/seekstorm/latest/seekstorm/index/fn.version.html Retrieves the current version string of the SeekStorm search library. ```APIDOC ## GET /version ### Description Returns the version of the SeekStorm search library as a static string. ### Method GET ### Endpoint /version ### Response #### Success Response (200) - **version** (string) - The version identifier of the library. ``` -------------------------------- ### Configure N-gram Indexing Strategies Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.IndexMetaObject.html Examples of bitwise OR flags for configuring n-gram indexing based on the trade-off between index size and query latency. ```rust NgramSet::SingleTerm as u8 ``` ```rust NgramSet::SingleTerm as u8 | NgramSet::NgramFF as u8 | NgramSet::NgramFFF ``` ```rust NgramSet::SingleTerm as u8 | NgramSet::NgramFF as u8 | NgramSet::NgramFR as u8 | NgramSet::NgramRF | NgramSet::NgramFFF ``` -------------------------------- ### Intersection Query Example Source: https://docs.rs/seekstorm/latest/seekstorm/search/trait.Search.html Demonstrates how to perform an intersection (AND) query using the QueryType::Intersection. The query string does not require explicit '+' operators. ```rust use seekstorm::search::QueryType; let query_type=QueryType::Intersection; let query_string="red apple".to_string(); ``` -------------------------------- ### Phrase Query Example Source: https://docs.rs/seekstorm/latest/seekstorm/search/trait.Search.html Illustrates how to search for an exact phrase using double quotes in the query string and setting the query type to QueryType::Phrase. ```rust use seekstorm::search::QueryType; let query_type=QueryType::Phrase; let query_string="red apple".to_string(); ``` -------------------------------- ### IndexMap Mutable Indexing by Key Panic Example Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Illustrates a panic scenario when attempting to use index syntax with a key that does not exist in the map. ```rust use indexmap::IndexMap; let mut map = IndexMap::new(); map.insert("foo", 1); map["bar"] = 1; // panics! ``` -------------------------------- ### Check Vector Capacity Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Examples of checking the capacity of a standard vector and a vector containing zero-sized elements. ```rust let mut vec: Vec = Vec::with_capacity(10); vec.push(42); assert!(vec.capacity() >= 10); ``` ```rust #[derive(Clone)] struct ZeroSized; fn main() { assert_eq!(std::mem::size_of::(), 0); let v = vec![ZeroSized; 0]; assert_eq!(v.capacity(), usize::MAX); } ``` -------------------------------- ### IndexMap Mutable Indexing by Index Panic Example Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Demonstrates a panic when trying to access an index that is out of bounds for the IndexMap. ```rust use indexmap::IndexMap; let mut map = IndexMap::new(); map.insert("foo", 1); map[10] = 1; // panics! ``` -------------------------------- ### Get substring from a string Source: https://docs.rs/seekstorm/latest/seekstorm/utils/fn.substring.html Returns a substring of the given string, starting at the specified index and with the specified length. Ensure start and length are within bounds to avoid panics. ```rust pub fn substring(source: &str, start: usize, length: usize) -> String ``` -------------------------------- ### GET /get_iterator Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Retrieves an iterator for documents in the index. ```APIDOC ## GET /get_iterator ### Description Provides an iterator to read documents from the index. ### Method GET ### Parameters #### Query Parameters - **docid** (Option) - Optional - Starting document ID. - **skip** (usize) - Required - Number of documents to skip. - **take** (isize) - Required - Number of documents to take. - **include_deleted** (bool) - Required - Whether to include deleted documents. - **include_document** (bool) - Required - Whether to include document content. - **fields** (Vec) - Required - Fields to retrieve. ``` -------------------------------- ### fn weak_count Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Gets the number of Weak pointers to the allocation. ```APIDOC ## fn weak_count ### Description Gets the number of `Weak` pointers to this allocation. ### Parameters - **this** (&Arc) - Required - The Arc instance to check. ``` -------------------------------- ### Create a SeekStorm Index Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Initializes a new index with a specified schema and configuration object. ```rust use std::path::Path; use seekstorm::index::{IndexMetaObject, SimilarityType,TokenizerType,StopwordType,FrequentwordType,AccessType,StemmerType,NgramSet,DocumentCompression,create_index}; let index_path=Path::new("C:/index/"); let schema_json = r#" [{"field":"title","field_type":"Text","stored":false,"indexed":false}, {"field":"body","field_type":"Text","stored":true,"indexed":true}, {"field":"url","field_type":"Text","stored":true,"indexed":false}, {"field":"town","field_type":"String15","stored":false,"indexed":false,"facet":true}]"#; let schema=serde_json::from_str(schema_json).unwrap(); let meta = IndexMetaObject { id: 0, name: "test_index".into(), similarity: SimilarityType::Bm25f, tokenizer: TokenizerType::AsciiAlphabetic, stemmer: StemmerType::None, stop_words: StopwordType::None, frequent_words: FrequentwordType::English, ngram_indexing: NgramSet::NgramFF as u8, document_compression: DocumentCompression::Snappy, access_type: AccessType::Mmap, spelling_correction: None, query_completion: None, }; let serialize_schema=true; let segment_number_bits1=11; let index_arc=create_index(index_path,meta,&schema,&Vec::new(),segment_number_bits1,false,None).await.unwrap(); ``` -------------------------------- ### Get Immutable Raw Pointer to Vector Buffer Source: https://docs.rs/seekstorm/latest/seekstorm/search/type.Point.html Use `as_ptr` to get a raw pointer to the vector's buffer. Ensure the vector outlives the pointer and do not mutate the memory through this pointer. This is safe to mix with other `as_ptr`, `as_mut_ptr`, and `as_non_null` calls due to aliasing guarantees. ```rust let x = vec![1, 2, 4]; let x_ptr = x.as_ptr(); unsafe { for i in 0..x.len() { assert_eq!(*x_ptr.add(i), 1 << i); } } ``` ```rust unsafe { let mut v = vec![0, 1, 2]; let ptr1 = v.as_ptr(); let _ = ptr1.read(); let ptr2 = v.as_mut_ptr().offset(2); ptr2.write(2); // Notably, the write to `ptr2` did *not* invalidate `ptr1` // because it mutated a different element: let _ = ptr1.read(); } ``` -------------------------------- ### Collect Iterator into VecDeque and Convert to Vec Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Demonstrates collecting an iterator into a VecDeque and then converting it into a Vec. The first example shows an O(1) conversion, while the second involves data rearrangement. ```rust use std::collections::VecDeque; // This one is *O*(1). let deque: VecDeque<_> = (1..5).collect(); let ptr = deque.as_slices().0.as_ptr(); let vec = Vec::from(deque); assert_eq!(vec, [1, 2, 3, 4]); assert_eq!(vec.as_ptr(), ptr); ``` ```rust // This one needs data rearranging. let mut deque: VecDeque<_> = (1..5).collect(); deque.push_front(9); deque.push_front(8); let ptr = deque.as_slices().1.as_ptr(); let vec = Vec::from(deque); assert_eq!(vec, [8, 9, 1, 2, 3, 4]); assert_eq!(vec.as_ptr(), ptr); ``` -------------------------------- ### fn strong_count Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Gets the number of strong (Arc) pointers to the allocation. ```APIDOC ## fn strong_count ### Description Gets the number of strong (`Arc`) pointers to this allocation. ### Parameters - **this** (&Arc) - Required - The Arc instance to check. ``` -------------------------------- ### async fn open_index Source: https://docs.rs/seekstorm/latest/seekstorm/index/fn.open_index.html Loads a search index from the specified path into RAM or MMAP. ```APIDOC ## open_index ### Description Loads the index from disk into RAM or MMAP. ### Method Async Function ### Parameters #### Path Parameters - **index_path** (&Path) - Required - The file system path to the index. - **mute** (bool) - Required - If true, prevents emitting status messages (useful for interprocess communication). ### Response - **Result** - Returns an IndexArc on success, or a String containing an error message on failure. ``` -------------------------------- ### POST /seekstorm/index/create Source: https://docs.rs/seekstorm/latest/seekstorm/index/fn.create_index.html Creates an index in RAM using the provided configuration. This function is part of the seekstorm::index module. ```APIDOC ## POST /seekstorm/index/create ### Description Creates an index in RAM. Inner data structures for create index and open_index. ### Method POST ### Endpoint /seekstorm/index/create ### Parameters #### Request Body - **index_path** (Path) - Required - The path where the index will be created. - **meta** (IndexMetaObject) - Required - The metadata object for the index. - **schema** (Vec) - Required - The schema definition for the index. - **synonyms** (Vec) - Required - A vector of synonyms to be used in the index. - **segment_number_bits1** (usize) - Required - The number of bits to use for index segments (e.g., 11 bits for 2048 segments). - **mute** (bool) - Required - If true, prevents emitting status messages. - **force_shard_number** (Option) - Optional - Manually set the number of shards. If None, it defaults to the number of physical processor cores. Options include 'small' (slower indexing, higher latency, slightly higher throughput, faster realtime search, lower RAM consumption) and 'large' (faster indexing, lower latency, slightly lower throughput, slower realtime search, higher RAM consumption). ### Request Example ```json { "index_path": "/path/to/index", "meta": { ... }, "schema": [ ... ], "synonyms": [ ... ], "segment_number_bits1": 11, "mute": false, "force_shard_number": null } ``` ### Response #### Success Response (200) - **IndexArc** - A reference-counted pointer to the created index. #### Response Example ```json { "index": "" } ``` ``` -------------------------------- ### RangeI8 Struct Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI8.html Defines an I8 range filter with start and end points. ```APIDOC ## Struct RangeI8 ### Description Represents an 8-bit integer range filter. ### Fields - **start** (i8) - The starting value of the range. - **end** (i8) - The ending value of the range. ### Example ```rust struct RangeI8 { start: i8, end: i8, } ``` ``` -------------------------------- ### RangeI32 Struct Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI32.html Represents an i32 range filter with start and end values. ```APIDOC ## Struct RangeI32 ### Description I32 range filter ### Fields - **start** (i32) - range start - **end** (i32) - range end ### Request Example ```json { "start": 0, "end": 100 } ``` ### Response #### Success Response (200) - **start** (i32) - The starting value of the range. - **end** (i32) - The ending value of the range. #### Response Example ```json { "start": 0, "end": 100 } ``` ``` -------------------------------- ### Use an Asynchronous Rust Runtime Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Set up an asynchronous main function using tokio to run SeekStorm operations. ```rust use std::error::Error; #[tokio::main] async fn main() -> Result<(), Box> { // your SeekStorm code here Ok(()) } ``` -------------------------------- ### Convert Slice Back to Array using Arc Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html This example demonstrates converting a raw pointer of a slice back into an `Arc` of a fixed-size array using `Arc::from_raw_in` and `cast`. This requires the `allocator_api` feature and is a nightly-only experimental API. ```rust #![feature(allocator_api)] use std::sync::Arc; use std::alloc::System; let x: Arc<[u32], _> = Arc::new_in([1, 2, 3], System); let x_ptr: *const [u32] = Arc::into_raw_with_allocator(x).0; unsafe { let x: Arc<[u32; 3], _> = Arc::from_raw_in(x_ptr.cast::<[u32; 3]>(), System); assert_eq!(&*x, &[1, 2, 3]); } ``` -------------------------------- ### Implement CloneToUninit (Nightly) Source: https://docs.rs/seekstorm/latest/seekstorm/index/enum.DistanceUnit.html An experimental nightly-only API for copying data to an uninitialized memory location. Use with caution as it requires careful memory management. ```rust impl CloneToUninit for T where T: Clone, ``` -------------------------------- ### RangeI16 Struct Definition Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI16.html Defines the RangeI16 struct with start and end fields. ```APIDOC ## Struct RangeI16 ### Summary ```rust pub struct RangeI16 { pub start: i16, pub end: i16, } ``` ### Description I16 range filter ### Fields - **start** (i16) - range start - **end** (i16) - range end ``` -------------------------------- ### Try Creating Arc with Allocator API Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Demonstrates using `Arc::try_new` with the `allocator_api` feature to construct an `Arc` and handle potential allocation errors. ```rust #![feature(allocator_api)] use std::sync::Arc; let five = Arc::try_new(5)?; ``` -------------------------------- ### Get IndexMap entry by index Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Retrieves entries or references by their numeric index. ```rust pub fn get_index(&self, index: usize) -> Option<(&K, &V)> ``` ```rust pub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)> ``` ```rust pub fn get_index_entry( &mut self, index: usize, ) -> Option> ``` -------------------------------- ### Initialize Vec with Custom Allocator Source: https://docs.rs/seekstorm/latest/seekstorm/search/type.Point.html Demonstrates creating a vector with a specific allocator and handling zero-sized types. ```rust #![feature(allocator_api)] use std::alloc::System; let mut vec = Vec::with_capacity_in(10, System); // The vector contains no items, even though it has capacity for more assert_eq!(vec.len(), 0); assert!(vec.capacity() >= 10); // These are all done without reallocating... for i in 0..10 { vec.push(i); } assert_eq!(vec.len(), 10); assert!(vec.capacity() >= 10); // ...but this may make the vector reallocate vec.push(11); assert_eq!(vec.len(), 11); assert!(vec.capacity() >= 11); // A vector of a zero-sized type will always over-allocate, since no // allocation is necessary let vec_units = Vec::<(), System>::with_capacity_in(10, System); assert_eq!(vec_units.capacity(), usize::MAX); ``` -------------------------------- ### GET /index/facet-value Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Retrieves a specific facet value for a given document ID. ```APIDOC ## GET /index/facet-value ### Description Returns value from facet field for a doc_id even if schema stored=false. Facet fields are more compact and faster to access than standard document fields. ### Method GET ### Endpoint /index/facet-value ### Parameters #### Query Parameters - **field** (str) - Required - The facet field name. - **doc_id** (usize) - Required - The document ID. ``` -------------------------------- ### Get Index Shard Count Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Returns the number of shards within the index. ```rust pub async fn shard_count(&self) -> usize ``` -------------------------------- ### Basic Arc Creation Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Demonstrates the fundamental creation of an `Arc` with a value. ```rust use std::sync::Arc; let five = Arc::new(5); ``` -------------------------------- ### Get Indexed Document Count Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Returns the total number of documents that have been indexed. ```rust pub async fn indexed_doc_count(&self) -> usize ``` -------------------------------- ### Vec with Custom Allocator Source: https://docs.rs/seekstorm/latest/seekstorm/search/type.Point.html Demonstrates creating a Vec with a custom allocator and converting it back to parts. ```rust #![feature(allocator_api)] use std::alloc.System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### Try Creating Uninitialized Arc with Allocator API Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Shows how to use `Arc::try_new_uninit` with the `allocator_api` feature for creating an `Arc` with uninitialized contents, handling allocation errors. ```rust #![feature(allocator_api)] use std::sync::Arc; let mut five = Arc::::try_new_uninit()?; // Deferred initialization: Arc::get_mut(&mut five).unwrap().write(5); let five = unsafe { five.assume_init() }; assert_eq!(*five, 5); ``` -------------------------------- ### clone_to_uninit Source: https://docs.rs/seekstorm/latest/seekstorm/search/enum.Ranges.html This is a nightly-only experimental API. It performs copy-assignment from self to dest. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description This is a nightly-only experimental API. It performs copy-assignment from `self` to `dest`. ### Method unsafe fn ### Endpoint N/A (Method within a trait implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### RangeU8 Struct Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeU8.html Defines a range filter for u8 values with start and end points. ```APIDOC ## Struct RangeU8 ### Description U8 range filter ### Fields - **start** (u8) - The start of the range. - **end** (u8) - The end of the range. ``` -------------------------------- ### Constants and Configuration Source: https://docs.rs/seekstorm/latest/seekstorm/index/index.html Lists important constants and configuration parameters for the Seekstorm library. ```APIDOC ## Constants and Configuration This section outlines key constants that define index format versions and limits. ### Constants - **INDEX_FORMAT_VERSION_MAJOR**: Indicates an incompatible index format change. - **INDEX_FORMAT_VERSION_MINOR**: Indicates a backward-compatible format change. - **MAX_POSITIONS_PER_TERM**: Sets the maximum processed positions per term per document (default: 65,536). - **ROARING_BLOCK_SIZE**: Defines the maximum number of documents per block. ``` -------------------------------- ### RangeI64 Struct Definition Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI64.html Defines the RangeI64 struct with its public fields 'start' and 'end'. ```APIDOC ## Struct RangeI64 ### Description I64 range filter ### Fields - **start** (i64) - range start - **end** (i64) - range end ### Example ```rust pub struct RangeI64 { pub start: i64, pub end: i64, } ``` ``` -------------------------------- ### Index Management Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Demonstrates how to create and open a SeekStorm index, including schema definition and metadata configuration. ```APIDOC ## Create Index ### Description Creates a new SeekStorm index at the specified path with a given schema and metadata. ### Method `create_index` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters - **index_path** (Path) - Required - The file system path where the index will be created. - **meta** (IndexMetaObject) - Required - Metadata for the index, including name, similarity type, tokenizer, etc. - **schema** (serde_json::Value) - Required - The schema definition for the index fields. - **custom_stop_words** (Vec) - Optional - A list of custom stop words. - **segment_number_bits** (u8) - Required - Number of bits for segment numbering. - **use_mmap** (bool) - Required - Whether to use memory-mapped files for the index. - **spelling_correction** (Option) - Optional - Whether to enable spelling correction. ### Request Example ```rust use std::path::Path; use std::sync::{Arc, RwLock}; use seekstorm::index::{IndexMetaObject, SimilarityType,TokenizerType,StopwordType,FrequentwordType,AccessType,StemmerType,NgramSet,DocumentCompression,create_index}; let index_path=Path::new("C:/index/"); let schema_json = r#"[{"field":"title","field_type":"Text","stored":false,"indexed":false}, {"field":"body","field_type":"Text","stored":true,"indexed":true}, {"field":"url","field_type":"Text","stored":false,"indexed":false}]"#; let schema=serde_json::from_str(schema_json).unwrap(); let meta = IndexMetaObject { id: 0, name: "test_index".into(), similarity: SimilarityType::Bm25f, tokenizer: TokenizerType::AsciiAlphabetic, stemmer: StemmerType::None, stop_words: StopwordType::None, frequent_words: FrequentwordType::English, ngram_indexing: NgramSet::NgramFF as u8, document_compression: DocumentCompression::Snappy, access_type: AccessType::Mmap, spelling_correction: None, query_completion: None, }; let segment_number_bits1=11; let serialize_schema=true; let index_arc=create_index(index_path,meta,&schema,&Vec::new(),segment_number_bits1,false,None).await.unwrap(); ``` ## Open Index ### Description Opens an existing SeekStorm index from the specified path. ### Method `open_index` ### Endpoint N/A (Library function) ### Parameters #### Path Parameters - **index_path** (Path) - Required - The file system path to the existing index. - **use_mmap** (bool) - Required - Whether to use memory-mapped files when opening the index. ### Request Example ```rust use seekstorm::index::open_index; use std::path::Path; let index_path=Path::new("C:/index/"); let index_arc=open_index(index_path,false).await.unwrap(); ``` ``` -------------------------------- ### Get disjoint indices from IndexMap Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Retrieves multiple mutable references by unique indices. ```rust pub fn get_disjoint_indices_mut( &mut self, indices: [usize; N], ) -> Result<[(&K, &mut V); N], GetDisjointMutError> ``` ```rust let mut map = indexmap::IndexMap::from([(1, 'a'), (3, 'b'), (2, 'c')]); assert_eq!(map.get_disjoint_indices_mut([2, 0]), Ok([(&2, &mut 'c'), (&1, &mut 'a')])); ``` -------------------------------- ### Vec FromIterator Implementation Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Demonstrates how to collect an iterator into a Vec. It highlights the O(1) efficiency in certain scenarios and the potential for data rearrangement in others. Also discusses allocation strategies and memory management considerations. ```APIDOC ## FromIterator for Vec Available on **non-`no_global_oom_handling`** only. Collects an iterator into a Vec, commonly called via `Iterator::collect()` ### Allocation behavior In general `Vec` does not guarantee any particular growth or allocation strategy. That also applies to this trait impl. **Note:** This section covers implementation details and is therefore exempt from stability guarantees. Vec may use any or none of the following strategies, depending on the supplied iterator: * preallocate based on `Iterator::size_hint()` * and panic if the number of items is outside the provided lower/upper bounds * use an amortized growth strategy similar to `pushing` one item at a time * perform the iteration in-place on the original allocation backing the iterator The last case warrants some attention. It is an optimization that in many cases reduces peak memory consumption and improves cache locality. But when big, short-lived allocations are created, only a small fraction of their items get collected, no further use is made of the spare capacity and the resulting `Vec` is moved into a longer-lived structure, then this can lead to the large allocations having their lifetimes unnecessarily extended which can result in increased memory footprint. In cases where this is an issue, the excess capacity can be discarded with `Vec::shrink_to()`, `Vec::shrink_to_fit()` or by collecting into `Box<[T]>` instead, which additionally reduces the size of the long-lived struct. ```rust static LONG_LIVED: Mutex>> = Mutex::new(Vec::new()); for i in 0..10 { let big_temporary: Vec = (0..1024).collect(); // discard most items let mut result: Vec<_> = big_temporary.into_iter().filter(|i| i % 100 == 0).collect(); // without this a lot of unused capacity might be moved into the global result.shrink_to_fit(); LONG_LIVED.lock().unwrap().push(result); } ``` ### fn from_iter(iter: I) -> Vec where I: IntoIterator, Creates a value from an iterator. Read more ``` -------------------------------- ### GET /index/file Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Retrieves the raw file content associated with a specific document ID. ```APIDOC ## GET /index/file ### Description Fetches the file content as a byte vector for a specified document ID. ### Method GET ### Parameters #### Query Parameters - **doc_id** (usize) - Required - The document ID to load the file from. ### Response #### Success Response (200) - **content** (Vec) - The file content as a byte vector. ``` -------------------------------- ### IndexMap Lifecycle and Metadata Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Methods for map initialization, capacity management, and size queries. ```APIDOC ## with_capacity_and_hasher ### Description Create a new map with capacity for n key-value pairs. ## capacity ### Description Return the number of elements the map can hold without reallocating. ## len ### Description Return the number of key-value pairs in the map. ## is_empty ### Description Returns true if the map contains no elements. ``` -------------------------------- ### Get Facet Count Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Returns the total number of facets defined in the index schema. ```rust pub fn facets_count(&self) -> usize ``` -------------------------------- ### Vec::with_capacity_in Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Constructs a new, empty Vec with a specified initial capacity and allocator. This is a nightly-only experimental API. ```APIDOC ## POST /vec/with_capacity_in ### Description Constructs a new, empty `Vec` with at least the specified capacity and the provided allocator. The vector will be able to hold at least `capacity` elements without reallocating. This method is allowed to allocate for more elements than `capacity`. If `capacity` is zero, the vector will not allocate. The returned vector has the minimum _capacity_ specified, but will have a zero _length_. For `Vec` where `T` is a zero-sized type, there will be no allocation and the capacity will always be `usize::MAX`. ### Method POST ### Endpoint /vec/with_capacity_in ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **capacity** (usize) - Required - The minimum initial capacity for the vector. - **alloc** (A) - Required - The allocator to use for the vector. ### Request Example ```json { "capacity": 10, "alloc": "System" } ``` ### Response #### Success Response (200) - **Vec** - A new, empty vector with the specified capacity and allocator. #### Response Example ```json { "length": 0, "capacity": 10 } ``` ### Panics Panics if the new capacity exceeds `isize::MAX` _bytes_. ``` -------------------------------- ### seekstorm::utils::substring Source: https://docs.rs/seekstorm/latest/seekstorm/utils/fn.substring.html Extracts a substring from a given string based on start index and length. ```APIDOC ## Function substring ### Description Returns a substring of the given string, starting at the specified index and with the specified length. ### Signature ```rust pub fn substring(source: &str, start: usize, length: usize) -> String ``` ### Parameters #### Path Parameters - **source** (string) - The original string from which to extract the substring. - **start** (usize) - The starting index (0-based) of the substring. - **length** (usize) - The desired length of the substring. ### Returns - **String** - The extracted substring. ``` -------------------------------- ### Get range of IndexMap Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Retrieves a slice of key-value pairs within a specified index range. ```rust pub fn get_range(&self, range: R) -> Option<&Slice> where R: RangeBounds, ``` ```rust pub fn get_range_mut(&mut self, range: R) -> Option<&mut Slice> where R: RangeBounds, ``` -------------------------------- ### GET /index/document Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Retrieves a specific document from the index by its ID, with options for highlighting and field selection. ```APIDOC ## GET /index/document ### Description Retrieves a document for a given document ID from the index store. Supports optional highlighting and specific field filtering. ### Method GET ### Parameters #### Query Parameters - **doc_id** (usize) - Required - The document ID to load. - **include_uncommitted** (bool) - Required - Whether to include documents not yet committed. - **highlighter_option** (Option) - Optional - Configuration for keyword-in-context extraction. - **fields** (HashSet) - Optional - Set of stored fields to return. - **distance_fields** (Vec) - Optional - Fields to calculate distance for. ### Response #### Success Response (200) - **Document** (Object) - The retrieved document object. ``` -------------------------------- ### Get Committed Document Count Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Retrieves the total number of documents that have been successfully committed to the index. ```rust pub async fn committed_doc_count(&self) -> usize ``` -------------------------------- ### Try Creating Zeroed Arc with Allocator API Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.IndexArc.html Illustrates using `Arc::try_new_zeroed` with the `allocator_api` feature to create an `Arc` with zeroed memory, handling allocation errors. ```rust #![feature( allocator_api)] use std::sync::Arc; let zero = Arc::::try_new_zeroed()?; let zero = unsafe { zero.assume_init() }; assert_eq!(*zero, 0); ``` -------------------------------- ### Create Vec from External Memory Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Shows how to initialize a Vec from a raw pointer allocated via the global allocator. ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; fn main() { let layout = Layout::array::(16).expect("overflow cannot happen"); let vec = unsafe { let Some(mem) = NonNull::new(alloc(layout).cast::()) else { return; }; mem.write(1_000_000); Vec::from_parts(mem, 1, 16) }; assert_eq!(vec, &[1_000_000]); assert_eq!(vec.capacity(), 16); } ``` -------------------------------- ### Get Mutable Raw Pointer to Vector Buffer Source: https://docs.rs/seekstorm/latest/seekstorm/search/type.Point.html Use `as_mut_ptr` to get a mutable raw pointer to the vector's buffer. The caller must ensure the vector outlives the pointer. This pointer can be used to initialize elements before setting the vector's length. It also guarantees that the pointer may be passed to `dealloc` if `T` is not zero-sized and capacity is nonzero. ```rust // Allocate vector big enough for 4 elements. let size = 4; let mut x: Vec = Vec::with_capacity(size); let x_ptr = x.as_mut_ptr(); // Initialize elements via raw pointer writes, then set length. unsafe { for i in 0..size { *x_ptr.add(i) = i as i32; } x.set_len(size); } assert_eq!(&*x, &[0, 1, 2, 3]); ``` ```rust unsafe { let mut v = vec![0]; let ptr1 = v.as_mut_ptr(); ptr1.write(1); let ptr2 = v.as_mut_ptr(); ptr2.write(2); // Notably, the write to `ptr2` did *not* invalidate `ptr1`: ptr1.write(3); } ``` ```rust use std::mem::{ManuallyDrop, MaybeUninit}; let mut v = ManuallyDrop::new(vec![0, 1, 2]); let ptr = v.as_mut_ptr(); let capacity = v.capacity(); let slice_ptr: *mut [MaybeUninit] = std::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity); drop(unsafe { Box::from_raw(slice_ptr) }); ``` -------------------------------- ### Display search results with highlighting Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Process and display search results, including highlighting terms within document fields. Requires importing `Highlight` and `highlighter` from `seekstorm::highlighter` and `HashSet` from `std::collections`. ```rust use seekstorm::highlighter::{Highlight, highlighter}; use std::collections::HashSet; let highlights:Vec= vec![ Highlight { field: "body".to_string(), name:String::new(), fragment_number: 2, fragment_size: 160, highlight_markup: true, ..Default::default() }, ]; let highlighter=Some(highlighter(&index_arc,highlights, result_object.query_terms).await); let return_fields_filter= HashSet::new(); let distance_fields=Vec::new(); let index=index_arc.read().await; for result in result_object.results.iter() { let doc=index.get_document(result.doc_id,false,&highlighter,&return_fields_filter,&distance_fields).await.unwrap(); println!("result {} rank {} body field {:?}" , result.doc_id,result.score, doc.get("body")); } println!("result counts {} {} {}",result_object.results.len(), result_object.result_count, result_object.result_count_total); ``` -------------------------------- ### Define RangeI64 struct Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI64.html The structure used for I64 range filtering, containing start and end bounds. ```rust pub struct RangeI64 { pub start: i64, pub end: i64, } ``` -------------------------------- ### Define RangeI16 struct Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI16.html The structure used for I16 range filtering, containing start and end fields. ```rust pub struct RangeI16 { pub start: i16, pub end: i16, } ``` -------------------------------- ### Create IndexMap from array Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.Document.html Demonstrates creating an IndexMap from an array of tuples. ```rust use indexmap::IndexMap; let map1 = IndexMap::from([(1, 2), (3, 4)]); let map2: IndexMap<_, _> = [(1, 2), (3, 4)].into(); assert_eq!(map1, map2); ``` -------------------------------- ### Get raw pointer from Arc Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.ShardArc.html Retrieves a raw pointer to the data without affecting reference counts. ```rust use std::sync::Arc; let x = Arc::new("hello".to_owned()); let y = Arc::clone(&x); let x_ptr = Arc::as_ptr(&x); assert_eq!(x_ptr, Arc::as_ptr(&y)); assert_eq!(unsafe { &*x_ptr }, "hello"); ``` -------------------------------- ### impl CloneToUninit for T Source: https://docs.rs/seekstorm/latest/seekstorm/index/enum.TokenizerType.html Nightly-only experimental API for performing copy-assignment from `self` to a mutable pointer `dest`. ```APIDOC ## PUT /api/users/{id} ### Description Updates an existing user by their ID. ### Method PUT ### Endpoint /api/users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the user to update. #### Request Body - **name** (string) - Optional - The updated name of the user. - **email** (string) - Optional - The updated email address of the user. ### Request Example ```json { "name": "John Doe Updated", "email": "john.doe.updated@example.com" } ``` ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the user. - **name** (string) - The updated name of the user. - **email** (string) - The updated email address of the user. #### Response Example ```json { "id": 1, "name": "John Doe Updated", "email": "john.doe.updated@example.com" } ``` ``` -------------------------------- ### GET /index/stats Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Retrieves various statistical metrics about the index, including document counts and facet information. ```APIDOC ## GET /index/stats ### Description Provides metadata and counts for the index, such as current document count, shard count, and facet min/max values. ### Method GET ### Response #### Success Response (200) - **indexed_doc_count** (usize) - Total number of indexed documents. - **shard_count** (usize) - Total number of index shards. - **facets_count** (usize) - Number of defined facets. - **index_facets_minmax** (HashMap) - Min/max values for numeric facet fields. ``` -------------------------------- ### Get Index Level Count Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.Index.html Returns the number of index levels, where each level comprises 64K documents. ```rust pub async fn level_count(&self) -> usize ``` -------------------------------- ### Index and Commit Documents Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Adds documents to the index and commits them to disk for persistence. ```rust use seekstorm::index::IndexDocuments; use seekstorm::commit::Commit; use seekstorm::search::{QueryType, ResultType, QueryFacet, FacetFilter}; let documents_json = r#" [{"title":"title1 test","body":"body1","url":"url1","town":"Berlin"}, {"title":"title2","body":"body2 test","url":"url2","town":"Warsaw"}, {"title":"title3 test","body":"body3 test","url":"url3","town":"New York"}]"#; let documents_vec=serde_json::from_str(documents_json).unwrap(); index_arc.index_documents(documents_vec).await; // ### commit documents index_arc.commit().await; ``` -------------------------------- ### Open Index Source: https://docs.rs/seekstorm/latest/seekstorm/index.html Opens an existing SeekStorm index from the specified path. This is an alternative to creating a new index. ```rust use seekstorm::index::open_index; use std::path::Path; let index_path=Path::new("C:/index/"); let index_arc=open_index(index_path,false).await.unwrap(); ``` -------------------------------- ### Retrieve SeekStorm library version Source: https://docs.rs/seekstorm/latest/seekstorm/index/fn.version.html Returns the version of the SeekStorm search library as a static string. ```rust pub fn version() -> &'static str ``` -------------------------------- ### Implement Default for MinMaxFieldJson Source: https://docs.rs/seekstorm/latest/seekstorm/index/struct.MinMaxFieldJson.html Provides a default value for MinMaxFieldJson. Use this when you need a sensible starting point for the struct. ```rust fn default() -> MinMaxFieldJson ``` -------------------------------- ### Deconstruct and Rebuild Vec with Allocator Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Demonstrates using into_parts_with_alloc and from_parts_in to manipulate vector components directly with a specific allocator. ```rust #![feature(allocator_api)] use std::alloc::System; let mut v: Vec = Vec::new_in(System); v.push(-1); v.push(0); v.push(1); let (ptr, len, cap, alloc) = v.into_parts_with_alloc(); let rebuilt = unsafe { // We can now make changes to the components, such as // transmuting the raw pointer to a compatible type. let ptr = ptr.cast::(); Vec::from_parts_in(ptr, len, cap, alloc) }; assert_eq!(rebuilt, [4294967295, 0, 1]); ``` -------------------------------- ### Split vector into initialized and spare parts Source: https://docs.rs/seekstorm/latest/seekstorm/index/type.SynonymItem.html Experimental API to get both the initialized content and the spare capacity as slices. ```rust #![feature(vec_split_at_spare)] let mut v = vec![1, 1, 2]; // Reserve additional space big enough for 10 elements. v.reserve(10); let (init, uninit) = v.split_at_spare_mut(); let sum = init.iter().copied().sum::(); // Fill in the next 4 elements. uninit[0].write(sum); uninit[1].write(sum * 2); uninit[2].write(sum * 3); uninit[3].write(sum * 4); // Mark the 4 elements of the vector as being initialized. unsafe { let len = v.len(); v.set_len(len + 4); } assert_eq!(&v, &[1, 1, 2, 4, 8, 12, 16]); ``` -------------------------------- ### Into Chunks (Nightly) Source: https://docs.rs/seekstorm/latest/seekstorm/search/type.Point.html This nightly-only experimental API consumes a vector and groups its elements into chunks of a specified size `N`. Elements in the remainder are dropped. `N` must be greater than zero. ```rust #![feature(vec_into_chunks)] let vec = vec![0, 1, 2, 3, 4, 5, 6, 7]; assert_eq!(vec.into_chunks::<3>(), [[0, 1, 2], [3, 4, 5]]); ``` ```rust #![feature(vec_into_chunks)] let vec = vec![0, 1, 2, 3]; let chunks: Vec<[u8; 10]> = vec.into_chunks(); assert!(chunks.is_empty()); ``` ```rust #![feature(vec_into_chunks)] let flat = vec![0; 8 * 8 * 8]; let reshaped: Vec<[[[u8; 8]; 8]; 8]> = flat.into_chunks().into_chunks().into_chunks(); assert_eq!(reshaped.len(), 1); ``` -------------------------------- ### Get Schema Name for RangeI8 Source: https://docs.rs/seekstorm/latest/seekstorm/search/struct.RangeI8.html Returns the static name of the schema for RangeI8. This is part of the ToSchema trait implementation. ```rust fn name() -> Cow<'static, str> ```