mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-05 16:52:55 +00:00
* Split Collector into an overall Collector and a per-segment SegmentCollector. Precursor to cross-segment parallelism, and as a side benefit cleans up any per-segment fields from being Option<T> to just T. * Attempt to add MultiCollector back * working. Chained collector is broken though * Fix chained collector * Fix test * Make Weight Send+Sync for parallelization purposes * Expose parameters of RangeQuery for external usage * Removed &mut self * fixing tests * Restored TestCollectors * blop * multicollector working * chained collector working * test broken * fixing unit test * blop * blop * Blop * simplifying APi * blop * better syntax * Simplifying top_collector * refactoring * blop * Sync with master * Added multithread search * Collector refactoring * Schema::builder * CR and rustdoc * CR comments * blop * Added an executor * Sorted the segment readers in the searcher * Update searcher.rs * Fixed unit testst * changed the place where we have the sort-segment-by-count heuristic * using crossbeam::channel * inlining * Comments about panics propagating * Added unit test for executor panicking * Readded default * Removed Default impl * Added unit test for executor
42 lines
1.4 KiB
Rust
42 lines
1.4 KiB
Rust
extern crate tantivy;
|
|
use tantivy::schema::*;
|
|
|
|
// # Document from json
|
|
//
|
|
// For convenience, `Document` can be parsed directly from json.
|
|
fn main() -> tantivy::Result<()> {
|
|
// Let's first define a schema and an index.
|
|
// Check out the basic example if this is confusing to you.
|
|
//
|
|
// first we need to define a schema ...
|
|
let mut schema_builder = Schema::builder();
|
|
schema_builder.add_text_field("title", TEXT | STORED);
|
|
schema_builder.add_text_field("body", TEXT);
|
|
schema_builder.add_u64_field("year", INT_INDEXED);
|
|
let schema = schema_builder.build();
|
|
|
|
// Let's assume we have a json-serialized document.
|
|
let mice_and_men_doc_json = r#"{
|
|
"title": "Of Mice and Men",
|
|
"year": 1937
|
|
}"#;
|
|
|
|
// We can parse our document
|
|
let _mice_and_men_doc = schema.parse_document(&mice_and_men_doc_json)?;
|
|
|
|
// Multi-valued field are allowed, they are
|
|
// expressed in JSON by an array.
|
|
// The following document has two titles.
|
|
let frankenstein_json = r#"{
|
|
"title": ["Frankenstein", "The Modern Prometheus"],
|
|
"year": 1818
|
|
}"#;
|
|
let _frankenstein_doc = schema.parse_document(&frankenstein_json)?;
|
|
|
|
// Note that the schema is saved in your index directory.
|
|
//
|
|
// As a result, Indexes are aware of their schema, and you can use this feature
|
|
// just by opening an existing `Index`, and calling `index.schema()..parse_document(json)`.
|
|
Ok(())
|
|
}
|