Implementation:0xranx OpenContext Search Types
| Knowledge Sources | |
|---|---|
| Domains | Search, Rust_Core |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Common type definitions for the search module, including chunks, search options, search hits, and search results, provided by the Rust core library.
Description
The types module in crates/opencontext-core/src/search/types.rs defines the shared data structures used across the entire search pipeline. It contains Chunk (an embedded document fragment with its vector), TextChunk (a pre-embedding text fragment), SearchOptions (query parameters), SearchHit (a single search result), and SearchResults (the aggregate response). These types use serde for JSON serialization and are consumed by both the Rust indexer and the Node.js NAPI layer.
Usage
Import these types when building search-related Rust modules in the opencontext-core crate, or when the NAPI binding layer needs to understand the shape of data returned to Node.js.
Code Reference
Source Location
- Repository: 0xranx_OpenContext
- File: crates/opencontext-core/src/search/types.rs
- Lines: 1-235
Signature
pub struct Chunk {
pub id: String,
pub file_path: String,
pub content: String,
pub heading_path: String,
pub section_title: Option<String>,
pub doc_type: Option<String>,
pub entry_id: Option<String>,
pub entry_date: Option<String>,
pub entry_created_at: Option<String>,
pub idea_box: Option<String>,
pub chunk_index: usize,
pub vector: Vec<f32>,
}
pub struct TextChunk {
pub content: String,
pub heading_path: String,
pub start_line: usize,
pub end_line: usize,
}
pub enum SearchMode { Vector, Keyword, Hybrid }
pub enum AggregateBy { Content, Doc, Folder }
pub enum MatchType { Vector, Keyword, Hybrid }
pub struct SearchOptions {
pub query: String,
pub limit: Option<usize>,
pub mode: Option<SearchMode>,
pub aggregate_by: Option<AggregateBy>,
pub doc_type: Option<String>,
}
pub struct SearchHit {
pub file_path: String,
pub display_name: String,
pub content: String,
pub heading_path: Option<String>,
pub section_title: Option<String>,
pub line_start: Option<usize>,
pub line_end: Option<usize>,
pub score: f32,
pub matched_by: MatchType,
pub hit_count: Option<usize>,
pub doc_count: Option<usize>,
pub folder_path: Option<String>,
pub aggregate_type: Option<String>,
pub doc_type: Option<String>,
pub entry_id: Option<String>,
pub entry_date: Option<String>,
pub entry_created_at: Option<String>,
pub idea_box: Option<String>,
}
pub struct SearchResults {
pub query: String,
pub results: Vec<SearchHit>,
pub count: usize,
pub mode: Option<String>,
pub aggregate_by: Option<String>,
pub index_missing: Option<bool>,
pub error: Option<String>,
}
Import
use opencontext_core::search::types::{Chunk, TextChunk, SearchMode, SearchOptions, SearchHit, SearchResults};
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| query | String | Yes | The search query text |
| limit | Option<usize> | No | Max results (default 10) |
| mode | Option<SearchMode> | No | Vector, Keyword, or Hybrid (default Hybrid) |
| aggregate_by | Option<AggregateBy> | No | Content, Doc, or Folder (default Doc) |
| doc_type | Option<String> | No | Filter by "doc" or "idea" |
Outputs
| Name | Type | Description |
|---|---|---|
| SearchResults | struct | Complete search response with hits, count, mode info |
| SearchHit | struct | Individual result with score, match type, and metadata |
| Chunk | struct | Embedded text chunk with vector for indexing |
Usage Examples
Creating Search Options
use opencontext_core::search::types::{SearchOptions, SearchMode, AggregateBy};
let opts = SearchOptions {
query: "how to train models".to_string(),
limit: Some(20),
mode: Some(SearchMode::Hybrid),
aggregate_by: Some(AggregateBy::Doc),
doc_type: None,
};
// Access resolved defaults
assert_eq!(opts.limit(), 20);
assert_eq!(opts.mode(), SearchMode::Hybrid);
Building Empty/Error Results
use opencontext_core::search::types::SearchResults;
// Empty result set
let empty = SearchResults::empty("query".to_string());
// Error result
let errored = SearchResults::with_error("query".to_string(), "API key missing".to_string());
// Index not built indicator
let not_built = SearchResults::index_not_built("query".to_string());
assert_eq!(not_built.index_missing, Some(true));
Related Pages
- Principle:0xranx_OpenContext_Hybrid_Search
- Principle:0xranx_OpenContext_Index_Build
- Environment:0xranx_OpenContext_Rust_Toolchain
</content> </invoke>