Skip to content

Commit 77ce719

Browse files
authored
Merge pull request #4206 from vespa-engine/havardpe/document-near-with-negative-terms-and-fix-old-errors
Document negative terms in near/onear and clarify distance semantics
2 parents 2c99b5f + 67cd1b6 commit 77ce719

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

en/reference/query-language-reference.html

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,24 +248,39 @@ <h2 id="where">where</h2>
248248
<th>near</th>
249249
<td>
250250
<p id="near">
251-
<code>near()</code> matches if all argument terms occur close to each other in the same document.
251+
<code>near()</code> matches if all argument terms occur within the specified distance,
252+
in any order. Negative terms (prefixed with <code>!</code>) exclude matches where those terms
253+
appear within the exclusion distance.
252254
</p>
255+
<pre>
256+
where field contains near("a", "b", "c")
257+
where field contains ({distance: 5}near("web", "search"))
258+
where field contains near("sql", "database", !"nosql")
259+
</pre>
253260
<table class="table">
254261
<thead>
255262
<tr>
256263
<th>Annotation</th>
257-
<th>Effect</th>
264+
<th>Default</th>
265+
<th>Description</th>
258266
</tr>
259267
</thead>
260268
<tbody>
261269
<tr>
262270
<td><a href="#distance">distance</a></td>
263-
<td>Tune closeness using <code>distance</code>.</td>
271+
<td>2</td>
272+
<td>Maximum position difference for terms to match.</td>
273+
</tr>
274+
<tr>
275+
<td>exclusionDistance</td>
276+
<td>(distance+1)/2</td>
277+
<td>Exclusion zone size around negative terms.</td>
264278
</tr>
265279
</tbody>
266280
</table>
267281
<p>
268-
For multi-value fields, setting <a href="schema-reference.html#rank-element-gap">element-gap</a> for the field in the rank profile enables distance calculation between adjacent elements.
282+
Negative terms must come after all positive terms.
283+
For multi-value fields, setting <a href="schema-reference.html#rank-element-gap">element-gap</a> for the field in the rank profile enables distance calculation between adjacent elements.
269284
</p>
270285
</td>
271286
</tr>
@@ -275,26 +290,38 @@ <h2 id="where">where</h2>
275290
<td>
276291
<p id="onear">
277292
<code>onear()</code> (ordered near) is like <code>near()</code>,
278-
but also requires the terms in the document having the same order
279-
as given in the function (i.e. it is a phrase allowing other words interleaved).
280-
With distance 1, <code>onear()</code> has the same semantics as <code>phrase()</code>.
293+
but requires terms to appear in the same order as specified in the query.
294+
With distance set to (number of terms - 1), <code>onear()</code> is equivalent to <code>phrase()</code>.
281295
</p>
282-
<table class="table"> <!-- ToDo: Assuming near and onear support the same annotations -->
296+
<pre>
297+
where field contains onear("web", "search", "engine")
298+
where field contains ({distance: 5}onear("neural", "network"))
299+
where field contains onear("java", "tutorial", !"script")
300+
</pre>
301+
<table class="table">
283302
<thead>
284303
<tr>
285304
<th>Annotation</th>
286-
<th>Effect</th>
305+
<th>Default</th>
306+
<th>Description</th>
287307
</tr>
288308
</thead>
289309
<tbody>
290310
<tr>
291311
<td><a href="#distance">distance</a></td>
292-
<td>Tune closeness using <code>distance</code>.</td>
312+
<td>2</td>
313+
<td>Maximum position difference for terms to match.</td>
314+
</tr>
315+
<tr>
316+
<td>exclusionDistance</td>
317+
<td>(distance+1)/2</td>
318+
<td>Exclusion zone size around negative terms.</td>
293319
</tr>
294320
</tbody>
295321
</table>
296322
<p>
297-
For multi-value fields, setting <a href="schema-reference.html#rank-element-gap">element-gap</a> for the field in the rank profile enables distance calculation between adjacent elements.
323+
Negative terms must come after all positive terms.
324+
For multi-value fields, setting <a href="schema-reference.html#rank-element-gap">element-gap</a> for the field in the rank profile enables distance calculation between adjacent elements.
298325
</p>
299326
</td>
300327
</tr>
@@ -1704,9 +1731,10 @@ <h2 id="annotations">Annotations</h2>
17041731
<td>int</td>
17051732
<td>
17061733
<p id="distance">
1707-
The <em>distance</em>-annotation sets the maximum position difference to count as a match,
1734+
The <em>distance</em> annotation sets the maximum position difference to count as a match,
17081735
see <a href="#near">near</a> / <a href="#onear">onear</a>.
1709-
The default distance is 2, meaning match if the words have up to one separating word.
1736+
All matching terms must fit within positions [P, P+distance] where P is the first term's position.
1737+
Default is 2.
17101738
</p>
17111739
<pre>
17121740
where text contains ({distance: 5}near("a", "b"))

0 commit comments

Comments
 (0)