tag:support.flying-sphinx.com,2011-01-05:/discussions/problems/1749-weighting-an-indexed-boolean-field-makes-no-difference-in-searchesFlying Sphinx: Discussion 2016-08-11T01:31:46Ztag:support.flying-sphinx.com,2011-01-05:Comment/346860512014-09-23T11:16:46Z2014-09-23T11:16:46ZWeighting an indexed boolean field makes no difference in searches?<div><p>Hello, I've got a field that I am indexing as a boolean, mainly
it's the episodes field in our table. The idea is that if an entry
has <code>> 0 episodes</code> it be listed further down the
search results. As such I've added this to the index:</p>
<pre>
<code>has 'episode > 0', as: :episode, type: :boolean</code>
</pre>
<p>And this to our searches results:</p>
<pre>
<code> common_search_attributes[:field_weights] = {title: 40, director: 30, starring: 20, episode: 3}</code>
</pre>
<p><code>common_search_attributes</code> gets called for all
searches.</p>
<p>We figured that by adding a very smal weight to the episode
boolean field we'd see the results with episodes listed together
further down. However, after reindexing and searching with and
without the <code>episode: 3</code> change the results are exactly
the same.</p>
<p>What are we doing wrong?</p>
<p>Thanks.</p></div>alextag:support.flying-sphinx.com,2011-01-05:Comment/346860512014-09-23T16:56:23Z2014-09-23T16:56:23ZWeighting an indexed boolean field makes no difference in searches?<div><p>Hi Alex</p>
<p>Unfortunately, field weights only work with fields, not
attributes.</p>
<p>There's two other ways to approach this I can think of: order by
weight and then by episode:</p>
<pre>
<code>common_search_attributes[:select] = "*, weight() as score"
common_search_attributes[:order] = "score DESC, episode ASC"</code>
</pre>
<p>The second approach is similar, but allows for more complexity:
create your own weighting formula</p>
<pre>
<code>common_search_attributes[:select] = "*, IF(episode = 1, weight(), weight() * 3) as score"
common_search_attributes[:order] = "score DESC"</code>
</pre>
<p><a href=
"http://sphinxsearch.com/docs/manual-2.1.9.html#expressions">http://sphinxsearch.com/docs/manual-2.1.9.html#expressions</a>
has more details on functions and such you can use.</p>
<p>Cheers</p>
<p>Pat</p></div>Pat Allantag:support.flying-sphinx.com,2011-01-05:Comment/346860512014-09-24T09:44:47Z2014-09-24T09:44:47ZWeighting an indexed boolean field makes no difference in searches?<div><p>Thanks a lot Pat, I’ll try this.</p>
<p>—<br>
Sent from my iPad, please excuse hypos.</p></div>alex