-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from PSeitz/master
update literate docs
- Loading branch information
Showing
27 changed files
with
6,332 additions
and
936 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,309 @@ | ||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>DateTime field example</title> | ||
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | ||
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"> | ||
<link rel="stylesheet" media="all" href="docco.css" /> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div id="background"></div> | ||
|
||
<ul id="jump_to"> | ||
<li> | ||
<a class="large" href="javascript:void(0);">Jump To …</a> | ||
<a class="small" href="javascript:void(0);">+</a> | ||
<div id="jump_wrapper"> | ||
<div id="jump_page_wrapper"> | ||
<div id="jump_page"> | ||
|
||
|
||
<a class="source" href="aggregation.html"> | ||
aggregation.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="basic_search.html"> | ||
basic_search.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="custom_collector.html"> | ||
custom_collector.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="custom_tokenizer.html"> | ||
custom_tokenizer.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="date_time_field.html"> | ||
date_time_field.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="deleting_updating_documents.html"> | ||
deleting_updating_documents.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="faceted_search.html"> | ||
faceted_search.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="faceted_search_with_tweaked_score.html"> | ||
faceted_search_with_tweaked_score.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="fuzzy_search.html"> | ||
fuzzy_search.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="index_from_multiple_threads.html"> | ||
index_from_multiple_threads.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="index_with_json.html"> | ||
index_with_json.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="integer_range_search.html"> | ||
integer_range_search.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="ip_field.html"> | ||
ip_field.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="iterating_docs_and_positions.html"> | ||
iterating_docs_and_positions.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="json_field.html"> | ||
json_field.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="phrase_prefix_search.html"> | ||
phrase_prefix_search.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="pre_tokenized_text.html"> | ||
pre_tokenized_text.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="snippet.html"> | ||
snippet.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="stop_words.html"> | ||
stop_words.rs | ||
</a> | ||
|
||
|
||
<a class="source" href="warmer.html"> | ||
warmer.rs | ||
</a> | ||
|
||
</div> | ||
</div> | ||
</li> | ||
</ul> | ||
|
||
<ul class="sections"> | ||
|
||
|
||
|
||
<li id="section-1"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-1">§</a> | ||
</div> | ||
<h1 id="datetime-field-example">DateTime field example</h1> | ||
<p>This example shows how the DateTime field can be used</p> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> | ||
<span class="hljs-keyword">use</span> tantivy::collector::TopDocs; | ||
<span class="hljs-keyword">use</span> tantivy::query::QueryParser; | ||
<span class="hljs-keyword">use</span> tantivy::schema::{DateOptions, Document, OwnedValue, Schema, INDEXED, STORED, STRING}; | ||
<span class="hljs-keyword">use</span> tantivy::{Index, IndexWriter, TantivyDocument}; | ||
|
||
<span class="hljs-keyword">fn</span> <span class="hljs-title function_">main</span>() <span class="hljs-punctuation">-></span> tantivy::<span class="hljs-type">Result</span><()> {</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-2"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-2">§</a> | ||
</div> | ||
<h1 id="defining-the-schema">Defining the schema</h1> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-keyword">mut </span><span class="hljs-variable">schema_builder</span> = Schema::<span class="hljs-title function_ invoke__">builder</span>(); | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">opts</span> = DateOptions::<span class="hljs-title function_ invoke__">from</span>(INDEXED) | ||
.<span class="hljs-title function_ invoke__">set_stored</span>() | ||
.<span class="hljs-title function_ invoke__">set_fast</span>() | ||
.<span class="hljs-title function_ invoke__">set_precision</span>(tantivy::schema::DateTimePrecision::Seconds);</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-3"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-3">§</a> | ||
</div> | ||
<p>Add <code>occurred_at</code> date field type</p> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-variable">occurred_at</span> = schema_builder.<span class="hljs-title function_ invoke__">add_date_field</span>(<span class="hljs-string">"occurred_at"</span>, opts); | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">event_type</span> = schema_builder.<span class="hljs-title function_ invoke__">add_text_field</span>(<span class="hljs-string">"event"</span>, STRING | STORED); | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">schema</span> = schema_builder.<span class="hljs-title function_ invoke__">build</span>();</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-4"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-4">§</a> | ||
</div> | ||
<h1 id="indexing-documents">Indexing documents</h1> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-variable">index</span> = Index::<span class="hljs-title function_ invoke__">create_in_ram</span>(schema.<span class="hljs-title function_ invoke__">clone</span>()); | ||
|
||
<span class="hljs-keyword">let</span> <span class="hljs-keyword">mut </span><span class="hljs-variable">index_writer</span>: IndexWriter = index.<span class="hljs-title function_ invoke__">writer</span>(<span class="hljs-number">50_000_000</span>)?;</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-5"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-5">§</a> | ||
</div> | ||
<p>The dates are passed as string in the RFC3339 format</p> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-variable">doc</span> = TantivyDocument::<span class="hljs-title function_ invoke__">parse_json</span>( | ||
&schema, | ||
<span class="hljs-string">r#"{ | ||
"occurred_at": "2022-06-22T12:53:50.53Z", | ||
"event": "pull-request" | ||
}"#</span>, | ||
)?; | ||
index_writer.<span class="hljs-title function_ invoke__">add_document</span>(doc)?; | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">doc</span> = TantivyDocument::<span class="hljs-title function_ invoke__">parse_json</span>( | ||
&schema, | ||
<span class="hljs-string">r#"{ | ||
"occurred_at": "2022-06-22T13:00:00.22Z", | ||
"event": "comment" | ||
}"#</span>, | ||
)?; | ||
index_writer.<span class="hljs-title function_ invoke__">add_document</span>(doc)?; | ||
index_writer.<span class="hljs-title function_ invoke__">commit</span>()?; | ||
|
||
<span class="hljs-keyword">let</span> <span class="hljs-variable">reader</span> = index.<span class="hljs-title function_ invoke__">reader</span>()?; | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">searcher</span> = reader.<span class="hljs-title function_ invoke__">searcher</span>();</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-6"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-6">§</a> | ||
</div> | ||
<h1 id="search">Search</h1> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-variable">query_parser</span> = QueryParser::<span class="hljs-title function_ invoke__">for_index</span>(&index, <span class="hljs-built_in">vec!</span>[event_type]); | ||
{</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-7"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-7">§</a> | ||
</div> | ||
<p>Simple exact search on the date</p> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-variable">query</span> = query_parser.<span class="hljs-title function_ invoke__">parse_query</span>(<span class="hljs-string">"occurred_at:\"2022-06-22T12:53:50.53Z\""</span>)?; | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">count_docs</span> = searcher.<span class="hljs-title function_ invoke__">search</span>(&*query, &TopDocs::<span class="hljs-title function_ invoke__">with_limit</span>(<span class="hljs-number">5</span>))?; | ||
<span class="hljs-built_in">assert_eq!</span>(count_docs.<span class="hljs-title function_ invoke__">len</span>(), <span class="hljs-number">1</span>); | ||
} | ||
{</pre></div></div> | ||
|
||
</li> | ||
|
||
|
||
<li id="section-8"> | ||
<div class="annotation"> | ||
|
||
<div class="sswrap "> | ||
<a class="ss" href="#section-8">§</a> | ||
</div> | ||
<p>Range query on the date field</p> | ||
|
||
</div> | ||
|
||
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> <span class="hljs-variable">query</span> = query_parser | ||
.<span class="hljs-title function_ invoke__">parse_query</span>(<span class="hljs-string">r#"occurred_at:[2022-06-22T12:58:00Z TO 2022-06-23T00:00:00Z}"#</span>)?; | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">count_docs</span> = searcher.<span class="hljs-title function_ invoke__">search</span>(&*query, &TopDocs::<span class="hljs-title function_ invoke__">with_limit</span>(<span class="hljs-number">4</span>))?; | ||
<span class="hljs-built_in">assert_eq!</span>(count_docs.<span class="hljs-title function_ invoke__">len</span>(), <span class="hljs-number">1</span>); | ||
<span class="hljs-title function_ invoke__">for</span> (_score, doc_address) <span class="hljs-keyword">in</span> count_docs { | ||
<span class="hljs-keyword">let</span> <span class="hljs-variable">retrieved_doc</span> = searcher.doc::<TantivyDocument>(doc_address)?; | ||
<span class="hljs-built_in">assert!</span>(matches!( | ||
retrieved_doc.<span class="hljs-title function_ invoke__">get_first</span>(occurred_at), | ||
<span class="hljs-title function_ invoke__">Some</span>(OwnedValue::<span class="hljs-title function_ invoke__">Date</span>(_)) | ||
)); | ||
<span class="hljs-built_in">assert_eq!</span>( | ||
retrieved_doc.<span class="hljs-title function_ invoke__">to_json</span>(&schema), | ||
<span class="hljs-string">r#"{"event":["comment"],"occurred_at":["2022-06-22T13:00:00.22Z"]}"#</span> | ||
); | ||
} | ||
} | ||
<span class="hljs-title function_ invoke__">Ok</span>(()) | ||
}</pre></div></div> | ||
|
||
</li> | ||
|
||
</ul> | ||
</div> | ||
</body> | ||
</html> |
Oops, something went wrong.