/usr/share/doc/python-django-haystack-doc/html/boost.html is in python-django-haystack-doc 2.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Boost — Haystack 2.1.1-dev documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '2.1.1-dev',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="Haystack 2.1.1-dev documentation" href="index.html" />
<link rel="next" title="Signal Processors" href="signal_processors.html" />
<link rel="prev" title="Autocomplete" href="autocomplete.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="signal_processors.html" title="Signal Processors"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="autocomplete.html" title="Autocomplete"
accesskey="P">previous</a> |</li>
<li><a href="toc.html">Haystack 2.1.1-dev documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="boost">
<span id="ref-boost"></span><h1>Boost<a class="headerlink" href="#boost" title="Permalink to this headline">¶</a></h1>
<p>Scoring is a critical component of good search. Normal full-text searches
automatically score a document based on how well it matches the query provided.
However, sometimes you want certain documents to score better than they
otherwise would. Boosting is a way to achieve this. There are three types of
boost:</p>
<ul class="simple">
<li>Term Boost</li>
<li>Document Boost</li>
<li>Field Boost</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Document & Field boost support was added in Haystack 1.1.</p>
</div>
<p>Despite all being types of boost, they take place at different times and have
slightly different effects on scoring.</p>
<p>Term boost happens at query time (when the search query is run) and is based
around increasing the score if a certain word/phrase is seen.</p>
<p>On the other hand, document & field boosts take place at indexing time (when
the document is being added to the index). Document boost causes the relevance
of the entire result to go up, where field boost causes only searches within
that field to do better.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">Be warned that boost is very, very sensitive & can hurt overall search
quality if over-zealously applied. Even very small adjustments can affect
relevance in a big way.</p>
</div>
<div class="section" id="term-boost">
<h2>Term Boost<a class="headerlink" href="#term-boost" title="Permalink to this headline">¶</a></h2>
<p>Term boosting is achieved by using <tt class="docutils literal"><span class="pre">SearchQuerySet.boost</span></tt>. You provide it
the term you want to boost on & a floating point value (based around <tt class="docutils literal"><span class="pre">1.0</span></tt>
as 100% - no boost).</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c"># Slight increase in relevance for documents that include "banana".</span>
<span class="n">sqs</span> <span class="o">=</span> <span class="n">SearchQuerySet</span><span class="p">()</span><span class="o">.</span><span class="n">boost</span><span class="p">(</span><span class="s">'banana'</span><span class="p">,</span> <span class="mf">1.1</span><span class="p">)</span>
<span class="c"># Big decrease in relevance for documents that include "blueberry".</span>
<span class="n">sqs</span> <span class="o">=</span> <span class="n">SearchQuerySet</span><span class="p">()</span><span class="o">.</span><span class="n">boost</span><span class="p">(</span><span class="s">'blueberry'</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">)</span>
</pre></div>
</div>
<p>See the <a class="reference internal" href="searchqueryset_api.html"><em>SearchQuerySet API</em></a> docs for more details on using this method.</p>
</div>
<div class="section" id="document-boost">
<h2>Document Boost<a class="headerlink" href="#document-boost" title="Permalink to this headline">¶</a></h2>
<p>Document boosting is done by adding a <tt class="docutils literal"><span class="pre">boost</span></tt> field to the prepared data
<tt class="docutils literal"><span class="pre">SearchIndex</span></tt> creates. The best way to do this is to override
<tt class="docutils literal"><span class="pre">SearchIndex.prepare</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">haystack</span> <span class="kn">import</span> <span class="n">indexes</span>
<span class="kn">from</span> <span class="nn">notes.models</span> <span class="kn">import</span> <span class="n">Note</span>
<span class="k">class</span> <span class="nc">NoteSearchIndex</span><span class="p">(</span><span class="n">indexes</span><span class="o">.</span><span class="n">SearchIndex</span><span class="p">,</span> <span class="n">indexes</span><span class="o">.</span><span class="n">Indexable</span><span class="p">):</span>
<span class="c"># Your regular fields here then...</span>
<span class="k">def</span> <span class="nf">prepare</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
<span class="n">data</span> <span class="o">=</span> <span class="nb">super</span><span class="p">(</span><span class="n">NoteSearchIndex</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">prepare</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="n">data</span><span class="p">[</span><span class="s">'boost'</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.1</span>
<span class="k">return</span> <span class="n">data</span>
</pre></div>
</div>
<p>Another approach might be to add a new field called <tt class="docutils literal"><span class="pre">boost</span></tt>. However, this
can skew your schema and is not encouraged.</p>
</div>
<div class="section" id="field-boost">
<h2>Field Boost<a class="headerlink" href="#field-boost" title="Permalink to this headline">¶</a></h2>
<p>Field boosting is enabled by setting the <tt class="docutils literal"><span class="pre">boost</span></tt> kwarg on the desired field.
An example of this might be increasing the significance of a <tt class="docutils literal"><span class="pre">title</span></tt>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">haystack</span> <span class="kn">import</span> <span class="n">indexes</span>
<span class="kn">from</span> <span class="nn">notes.models</span> <span class="kn">import</span> <span class="n">Note</span>
<span class="k">class</span> <span class="nc">NoteSearchIndex</span><span class="p">(</span><span class="n">indexes</span><span class="o">.</span><span class="n">SearchIndex</span><span class="p">,</span> <span class="n">indexes</span><span class="o">.</span><span class="n">Indexable</span><span class="p">):</span>
<span class="n">text</span> <span class="o">=</span> <span class="n">indexes</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">document</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="n">use_template</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">title</span> <span class="o">=</span> <span class="n">indexes</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">model_attr</span><span class="o">=</span><span class="s">'title'</span><span class="p">,</span> <span class="n">boost</span><span class="o">=</span><span class="mf">1.125</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">Note</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="toc.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Boost</a><ul>
<li><a class="reference internal" href="#term-boost">Term Boost</a></li>
<li><a class="reference internal" href="#document-boost">Document Boost</a></li>
<li><a class="reference internal" href="#field-boost">Field Boost</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="autocomplete.html"
title="previous chapter">Autocomplete</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="signal_processors.html"
title="next chapter">Signal Processors</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/boost.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="signal_processors.html" title="Signal Processors"
>next</a> |</li>
<li class="right" >
<a href="autocomplete.html" title="Autocomplete"
>previous</a> |</li>
<li><a href="toc.html">Haystack 2.1.1-dev documentation</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2009-2013, Daniel Lindsley.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
</div>
</body>
</html>
|