Full-text search abstraction (Meilisearch, PostgreSQL FTS)
| Tier | infrastructure |
| Role | unclassified (baselined) |
| Path | crates/infrastructure/search |
| Edition | 2021 |
| Targets | infrastructure_search |
| Public items | 73 across 1 module |
| Tests | 30 |
What it is for
Full-text search abstraction for Rust applications.
This crate provides a unified interface for full-text search across different backends (PostgreSQL FTS, Meilisearch, Elasticsearch).
Capabilities
AutocompleteConfig
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct AutocompleteConfig |
AutocompleteConfig :: fn default() -> Self |
FacetResult
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct FacetResult |
FacetValue
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct FacetValue |
FilterOperator
Full-text search abstraction for Rust applications.
| Item |
|---|
pub enum FilterOperator |
InMemorySearchEngine
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct InMemorySearchEngine |
InMemorySearchEngine :: fn new() -> Self |
InMemorySearchEngine :: async fn create_index(& self, config : IndexConfig) -> Result <()> |
InMemorySearchEngine :: async fn delete_index(& self, name : & str) -> Result <()> |
InMemorySearchEngine :: async fn index_exists(& self, name : & str) -> Result <bool> |
InMemorySearchEngine :: async fn index_document(& self, doc : SearchDocument) -> Result <()> |
InMemorySearchEngine :: async fn index_documents(& self, docs : Vec <SearchDocument>) -> Result <()> |
InMemorySearchEngine :: async fn delete_document(& self, index : & str, id : & str) -> Result <()> |
InMemorySearchEngine :: async fn search(& self, query : SearchQuery) -> Result <SearchResults> |
InMemorySearchEngine :: async fn get_document(& self, index : & str, id : & str) -> Result <Option <SearchDocument>> |
IndexConfig
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct IndexConfig |
IndexConfig :: fn new(name : impl Into <String>) -> Self |
IndexConfig :: fn with_primary_key(mut self, key : impl Into <String>) -> Self |
IndexConfig :: fn with_searchable_fields(mut self, fields : Vec <impl Into <String>>) -> Self |
IndexConfig :: fn with_filterable_fields(mut self, fields : Vec <impl Into <String>>) -> Self |
IndexConfig :: fn with_sortable_fields(mut self, fields : Vec <impl Into <String>>) -> Self |
Result
Full-text search abstraction for Rust applications.
| Item |
|---|
pub type Result<T>: std::result::Result <T, SearchError> |
SearchBackend
Full-text search abstraction for Rust applications.
| Item |
|---|
pub enum SearchBackend |
SearchBackend :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
SearchDocument
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct SearchDocument |
SearchDocument :: fn new(id : impl Into <String>, index : impl Into <String>) -> Self |
SearchDocument :: fn with_field(mut self, key : impl Into <String>, value : impl Serialize) -> Self |
SearchDocument :: fn get_field <T : for <'de> Deserialize <'de>>(& self, key : & str) -> Option <T> |
SearchDocument :: fn with_indexed_at(mut self, at : DateTime <Utc>) -> Self |
SearchEngine
Full-text search abstraction for Rust applications.
| Item |
|---|
pub trait SearchEngine |
SearchError
Full-text search abstraction for Rust applications.
| Item |
|---|
pub enum SearchError |
SearchFilter
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct SearchFilter |
SearchFilter :: fn eq(field : impl Into <String>, value : impl Serialize) -> Self |
SearchFilter :: fn ne(field : impl Into <String>, value : impl Serialize) -> Self |
SearchFilter :: fn gt(field : impl Into <String>, value : impl Serialize) -> Self |
SearchFilter :: fn lt(field : impl Into <String>, value : impl Serialize) -> Self |
SearchFilter :: fn in_values(field : impl Into <String>, values : Vec <impl Serialize>) -> Self |
SearchFilter :: fn range(field : impl Into <String>, min : impl Serialize, max : impl Serialize) -> Self |
SearchHit
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct SearchHit |
SearchHit :: fn new(id : impl Into <String>, score : f64) -> Self |
SearchHit :: fn with_field(mut self, key : impl Into <String>, value : impl Serialize) -> Self |
SearchHit :: fn get_field <T : for <'de> Deserialize <'de>>(& self, key : & str) -> Option <T> |
SearchQuery
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct SearchQuery |
SearchQuery :: fn new(query : impl Into <String>, index : impl Into <String>) -> Self |
SearchQuery :: fn with_fields(mut self, fields : Vec <String>) -> Self |
SearchQuery :: fn with_filter(mut self, filter : SearchFilter) -> Self |
SearchQuery :: fn with_sort(mut self, field : impl Into <String>, direction : SortDirection) -> Self |
SearchQuery :: fn with_pagination(mut self, offset : usize, limit : usize) -> Self |
SearchQuery :: fn with_highlight(mut self) -> Self |
SearchQuery :: fn with_facets(mut self, facets : Vec <String>) -> Self |
SearchResults
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct SearchResults |
SearchResults :: fn empty(query : impl Into <String>) -> Self |
SearchResults :: fn is_empty(& self) -> bool |
SearchResults :: fn len(& self) -> usize |
SortDirection
Full-text search abstraction for Rust applications.
| Item |
|---|
pub enum SortDirection |
SortField
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct SortField |
Suggestion
Full-text search abstraction for Rust applications.
| Item |
|---|
pub struct Suggestion |
postgres (other)
PostgreSQL-backed search engine implementation.
| Item |
|---|
fn filter_to_sql(filter : & crate::SearchFilter, param_offset : usize) ->(String, Vec <String>) |
fn text_search_sql(query : & str, fields : & & str, param_offset : usize) ->(String, String) |
fn sort_to_sql(query : & SearchQuery, allowed_fields : & & str) -> String |
fn build_facet(field : & str, values : Vec <(String, u64)>) -> FacetResult |
fn build_hit(id : & str, fields : Vec <(& str, serde_json::Value)>) -> SearchHit |
PostgresSearchEngine
PostgreSQL-backed search engine implementation.
| Item |
|---|
pub struct PostgresSearchEngine |
PostgresSearchEngine :: fn new(pool : PgPool) -> Self |
PostgresSearchEngine :: fn pool(& self) -> & PgPool |
PostgresSearchEngine :: async fn create_index(& self, _config : IndexConfig) -> crate::Result <()> |
PostgresSearchEngine :: async fn delete_index(& self, _name : & str) -> crate::Result <()> |
PostgresSearchEngine :: async fn index_exists(& self, _name : & str) -> crate::Result <bool> |
PostgresSearchEngine :: async fn index_document(& self, _doc : SearchDocument) -> crate::Result <()> |
PostgresSearchEngine :: async fn index_documents(& self, _docs : Vec <SearchDocument>) -> crate::Result <()> |
PostgresSearchEngine :: async fn delete_document(& self, _index : & str, _id : & str) -> crate::Result <()> |
PostgresSearchEngine :: async fn get_document(& self, _index : & str, _id : & str) -> crate::Result <Option <SearchDocument>> |
PostgresSearchEngine :: async fn search(& self, query : SearchQuery) -> crate::Result <SearchResults> |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
infrastructure_search
postgres
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum SearchError | Errors that can occur during search operations. |
pub type Result<T>: std::result::Result <T, SearchError> | Result type for search operations. |
pub enum SearchBackend | Search backend type. |
SearchBackend :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct SearchDocument | A searchable document. |
SearchDocument :: fn new(id : impl Into <String>, index : impl Into <String>) -> Self | Creates a new search document. |
SearchDocument :: fn with_field(mut self, key : impl Into <String>, value : impl Serialize) -> Self | Adds a field to the document. |
SearchDocument :: fn get_field <T : for <'de> Deserialize <'de>>(& self, key : & str) -> Option <T> | Gets a field value. |
SearchDocument :: fn with_indexed_at(mut self, at : DateTime <Utc>) -> Self | Sets the indexed timestamp. |
pub struct SearchQuery | Search query configuration. |
SearchQuery :: fn new(query : impl Into <String>, index : impl Into <String>) -> Self | Creates a new search query. |
SearchQuery :: fn with_fields(mut self, fields : Vec <String>) -> Self | Limits search to specific fields. |
SearchQuery :: fn with_filter(mut self, filter : SearchFilter) -> Self | Adds a filter. |
SearchQuery :: fn with_sort(mut self, field : impl Into <String>, direction : SortDirection) -> Self | Adds sort configuration. |
SearchQuery :: fn with_pagination(mut self, offset : usize, limit : usize) -> Self | Sets pagination. |
SearchQuery :: fn with_highlight(mut self) -> Self | Enables highlighting. |
SearchQuery :: fn with_facets(mut self, facets : Vec <String>) -> Self | Adds facets to compute. |
pub struct SearchFilter | A search filter. |
SearchFilter :: fn eq(field : impl Into <String>, value : impl Serialize) -> Self | Creates an equals filter. |
SearchFilter :: fn ne(field : impl Into <String>, value : impl Serialize) -> Self | Creates a not equals filter. |
SearchFilter :: fn gt(field : impl Into <String>, value : impl Serialize) -> Self | Creates a greater than filter. |
SearchFilter :: fn lt(field : impl Into <String>, value : impl Serialize) -> Self | Creates a less than filter. |
SearchFilter :: fn in_values(field : impl Into <String>, values : Vec <impl Serialize>) -> Self | Creates an "in" filter. |
SearchFilter :: fn range(field : impl Into <String>, min : impl Serialize, max : impl Serialize) -> Self | Creates a range filter. |
pub enum FilterOperator | Filter operators. |
pub enum SortDirection | Sort direction. |
pub struct SortField | Sort field configuration. |
pub struct SearchHit | A search result hit. |
SearchHit :: fn new(id : impl Into <String>, score : f64) -> Self | Creates a new search hit. |
SearchHit :: fn with_field(mut self, key : impl Into <String>, value : impl Serialize) -> Self | Adds a field. |
SearchHit :: fn get_field <T : for <'de> Deserialize <'de>>(& self, key : & str) -> Option <T> | Gets a field value. |
pub struct FacetResult | Facet result. |
pub struct FacetValue | A single facet value with count. |
pub struct SearchResults | Search results. |
SearchResults :: fn empty(query : impl Into <String>) -> Self | Creates empty search results. |
SearchResults :: fn is_empty(& self) -> bool | Returns true if there are no results. |
SearchResults :: fn len(& self) -> usize | Returns the number of hits. |
pub struct IndexConfig | Index configuration. |
IndexConfig :: fn new(name : impl Into <String>) -> Self | Creates a new index configuration. |
IndexConfig :: fn with_primary_key(mut self, key : impl Into <String>) -> Self | Sets the primary key field. |
IndexConfig :: fn with_searchable_fields(mut self, fields : Vec <impl Into <String>>) -> Self | Sets searchable fields. |
IndexConfig :: fn with_filterable_fields(mut self, fields : Vec <impl Into <String>>) -> Self | Sets filterable fields. |
IndexConfig :: fn with_sortable_fields(mut self, fields : Vec <impl Into <String>>) -> Self | Sets sortable fields. |
pub trait SearchEngine | Search engine trait. |
pub struct InMemorySearchEngine | In-memory search engine for testing. |
InMemorySearchEngine :: fn new() -> Self | Creates a new in-memory search engine. |
InMemorySearchEngine :: async fn create_index(& self, config : IndexConfig) -> Result <()> | — |
InMemorySearchEngine :: async fn delete_index(& self, name : & str) -> Result <()> | — |
InMemorySearchEngine :: async fn index_exists(& self, name : & str) -> Result <bool> | — |
InMemorySearchEngine :: async fn index_document(& self, doc : SearchDocument) -> Result <()> | — |
InMemorySearchEngine :: async fn index_documents(& self, docs : Vec <SearchDocument>) -> Result <()> | — |
InMemorySearchEngine :: async fn delete_document(& self, index : & str, id : & str) -> Result <()> | — |
InMemorySearchEngine :: async fn search(& self, query : SearchQuery) -> Result <SearchResults> | — |
InMemorySearchEngine :: async fn get_document(& self, index : & str, id : & str) -> Result <Option <SearchDocument>> | — |
pub struct Suggestion | Suggestion for autocomplete. |
pub struct AutocompleteConfig | Autocomplete configuration. |
AutocompleteConfig :: fn default() -> Self | — |
`postgres`
| Item | What it is |
|---|---|
pub struct PostgresSearchEngine | PostgreSQL search engine |
PostgresSearchEngine :: fn new(pool : PgPool) -> Self | Create a new PostgreSQL search engine. |
PostgresSearchEngine :: fn pool(& self) -> & PgPool | Get a reference to the connection pool. |
PostgresSearchEngine :: async fn create_index(& self, _config : IndexConfig) -> crate::Result <()> | — |
PostgresSearchEngine :: async fn delete_index(& self, _name : & str) -> crate::Result <()> | — |
PostgresSearchEngine :: async fn index_exists(& self, _name : & str) -> crate::Result <bool> | — |
PostgresSearchEngine :: async fn index_document(& self, _doc : SearchDocument) -> crate::Result <()> | — |
PostgresSearchEngine :: async fn index_documents(& self, _docs : Vec <SearchDocument>) -> crate::Result <()> | — |
PostgresSearchEngine :: async fn delete_document(& self, _index : & str, _id : & str) -> crate::Result <()> | — |
PostgresSearchEngine :: async fn get_document(& self, _index : & str, _id : & str) -> crate::Result <Option <SearchDocument>> | — |
PostgresSearchEngine :: async fn search(& self, query : SearchQuery) -> crate::Result <SearchResults> | — |
fn filter_to_sql(filter : & crate::SearchFilter, param_offset : usize) ->(String, Vec <String>) | Build a SQL WHERE condition from a single SearchFilter |
fn text_search_sql(query : & str, fields : & & str, param_offset : usize) ->(String, String) | Build a SQL text search condition for ILIKE across multiple fields |
fn sort_to_sql(query : & SearchQuery, allowed_fields : & & str) -> String | Build an ORDER BY clause from SearchQuery sort fields |
fn build_facet(field : & str, values : Vec <(String, u64)>) -> FacetResult | Build a FacetResult from a list of (value, count) pairs. |
fn build_hit(id : & str, fields : Vec <(& str, serde_json::Value)>) -> SearchHit | Build a SearchHit from an ID and key-value pairs. |
No pub use re-exports: every item above is declared in this crate.
Boundary
Reaches into foundation.
Shares tier infrastructure with 82 other crates: infrastructure-acquire, infrastructure-adapters-google-calendar, infrastructure-adapters-google-gmail, infrastructure-adapters-google-places, infrastructure-adapters-google-trends, infrastructure-adapters-shodan, infrastructure-adapters-yelp, infrastructure-agent, … (82 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | infrastructure |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/infrastructure/search |
| Vocabulary in force (lexicon) | current |
Tier flow. Which tiers this crate's own edges cross.
flowchart LR n_infrastructure["infrastructure"] --> n_foundation["foundation"]
Dependencies
Runtime, in this workspace.
| Crate | Tier | Optional | Only on |
|---|---|---|---|
| `foundation-basemodels` | foundation | no | always |
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
async-trait | ^0.1 | — | no | always |
chrono | ^0.4 | serde | no | always |
meilisearch-sdk | ^0.27 | — | yes | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
sqlx | ^0.8 | runtime-tokio, postgres, chrono, uuid, json | no | always |
thiserror | ^2 | — | no | always |
tokio | ^1 | full | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. 2 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_search["application-search"] -->|uses| SELF n_platform_privacy_scan_api["platform-privacy-scan-api"] -->|uses| SELF SELF["infrastructure-search"] SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
| Feature | Enables | On by default |
|---|---|---|
default | — | yes |
meilisearch | meilisearch-sdk | no |
meilisearch-sdk | dep:meilisearch-sdk | no |
flowchart LR n_default["default"] n_meilisearch["meilisearch"] --> n_meilisearch_sdk["meilisearch-sdk"] n_meilisearch_sdk["meilisearch-sdk"] --> n_dep_meilisearch_sdk["dep:meilisearch-sdk"]
Targets
| Kind | Name | Source |
|---|---|---|
| lib | infrastructure_search | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
SearchError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | yes |
| async runtime | yes |
| database access | yes |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
2 workspace crates depend on this one: application-search, platform-privacy-scan-api.
Verification
| Kind | Count |
|---|---|
| Unit tests | 30 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 18 | 0 | 2 |
postgres | 6 | 0 | 0 |
What the tests establish, by name:
test_autocomplete_config_default—src/lib.rstest_filter_eq—src/lib.rstest_filter_range—src/lib.rstest_in_memory_create_index—src/lib.rstest_in_memory_delete_document—src/lib.rstest_in_memory_index_document—src/lib.rstest_in_memory_search_basic—src/lib.rstest_in_memory_search_pagination—src/lib.rstest_index_config_new—src/lib.rstest_search_backend_display—src/lib.rstest_search_document_new—src/lib.rstest_search_document_serialization—src/lib.rstest_search_document_with_fields—src/lib.rstest_search_error_display—src/lib.rstest_search_hit_new—src/lib.rstest_search_query_new—src/lib.rstest_search_query_with_pagination—src/lib.rstest_search_results_empty—src/lib.rstest_build_facet—src/postgres.rstest_build_facet_empty—src/postgres.rstest_build_hit—src/postgres.rstest_filter_eq—src/postgres.rstest_filter_in—src/postgres.rstest_filter_range—src/postgres.rstest_search_results_with_facets—src/postgres.rstest_sort_default—src/postgres.rstest_sort_rejects_unlisted—src/postgres.rstest_sort_with_field—src/postgres.rstest_text_search—src/postgres.rstest_text_search_empty—src/postgres.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 55 | 73 |
Public modules with a //! block | 1 | 1 |
pie showData
title Public items with rustdoc
"Documented" : 55
"No rustdoc detected" : 18
Metrics
| Metric | Value |
|---|---|
| Rust source files | 2 |
| Source lines | 1224 |
| Code lines | 907 |
| Public API items | 73 |
| Public modules | 1 |
| Tests | 30 |
| Examples | 0 |
| Cargo features | 3 |
| Direct runtime dependencies | 10 |
| Workspace reverse dependencies | 2 |
pie showData
title Public API by kind
"enum" : 4
"function" : 5
"method" : 49
"struct" : 13
"trait" : 1
"type alias" : 1
pie showData
title Rust source composition
"Code" : 907
"Blank or comment" : 317
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.