blob: 6b64598814119021cb7651c8d5ff779f7a41102e [file] [log] [blame]
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="`doc!` is a shortcut that helps building `Document` objects."><meta name="keywords" content="rust, rustlang, rust-lang, doc"><title>doc in tantivy - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" href="../normalize.css"><link rel="stylesheet" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" href="../ayu.css" disabled><link rel="stylesheet" href="../dark.css" disabled><link rel="stylesheet" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="sidebar-items.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc macro"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">&#9776;</button><a class="sidebar-logo" href="../tantivy/index.html"><div class="logo-container"><img src="http://fulmicoton.com/tantivy-logo/tantivy-logo.png" alt="logo"></div></a><h2></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../tantivy/index.html"><div class="logo-container">
<img src="http://fulmicoton.com/tantivy-logo/tantivy-logo.png" alt="logo"></div></a><div class="sidebar-elems"><h2><a href="index.html">In tantivy</a></h2></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn">Macro <a href="index.html">tantivy</a>::<wbr><a class="macro" href="#">doc</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/tantivy/macros.rs.html#45-64">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><div class="item-decl"><div class="example-wrap"><pre class="rust macro"><code><span class="macro">macro_rules! </span>doc {
() =&gt; { ... };
($(<span class="macro-nonterminal">$field</span>:expr =&gt; <span class="macro-nonterminal">$value</span>:expr),<span class="kw-2">*</span>) =&gt; { ... };
($(<span class="macro-nonterminal">$field</span>:expr =&gt; <span class="macro-nonterminal">$value</span>:expr),+ ,) =&gt; { ... };
}</code></pre></div>
</div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>doc!</code> is a shortcut that helps building <code>Document</code>
objects.</p>
<p>Assuming that <code>field1</code> and <code>field2</code> are <code>Field</code> instances.
You can create a document with a value of <code>value1</code> for <code>field1</code>
<code>value2</code> for <code>field2</code>, as follows :</p>
<div class="example-wrap"><pre class="language-c"><code>doc!(
field1 =&gt; value1,
field2 =&gt; value2,
)</code></pre></div>
<p>The value can be a <code>u64</code>, a <code>&amp;str</code>, a <code>i64</code>, or a <code>String</code>.</p>
<h2 id="warning"><a href="#warning">Warning</a></h2>
<p>The document hence created, is not yet validated against a schema.
Nothing prevents its user from creating an invalid document missing a
field, or associating a <code>String</code> to a <code>u64</code> field for instance.</p>
<h2 id="example"><a href="#example">Example</a></h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy::schema::{Schema, TEXT, FAST};
<span class="kw">use </span>tantivy::doc;
<span class="comment">//...
</span><span class="kw">let </span><span class="kw-2">mut </span>schema_builder = Schema::builder();
<span class="kw">let </span>title = schema_builder.add_text_field(<span class="string">&quot;title&quot;</span>, TEXT);
<span class="kw">let </span>author = schema_builder.add_text_field(<span class="string">&quot;text&quot;</span>, TEXT);
<span class="kw">let </span>likes = schema_builder.add_u64_field(<span class="string">&quot;num_u64&quot;</span>, FAST);
<span class="kw">let </span>schema = schema_builder.build();
<span class="kw">let </span>doc = <span class="macro">doc!</span>(
title =&gt; <span class="string">&quot;Life Aquatic&quot;</span>,
author =&gt; <span class="string">&quot;Wes Anderson&quot;</span>,
likes =&gt; <span class="number">4u64
</span>);</code></pre></div>
</div></details></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="tantivy" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.66.0-nightly (5c8bff74b 2022-10-21)" ></div></body></html>