blob: 0b054e22e343cd1109dc36bcafaaeac3c3333117 [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>Lucene.Net.QueryParser | Apache Lucene.NET 4.8.0-beta00013 Documentation </title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="Lucene.Net.QueryParser | 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="queryparser/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.QueryParser">
<h1 id="" data-uid="Lucene.Net.QueryParser" class="text-break">Lucene.Net.QueryParser</h1>
<!--
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> Apache Lucene QueryParsers.</p>
<p> This module provides a number of queryparsers:</p>
<ul>
<li><p><a href="#classic">Classic</a></p>
</li>
<li><p><a href="#analyzing">Analyzing</a></p>
</li>
<li><p><a href="#complexphrase">Complex Phrase</a></p>
</li>
<li><p><a href="#extendable">Extendable</a></p>
</li>
<li><p><a href="#flexible">Flexible</a></p>
</li>
<li><p><a href="#surround">Surround</a></p>
</li>
<li><p><a href="#xml">XML</a></p>
</li>
</ul>
<hr>
<h2 id="classic"><a href="">Classic</a></h2>
<p> A Simple Lucene QueryParser implemented with JavaCC.</p>
<h2 id="analyzing"><a href="">Analyzing</a></h2>
<p> QueryParser that passes Fuzzy-, Prefix-, Range-, and WildcardQuerys through the given analyzer.</p>
<h2 id="complex-phrase"><a href="">Complex Phrase</a></h2>
<p> QueryParser which permits complex phrase query syntax eg &quot;(john jon jonathan~) peters*&quot;</p>
<h2 id="extendable"><a href="">Extendable</a></h2>
<p> Extendable QueryParser provides a simple and flexible extension mechanism by overloading query field names.</p>
<h2 id="flexible"><a href="">Flexible</a></h2>
<p> This project contains the new Lucene query parser implementation, which matches the syntax of the core QueryParser but offers a more modular architecture to enable customization. </p>
<p> It&#39;s currently divided in 2 main packages: * <a class="xref" href="Lucene.Net.QueryParsers.Flexible.Core.html">Lucene.Net.QueryParsers.Flexible.Core</a>: it contains the query parser API classes, which should be extended by query parser implementations. * <a class="xref" href="Lucene.Net.QueryParsers.Flexible.Standard.html">Lucene.Net.QueryParsers.Flexible.Standard</a>: it contains the current Lucene query parser implementation using the new query parser API. </p>
<h3 id="features">Features</h3>
<ol>
<li><p>Full support for boolean logic (not enabled)</p>
</li>
<li><p>QueryNode Trees - support for several syntaxes,
that can be converted into similar syntax QueryNode trees.</p>
</li>
<li><p>QueryNode Processors - Optimize, validate, rewrite the
QueryNode trees</p>
</li>
<li><p>Processors Pipelines - Select your favorite Processor
and build a processor pipeline, to implement the features you need</p>
</li>
<li><p>Config Interfaces - Allow the consumer of the Query Parser to implement
a diff Config Handler Objects to suite their needs.</p>
</li>
<li><p>Standard Builders - convert QueryNode&#39;s into several lucene
representations. Supported conversion is using a 2.4 compatible logic</p>
</li>
<li><p>QueryNode tree&#39;s can be converted to a lucene 2.4 syntax string, using toQueryString </p>
</li>
</ol>
<h3 id="design">Design</h3>
<p> This new query parser was designed to have very generic architecture, so that it can be easily used for different products with varying query syntaxes. This code is much more flexible and extensible than the Lucene query parser in 2.4.X. </p>
<p> The new query parser goal is to separate syntax and semantics of a query. E.g. &#39;a AND b&#39;, &#39;+a +b&#39;, &#39;AND(a,b)&#39; could be different syntaxes for the same query. It distinguishes the semantics of the different query components, e.g. whether and how to tokenize/lemmatize/normalize the different terms or which Query objects to create for the terms. It allows to write a parser with a new syntax, while reusing the underlying semantics, as quickly as possible. </p>
<p> The query parser has three layers and its core is what we call the QueryNode tree. It is a tree that initially represents the syntax of the original query, e.g. for &#39;a AND b&#39;: </p>
<pre><code> AND
/ \
A B
</code></pre><p> The three layers are: </p>
<dl>
<dt>QueryParser</dt>
<dd>
This layer is the text parsing layer which simply transforms the
query text string into a <a class="xref" href="Lucene.Net.QueryParsers.Flexible.Core.Nodes.QueryNode.html">QueryNode</a> tree. Every text parser
must implement the interface &lt;xref:Lucene.Net.QueryParsers.Flexible.Core.Parser.SyntaxParser&gt;.
Lucene default implementations implements it using JavaCC.
</dd>
<dt>QueryNodeProcessor</dt>
<dd>The query node processors do most of the work. It is in fact a
configurable chain of processors. Each processors can walk the tree and
modify nodes or even the tree&#39;s structure. That makes it possible to
e.g. do query optimization before the query is executed or to tokenize
terms.
</dd>
<dt>QueryBuilder</dt>
<dd>
The third layer is a configurable map of builders, which map <a class="xref" href="Lucene.Net.QueryParsers.Flexible.Core.Nodes.QueryNode.html">QueryNode</a> types to its specific
builder that will transform the QueryNode into Lucene Query object.
</dd>
</dl>
<p> Furthermore, the query parser uses flexible configuration objects. It also uses message classes that allow to attach resource bundles. This makes it possible to translate messages, which is an important feature of a query parser. </p>
<p> This design allows to develop different query syntaxes very quickly. </p>
<h3 id="standardqueryparser-and-queryparserwrapper">StandardQueryParser and QueryParserWrapper</h3>
<p>The classic Lucene query parser is located under
<a class="xref" href="Lucene.Net.QueryParsers.Classic.html">Lucene.Net.QueryParsers.Classic</a>.</p>
<p>To make it simpler to use the new query parser
the class <a class="xref" href="Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser.html">StandardQueryParser</a> may be helpful,
specially for people that do not want to extend the Query Parser.
It uses the default Lucene query processors, text parser and builders, so
you don&#39;t need to worry about dealing with those.</p>
<p><a class="xref" href="Lucene.Net.QueryParsers.Flexible.Standard.StandardQueryParser.html">StandardQueryParser</a> usage:</p>
<pre><code> StandardQueryParser qpHelper = new StandardQueryParser();
StandardQueryConfigHandler config = qpHelper.getQueryConfigHandler();
config.setAllowLeadingWildcard(true);
config.setAnalyzer(new WhitespaceAnalyzer());
Query query = qpHelper.parse(&quot;apache AND lucene&quot;, &quot;defaultField&quot;);
</code></pre><h2 id="surround"><a href="">Surround</a></h2>
<p> A QueryParser that supports the Span family of queries as well as pre and infix notation. </p>
<h2 id="xml"><a href="">XML</a></h2>
<p>A QueryParser that produces Lucene Query objects from XML streams.</p>
</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.QueryParser/overview.md/#L1" 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>