blob: cd440eabc0c15e901a894b1b630eda51a227cd84 [file] [log] [blame]
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Namespace Lucene.Net.Search.Spans
| Apache Lucene.NET 4.8.0-beta00013 Documentation </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="Namespace Lucene.Net.Search.Spans
| Apache Lucene.NET 4.8.0-beta00013 Documentation ">
<meta name="generator" content="docfx 2.56.2.0">
<link rel="shortcut icon" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/logo/favicon.ico">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.vendor.css">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.css">
<link rel="stylesheet" href="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/main.css">
<meta property="docfx:navrel" content="toc.html">
<meta property="docfx:tocrel" content="core/toc.html">
<meta property="docfx:rel" content="https://lucenenet.apache.org/docs/4.8.0-beta00009/">
</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<span id="forkongithub"><a href="https://github.com/apache/lucenenet" target="_blank">Fork me on GitHub</a></span>
<div id="wrapper">
<header>
<nav id="autocollapse" class="navbar ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<img id="logo" class="svg" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/logo/lucene-net-color.png" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>
<div class="subnav navbar navbar-default">
<div class="container hide-when-search">
<ul class="level0 breadcrumb">
<li>
<a href="https://lucenenet.apache.org/docs/4.8.0-beta00009/">API</a>
<span id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</span>
</li>
</ul>
</div>
</div>
</header>
<div class="container body-content">
<div id="search-results">
<div class="search-list"></div>
<div class="sr-items">
<p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
</div>
<ul id="pagination"></ul>
</div>
</div>
<div role="main" class="container body-content hide-when-search">
<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="Lucene.Net.Search.Spans">
<h1 id="Lucene_Net_Search_Spans" data-uid="Lucene.Net.Search.Spans" class="text-break">Namespace Lucene.Net.Search.Spans
</h1>
<div class="markdown level0 summary"><!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>The calculus of spans.</p>
<p>A span is a <code>&lt;doc,startPosition,endPosition&gt;</code> tuple.</p>
<p>The following span query operators are implemented: * A <a class="xref" href="Lucene.Net.Search.Spans.SpanTermQuery.html">SpanTermQuery</a> matches all spans containing a particular <a class="xref" href="Lucene.Net.Index.Term.html">Term</a>. * A <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a> matches spans which occur near one another, and can be used to implement things like phrase search (when constructed from <a class="xref" href="Lucene.Net.Search.Spans.SpanTermQuery.html">SpanTermQuery</a>s) and inter-phrase proximity (when constructed from other <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a>s). * A <a class="xref" href="Lucene.Net.Search.Spans.SpanOrQuery.html">SpanOrQuery</a> merges spans from a number of other <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a>s. * A <a class="xref" href="Lucene.Net.Search.Spans.SpanNotQuery.html">SpanNotQuery</a> removes spans matching one <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> which overlap (or comes near) another. This can be used, e.g., to implement within-paragraph search. * A <a class="xref" href="Lucene.Net.Search.Spans.SpanFirstQuery.html">SpanFirstQuery</a> matches spans matching <code>q</code> whose end position is less than <code>n</code>. This can be used to constrain matches to the first part of the document. * A <a class="xref" href="Lucene.Net.Search.Spans.SpanPositionRangeQuery.html">SpanPositionRangeQuery</a> is a more general form of SpanFirstQuery that can constrain matches to arbitrary portions of the document. In all cases, output spans are minimally inclusive. In other words, a span formed by matching a span in x and y starts at the lesser of the two starts and ends at the greater of the two ends. </p>
<p>For example, a span query which matches &quot;John Kerry&quot; within ten
words of &quot;George Bush&quot; within the first 100 words of the document
could be constructed with:</p>
<pre><code>SpanQuery john = new SpanTermQuery(new Term(&quot;content&quot;, &quot;john&quot;));
SpanQuery kerry = new SpanTermQuery(new Term(&quot;content&quot;, &quot;kerry&quot;));
SpanQuery george = new SpanTermQuery(new Term(&quot;content&quot;, &quot;george&quot;));
SpanQuery bush = new SpanTermQuery(new Term(&quot;content&quot;, &quot;bush&quot;));
</code></pre><p>SpanQuery johnKerry =
new SpanNearQuery(new SpanQuery[] {john, kerry}, 0, true);</p>
<p>SpanQuery georgeBush =
new SpanNearQuery(new SpanQuery[] {george, bush}, 0, true);</p>
<p>SpanQuery johnKerryNearGeorgeBush =
new SpanNearQuery(new SpanQuery[] {johnKerry, georgeBush}, 10, false);</p>
<p>SpanQuery johnKerryNearGeorgeBushAtStart =
new SpanFirstQuery(johnKerryNearGeorgeBush, 100);</p>
<p>Span queries may be freely intermixed with other Lucene queries.
So, for example, the above query can be restricted to documents which
also use the word &quot;iraq&quot; with:</p>
<pre><code>Query query = new BooleanQuery();
query.add(johnKerryNearGeorgeBushAtStart, true, false);
query.add(new TermQuery(&quot;content&quot;, &quot;iraq&quot;), true, false);
</code></pre></div>
<div class="markdown level0 conceptual"></div>
<div class="markdown level0 remarks"></div>
<h3 id="classes">Classes
</h3>
<h4><a class="xref" href="Lucene.Net.Search.Spans.FieldMaskingSpanQuery.html">FieldMaskingSpanQuery</a></h4>
<section><p>Wrapper to allow <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> objects participate in composite
single-field SpanQueries by &apos;lying&apos; about their search field. That is,
the masked <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> will function as normal,
but <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html#Lucene_Net_Search_Spans_SpanQuery_Field">Field</a> simply hands back the value supplied
in this class&apos;s constructor.</p>
<p>This can be used to support Queries like <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a> or
<a class="xref" href="Lucene.Net.Search.Spans.SpanOrQuery.html">SpanOrQuery</a> across different fields, which is not ordinarily
permitted.</p>
<p>This can be useful for denormalized relational data: for example, when
indexing a document with conceptually many &apos;children&apos;: </p>
<pre><code> teacherid: 1
studentfirstname: james
studentsurname: jones
teacherid: 2
studenfirstname: james
studentsurname: smith
studentfirstname: sally
studentsurname: jones</code></pre>
<p>A <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a> with a slop of 0 can be applied across two
<a class="xref" href="Lucene.Net.Search.Spans.SpanTermQuery.html">SpanTermQuery</a> objects as follows:
<pre><code> SpanQuery q1 = new SpanTermQuery(new Term(&quot;studentfirstname&quot;, &quot;james&quot;));
SpanQuery q2 = new SpanTermQuery(new Term(&quot;studentsurname&quot;, &quot;jones&quot;));
SpanQuery q2m = new FieldMaskingSpanQuery(q2, &quot;studentfirstname&quot;);
Query q = new SpanNearQuery(new SpanQuery[] { q1, q2m }, -1, false);</code></pre>
to search for &apos;studentfirstname:james studentsurname:jones&apos; and find
teacherid 1 without matching teacherid 2 (which has a &apos;james&apos; in position 0
and &apos;jones&apos; in position 1). </p>
<p>Note: as <a class="xref" href="Lucene.Net.Search.Spans.FieldMaskingSpanQuery.html#Lucene_Net_Search_Spans_FieldMaskingSpanQuery_Field">Field</a> returns the masked field, scoring will be
done using the <a class="xref" href="Lucene.Net.Search.Similarities.Similarity.html">Similarity</a> and collection statistics of the field name supplied,
but with the term statistics of the real field. This may lead to exceptions,
poor performance, and unexpected scoring behavior.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.NearSpansOrdered.html">NearSpansOrdered</a></h4>
<section><p>A <a class="xref" href="Lucene.Net.Search.Spans.Spans.html">Spans</a> that is formed from the ordered subspans of a <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a>
where the subspans do not overlap and have a maximum slop between them.
<p>
The formed spans only contains minimum slop matches.
<p>
The matching slop is computed from the distance(s) between
the non overlapping matching <a class="xref" href="Lucene.Net.Search.Spans.Spans.html">Spans</a>.
<p>
Successive matches are always formed from the successive <a class="xref" href="Lucene.Net.Search.Spans.Spans.html">Spans</a>
of the <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a>.
<p>
The formed spans may contain overlaps when the slop is at least 1.
For example, when querying using
<code>t1 t2 t3</code>
with slop at least 1, the fragment:
<code>t1 t2 t1 t3 t2 t3</code>
matches twice:
<code>t1 t2 .. t3 </code>
<code> t1 .. t2 t3</code></p>
<p><p>
Expert:
Only public for subclassing. Most implementations should not need this class</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.NearSpansUnordered.html">NearSpansUnordered</a></h4>
<section><p>Similar to <a class="xref" href="Lucene.Net.Search.Spans.NearSpansOrdered.html">NearSpansOrdered</a>, but for the unordered case.
<p>
Expert:
Only public for subclassing. Most implementations should not need this class</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanFirstQuery.html">SpanFirstQuery</a></h4>
<section><p>Matches spans near the beginning of a field.
<p>
This class is a simple extension of <a class="xref" href="Lucene.Net.Search.Spans.SpanPositionRangeQuery.html">SpanPositionRangeQuery</a> in that it assumes the
start to be zero and only checks the end boundary.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanMultiTermQueryWrapper-1.html">SpanMultiTermQueryWrapper&lt;Q&gt;</a></h4>
<section><p>Wraps any <a class="xref" href="Lucene.Net.Search.MultiTermQuery.html">MultiTermQuery</a> as a <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a>,
so it can be nested within other <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> classes.
<p>
The query is rewritten by default to a <a class="xref" href="Lucene.Net.Search.Spans.SpanOrQuery.html">SpanOrQuery</a> containing
the expanded terms, but this can be customized.
<p>
Example:</p>
<pre><code>WildcardQuery wildcard = new WildcardQuery(new Term(&quot;field&quot;, &quot;bro?n&quot;));
SpanQuery spanWildcard = new SpanMultiTermQueryWrapper&lt;WildcardQuery>(wildcard);
// do something with spanWildcard, such as use it in a SpanFirstQuery</code></pre>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanMultiTermQueryWrapper-1.TopTermsSpanBooleanQueryRewrite.html">SpanMultiTermQueryWrapper&lt;Q&gt;.TopTermsSpanBooleanQueryRewrite</a></h4>
<section><p>A rewrite method that first translates each term into a <a class="xref" href="Lucene.Net.Search.Spans.SpanTermQuery.html">SpanTermQuery</a> in a
<a class="xref" href="Lucene.Net.Search.Occur.html#Lucene_Net_Search_Occur_SHOULD">SHOULD</a> clause in a <a class="xref" href="Lucene.Net.Search.BooleanQuery.html">BooleanQuery</a>, and keeps the
scores as computed by the query.</p>
<p><p>
This rewrite method only uses the top scoring terms so it will not overflow
the boolean max clause count.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanNearPayloadCheckQuery.html">SpanNearPayloadCheckQuery</a></h4>
<section><p>Only return those matches that have a specific payload at
the given position.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a></h4>
<section><p>Matches spans which are near one another. One can specify <em>slop</em>, the
maximum number of intervening unmatched positions, as well as whether
matches are required to be in-order.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanNotQuery.html">SpanNotQuery</a></h4>
<section><p>Removes matches which overlap with another <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> or
within a x tokens before or y tokens after another <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a>.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanOrQuery.html">SpanOrQuery</a></h4>
<section><p>Matches the union of its clauses. </p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanPayloadCheckQuery.html">SpanPayloadCheckQuery</a></h4>
<section><p>Only return those matches that have a specific payload at
the given position.
<p>
Do not use this with a <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> that contains a <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a>. Instead, use
<a class="xref" href="Lucene.Net.Search.Spans.SpanNearPayloadCheckQuery.html">SpanNearPayloadCheckQuery</a> since it properly handles the fact that payloads
aren&apos;t ordered by <a class="xref" href="Lucene.Net.Search.Spans.SpanNearQuery.html">SpanNearQuery</a>.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanPositionCheckQuery.html">SpanPositionCheckQuery</a></h4>
<section><p>Base class for filtering a <a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a> based on the position of a match.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanPositionCheckQuery.PositionCheckSpan.html">SpanPositionCheckQuery.PositionCheckSpan</a></h4>
<section></section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanPositionRangeQuery.html">SpanPositionRangeQuery</a></h4>
<section><p>Checks to see if the <a class="xref" href="Lucene.Net.Search.Spans.SpanPositionCheckQuery.html#Lucene_Net_Search_Spans_SpanPositionCheckQuery_Match">Match</a> lies between a start and end position</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanQuery.html">SpanQuery</a></h4>
<section><p>Base class for span-based queries. </p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanRewriteMethod.html">SpanRewriteMethod</a></h4>
<section><p>Abstract class that defines how the query is rewritten. </p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.Spans.html">Spans</a></h4>
<section><p>Expert: an enumeration of span matches. Used to implement span searching.
Each span represents a range of term positions within a document. Matches
are enumerated in order, by increasing document number, within that by
increasing start position and finally by increasing end position.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanScorer.html">SpanScorer</a></h4>
<section><p>Public for extension only.</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanTermQuery.html">SpanTermQuery</a></h4>
<section><p>Matches spans containing a term. </p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanWeight.html">SpanWeight</a></h4>
<section><p>Expert-only. Public for use by other weight implementations</p>
</section>
<h4><a class="xref" href="Lucene.Net.Search.Spans.TermSpans.html">TermSpans</a></h4>
<section><p>Expert:
Public for extension only</p>
</section>
<h3 id="interfaces">Interfaces
</h3>
<h4><a class="xref" href="Lucene.Net.Search.Spans.ISpanMultiTermQueryWrapper.html">ISpanMultiTermQueryWrapper</a></h4>
<section><p>LUCENENET specific interface for referring to/identifying a <a class="xref" href="Lucene.Net.Search.Spans.SpanMultiTermQueryWrapper-1.html">SpanMultiTermQueryWrapper&lt;Q&gt;</a> without
referring to its generic closing type.</p>
</section>
<h3 id="enums">Enums
</h3>
<h4><a class="xref" href="Lucene.Net.Search.Spans.SpanPositionCheckQuery.AcceptStatus.html">SpanPositionCheckQuery.AcceptStatus</a></h4>
<section><p>Return value for <a class="xref" href="Lucene.Net.Search.Spans.SpanPositionCheckQuery.html#Lucene_Net_Search_Spans_SpanPositionCheckQuery_AcceptPosition_Lucene_Net_Search_Spans_Spans_">AcceptPosition(Spans)</a>.</p>
</section>
</article>
</div>
<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
<li>
<a href="https://github.com/apache/lucenenet/blob/docs/4.8.0-beta00013/src/Lucene.Net/Search/Spans/package.md/#L2" class="contribution-link">Improve this Doc</a>
</li>
</ul>
</div>
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
</nav>
</div>
</div>
</div>
</div>
<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
Copyright © 2020 The Apache Software Foundation, Licensed under the <a href='http://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache License, Version 2.0</a><br> <small>Apache Lucene.Net, Lucene.Net, Apache, the Apache feather logo, and the Apache Lucene.Net project logo are trademarks of The Apache Software Foundation. <br>All other marks mentioned may be trademarks or registered trademarks of their respective owners.</small>
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.vendor.js"></script>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/docfx.js"></script>
<script type="text/javascript" src="https://lucenenet.apache.org/docs/4.8.0-beta00009/styles/main.js"></script>
</body>
</html>