blob: 79ba4e9a60c764dcde6c4972a8d5ef518615e5e0 [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="Collectors"><meta name="keywords" content="rust, rustlang, rust-lang, collector"><title>tantivy::collector - 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="../../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 mod"><!--[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><h2 class="location"><a href="#">Module collector</a></h2><div class="sidebar-elems"><section><ul class="block"><li><a href="#structs">Structs</a></li><li><a href="#traits">Traits</a></li></ul></section></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">Module <a href="../index.html">tantivy</a>::<wbr><a class="mod" href="#">collector</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/collector/mod.rs.html#1-485">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">&#x2212;</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="collectors"><a href="#collectors">Collectors</a></h2>
<p>Collectors define the information you want to extract from the documents matching the queries.
In tantivy jargon, we call this information your search “fruit”.</p>
<p>Your fruit could for instance be :</p>
<ul>
<li><a href="struct.Count.html">the count of matching documents</a></li>
<li><a href="struct.TopDocs.html">the top 10 documents, by relevancy or by a fast field</a></li>
<li><a href="struct.FacetCollector.html">facet counts</a></li>
</ul>
<p>At some point in your code, you will trigger the actual search operation by calling
<a href="../struct.Searcher.html#method.search"><code>Searcher::search()</code></a>.
This call will look like this:</p>
<div class="example-wrap"><pre class="language-verbatim"><code>let fruit = searcher.search(&amp;query, &amp;collector)?;</code></pre></div>
<p>Here the type of fruit is actually determined as an associated type of the collector
(<code>Collector::Fruit</code>).</p>
<h2 id="combining-several-collectors"><a href="#combining-several-collectors">Combining several collectors</a></h2>
<p>A rich search experience often requires to run several collectors on your search query.
For instance,</p>
<ul>
<li>selecting the top-K products matching your query</li>
<li>counting the matching documents</li>
<li>computing several facets</li>
<li>computing statistics about the matching product prices</li>
</ul>
<p>A simple and efficient way to do that is to pass your collectors as one tuple.
The resulting <code>Fruit</code> will then be a typed tuple with each collector’s original fruits
in their respective position.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>tantivy::collector::{Count, TopDocs};
<span class="kw">let </span>(doc_count, top_docs): (usize, Vec&lt;(Score, DocAddress)&gt;) =
searcher.search(<span class="kw-2">&amp;</span>query, <span class="kw-2">&amp;</span>(Count, TopDocs::with_limit(<span class="number">2</span>)))<span class="question-mark">?</span>;</code></pre></div>
<p>The <code>Collector</code> trait is implemented for up to 4 collectors.
If you have more than 4 collectors, you can either group them into
tuples of tuples <code>(a,(b,(c,d)))</code>, or rely on <a href="struct.MultiCollector.html" title="MultiCollector"><code>MultiCollector</code></a>.</p>
<h2 id="combining-several-collectors-dynamically"><a href="#combining-several-collectors-dynamically">Combining several collectors dynamically</a></h2>
<p>Combining collectors into a tuple is a zero-cost abstraction: everything
happens as if you had manually implemented a single collector
combining all of our features.</p>
<p>Unfortunately it requires you to know at compile time your collector types.
If on the other hand, the collectors depend on some query parameter,
you can rely on <a href="struct.MultiCollector.html" title="MultiCollector"><code>MultiCollector</code></a>’s.</p>
<h2 id="implementing-your-own-collectors"><a href="#implementing-your-own-collectors">Implementing your own collectors.</a></h2>
<p>See the <code>custom_collector</code> example.</p>
</div></details><h2 id="structs" class="small-section-header"><a href="#structs">Structs</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.Count.html" title="tantivy::collector::Count struct">Count</a></div><div class="item-right docblock-short"><code>CountCollector</code> collector only counts how many
documents match the query.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.DocSetCollector.html" title="tantivy::collector::DocSetCollector struct">DocSetCollector</a></div><div class="item-right docblock-short">Collectors that returns the set of DocAddress that matches the query.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FacetCollector.html" title="tantivy::collector::FacetCollector struct">FacetCollector</a></div><div class="item-right docblock-short">Collector for faceting</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FacetCounts.html" title="tantivy::collector::FacetCounts struct">FacetCounts</a></div><div class="item-right docblock-short">Intermediary result of the <code>FacetCollector</code> that stores
the facet counts for all the segments.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FilterCollector.html" title="tantivy::collector::FilterCollector struct">FilterCollector</a></div><div class="item-right docblock-short">The <code>FilterCollector</code> filters docs using a fast field value and a predicate.
Only the documents for which the predicate returned “true” will be passed on to the next
collector.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.FruitHandle.html" title="tantivy::collector::FruitHandle struct">FruitHandle</a></div><div class="item-right docblock-short">FruitHandle stores reference to the corresponding collector inside MultiCollector</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.HistogramCollector.html" title="tantivy::collector::HistogramCollector struct">HistogramCollector</a></div><div class="item-right docblock-short">Histogram builds an histogram of the values of a fastfield for the
collected DocSet.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.MultiCollector.html" title="tantivy::collector::MultiCollector struct">MultiCollector</a></div><div class="item-right docblock-short">Multicollector makes it possible to collect on more than one collector.
It should only be used for use cases where the Collector types is unknown
at compile time.</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.MultiFruit.html" title="tantivy::collector::MultiFruit struct">MultiFruit</a></div><div class="item-right docblock-short">MultiFruit keeps Fruits from every nested Collector</div></div><div class="item-row"><div class="item-left module-item"><a class="struct" href="struct.TopDocs.html" title="tantivy::collector::TopDocs struct">TopDocs</a></div><div class="item-right docblock-short">The <code>TopDocs</code> collector keeps track of the top <code>K</code> documents
sorted by their score.</div></div></div><h2 id="traits" class="small-section-header"><a href="#traits">Traits</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Collector.html" title="tantivy::collector::Collector trait">Collector</a></div><div class="item-right docblock-short">Collectors are in charge of collecting and retaining relevant
information from the document found and scored by the query.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CustomScorer.html" title="tantivy::collector::CustomScorer trait">CustomScorer</a></div><div class="item-right docblock-short"><code>CustomScorer</code> makes it possible to define any kind of score.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.CustomSegmentScorer.html" title="tantivy::collector::CustomSegmentScorer trait">CustomSegmentScorer</a></div><div class="item-right docblock-short">A custom segment scorer makes it possible to define any kind of score
for a given document belonging to a specific segment.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.Fruit.html" title="tantivy::collector::Fruit trait">Fruit</a></div><div class="item-right docblock-short"><code>Fruit</code> is the type for the result of our collection.
e.g. <code>usize</code> for the <code>Count</code> collector.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ScoreSegmentTweaker.html" title="tantivy::collector::ScoreSegmentTweaker trait">ScoreSegmentTweaker</a></div><div class="item-right docblock-short">A <code>ScoreSegmentTweaker</code> makes it possible to modify the default score
for a given document belonging to a specific segment.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.ScoreTweaker.html" title="tantivy::collector::ScoreTweaker trait">ScoreTweaker</a></div><div class="item-right docblock-short"><code>ScoreTweaker</code> makes it possible to tweak the score
emitted by the scorer into another one.</div></div><div class="item-row"><div class="item-left module-item"><a class="trait" href="trait.SegmentCollector.html" title="tantivy::collector::SegmentCollector trait">SegmentCollector</a></div><div class="item-right docblock-short">The <code>SegmentCollector</code> is the trait in charge of defining the
collect operation at the scale of the segment.</div></div></div></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>