You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2006/06/04 04:41:25 UTC
svn commit: r411501 [14/30] - in /incubator/lucene.net/trunk/C#/src: ./
Demo/DeleteFiles/ Demo/DemoLib/ Demo/DemoLib/HTML/ Demo/IndexFiles/
Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/
Lucene.Net/Analysis/Standard/ Lucene.Net/Docu...
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/LucenePackage.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/LucenePackage.cs?rev=411501&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/LucenePackage.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/LucenePackage.cs Sat Jun 3 19:41:13 2006
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+using System;
+
+namespace Lucene.Net
+{
+
+ /// <summary>Lucene's package information, including version. *</summary>
+ public sealed class LucenePackage
+ {
+
+ private LucenePackage()
+ {
+ } // can't construct
+
+ /// <summary>Return Lucene's package, including version information. </summary>
+ // {{Aroush-1.9}}
+ //// public static Package Get()
+ //// {
+ //// return typeof(LucenePackage).getPackage();
+ //// }
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Overview.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Overview.html?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Overview.html (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Overview.html Sat Jun 3 19:41:13 2006
@@ -1,33 +1,65 @@
<html>
<head>
- <title>Jakarta Lucene API</title>
+ <title>Apache Lucene API</title>
</head>
<body>
-Jakarta Lucene is a high-performance, full-featured text search engine library.
-The API is divided into several packages:
+<p>Apache Lucene is a high-performance, full-featured text search engine library.
+Here's a simple example how to use Lucene for indexing and searching (using JUnit
+to check if the results are what we expect):</p>
+
+<!-- ======================================================== -->
+<!-- = Java Sourcecode to HTML automatically converted code = -->
+<!-- = Java2Html Converter V4.1 2004 by Markus Gebhard markus@jave.de = -->
+<!-- = Further information: http://www.java2html.de = -->
+<div align="left" class="java">
+<table border="0" cellpadding="3" cellspacing="0" bgcolor="#ffffff">
+ <tr>
+ <!-- start source code -->
+ <td nowrap="nowrap" valign="top" align="left">
+ <code>
+<font color="#ffffff"> </font><font color="#000000">Analyzer analyzer = </font><font color="#7f0055"><b>new </b></font><font color="#000000">StandardAnalyzer</font><font color="#000000">()</font><font color="#000000">;</font><br/>
+<font color="#ffffff"></font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// Store the index in memory:</font><br/>
+<font color="#ffffff"> </font><font color="#000000">Directory directory = </font><font color="#7f0055"><b>new </b></font><font color="#000000">RAMDirectory</font><font color="#000000">()</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// To store an index on disk, use this instead (note that the </font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// parameter true will overwrite the index in that directory</font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// if one exists):</font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);</font><br/>
+<font color="#ffffff"> </font><font color="#000000">IndexWriter iwriter = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexWriter</font><font color="#000000">(</font><font color="#000000">directory, analyzer, </font><font color="#7f0055"><b>true</b></font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">iwriter.setMaxFieldLength</font><font color="#000000">(</font><font color="#990000">25000</font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">Document doc = </font><font color="#7f0055"><b>new </b></font><font color="#000000">Document</font><font color="#000000">()</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">String text = </font><font color="#2a00ff">"This is the text to be indexed."</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">doc.add</font><font color="#000000">(</font><font color="#7f0055"><b>new </b></font><font color="#000000">Field</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">, text, Field.Store.YES,</font><br/>
+<font color="#ffffff"> </font><font color="#000000">Field.Index.TOKENIZED</font><font color="#000000">))</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">iwriter.addDocument</font><font color="#000000">(</font><font color="#000000">doc</font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">iwriter.close</font><font color="#000000">()</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// Now search the index:</font><br/>
+<font color="#ffffff"> </font><font color="#000000">IndexSearcher isearcher = </font><font color="#7f0055"><b>new </b></font><font color="#000000">IndexSearcher</font><font color="#000000">(</font><font color="#000000">directory</font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// Parse a simple query that searches for "text":</font><br/>
+<font color="#ffffff"> </font><font color="#000000">Query query = QueryParser.parse</font><font color="#000000">(</font><font color="#2a00ff">"text"</font><font color="#000000">, </font><font color="#2a00ff">"fieldname"</font><font color="#000000">, analyzer</font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">Hits hits = isearcher.search</font><font color="#000000">(</font><font color="#000000">query</font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">assertEquals</font><font color="#000000">(</font><font color="#990000">1</font><font color="#000000">, hits.length</font><font color="#000000">())</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#3f7f5f">// Iterate through the results:</font><br/>
+<font color="#ffffff"> </font><font color="#7f0055"><b>for </b></font><font color="#000000">(</font><font color="#7f0055"><b>int </b></font><font color="#000000">i = </font><font color="#990000">0</font><font color="#000000">; i < hits.length</font><font color="#000000">()</font><font color="#000000">; i++</font><font color="#000000">) {</font><br/>
+<font color="#ffffff"> </font><font color="#000000">Document hitDoc = hits.doc</font><font color="#000000">(</font><font color="#000000">i</font><font color="#000000">)</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">assertEquals</font><font color="#000000">(</font><font color="#2a00ff">"This is the text to be indexed."</font><font color="#000000">, hitDoc.get</font><font color="#000000">(</font><font color="#2a00ff">"fieldname"</font><font color="#000000">))</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">}</font><br/>
+<font color="#ffffff"> </font><font color="#000000">isearcher.close</font><font color="#000000">()</font><font color="#000000">;</font><br/>
+<font color="#ffffff"> </font><font color="#000000">directory.close</font><font color="#000000">()</font><font color="#000000">;</font></code>
+
+ </td>
+ <!-- end source code -->
+ </tr>
+</table>
+</div>
+<!-- = END of automatically generated HTML code = -->
+<!-- ======================================================== -->
-<ul>
-<li>
-<b><a href = "org/apache/lucene/util/package-summary.html">org.apache.lucene.util</a></b>
-contains a few handy data structures, e.g., <a href = "org/apache/lucene/util/BitVector.html">BitVector</a>
-and <a href = "org/apache/lucene/util/PriorityQueue.html">PriorityQueue</a>.</li>
-
-<li>
-<b><a href = "org/apache/lucene/store/package-summary.html">org.apache.lucene.store</a></b>
-defines an abstract class for storing persistent data, the <a href = "org/apache/lucene/store/Directory.html">Directory</a>,
-a collection of named files written by an <a href = "org/apache/lucene/store/OutputStream.html">OutputStream</a>
-and read by an <a href = "org/apache/lucene/store/InputStream.html">InputStream</a>.
-Two implementations are provided, <a href = "org/apache/lucene/store/FSDirectory.html">FSDirectory</a>,
-which uses a file system directory to store files, and <a href = "org/apache/lucene/store/RAMDirectory.html">RAMDirectory</a>
-which implements files as memory-resident data structures.</li>
-
-<li>
-<b><a href = "org/apache/lucene/document/package-summary.html">org.apache.lucene.document</a></b>
-provides a simple <a href = "org/apache/lucene/document/Document.html">Document</a>
-class. A document is simply a set of named <a href = "org/apache/lucene/document/Field.html">Field</a>'s,
-whose values may be strings or instances of <a href = "http://java.sun.com//jsp/products/jdk/1.2/docs/api/java/io/Reader.html">java.io.Reader</a>.</li>
+<p>The Lucene API is divided into several packages:</p>
+<ul>
<li>
<b><a href = "org/apache/lucene/analysis/package-summary.html">org.apache.lucene.analysis</a></b>
defines an abstract <a href = "org/apache/lucene/analysis/Analyzer.html">Analyzer</a>
@@ -40,6 +72,12 @@
and the grammar-based <a href = "org/apache/lucene/analysis/standard/StandardAnalyzer.html">StandardAnalyzer</a>.</li>
<li>
+<b><a href = "org/apache/lucene/document/package-summary.html">org.apache.lucene.document</a></b>
+provides a simple <a href = "org/apache/lucene/document/Document.html">Document</a>
+class. A document is simply a set of named <a href = "org/apache/lucene/document/Field.html">Field</a>'s,
+whose values may be strings or instances of <a href = "http://java.sun.com//jsp/products/jdk/1.2/docs/api/java/io/Reader.html">java.io.Reader</a>.</li>
+
+<li>
<b><a href = "org/apache/lucene/index/package-summary.html">org.apache.lucene.index</a></b>
provides two primary classes: <a href = "org/apache/lucene/index/IndexWriter.html">IndexWriter</a>,
which creates and adds documents to indices; and <a href = "org/apache/lucene/index/IndexReader.html">IndexReader</a>,
@@ -59,17 +97,31 @@
<b><a href = "org/apache/lucene/queryParser/package-summary.html">org.apache.lucene.queryParser</a></b>
uses <a href = "http://javacc.dev.java.net">JavaCC</a> to implement a
<a href = "org/apache/lucene/queryParser/QueryParser.html">QueryParser</a>.</li>
+
+<li>
+<b><a href = "org/apache/lucene/store/package-summary.html">org.apache.lucene.store</a></b>
+defines an abstract class for storing persistent data, the <a href = "org/apache/lucene/store/Directory.html">Directory</a>,
+a collection of named files written by an <a href = "org/apache/lucene/store/IndexOutput.html">IndexOutput</a>
+and read by an <a href = "org/apache/lucene/store/IndexInput.html">IndexInput</a>.
+Two implementations are provided, <a href = "org/apache/lucene/store/FSDirectory.html">FSDirectory</a>,
+which uses a file system directory to store files, and <a href = "org/apache/lucene/store/RAMDirectory.html">RAMDirectory</a>
+which implements files as memory-resident data structures.</li>
+
+<li>
+<b><a href = "org/apache/lucene/util/package-summary.html">org.apache.lucene.util</a></b>
+contains a few handy data structures, e.g., <a href = "org/apache/lucene/util/BitVector.html">BitVector</a>
+and <a href = "org/apache/lucene/util/PriorityQueue.html">PriorityQueue</a>.</li>
</ul>
To use Lucene, an application should:
<ol>
<li>
Create <a href = "org/apache/lucene/document/Document.html">Document</a>'s by
adding
-<a href = "org/apache/lucene/document/Field.html">Field</a>'s.</li>
+<a href = "org/apache/lucene/document/Field.html">Field</a>'s;</li>
<li>
Create an <a href = "org/apache/lucene/index/IndexWriter.html">IndexWriter</a>
-and add documents to to it with <a href = "org/apache/lucene/index/IndexWriter.html#addDocument(org.apache.lucene.document.Document)">addDocument()</a>;</li>
+and add documents to it with <a href = "org/apache/lucene/index/IndexWriter.html#addDocument(org.apache.lucene.document.Document)">addDocument()</a>;</li>
<li>
Call <a href = "org/apache/lucene/queryParser/QueryParser.html#parse(java.lang.String)">QueryParser.parse()</a>
@@ -83,53 +135,43 @@
Some simple examples of code which does this are:
<ul>
<li>
- <a href = "src/demo/org/apache/lucene/demo/FileDocument.java">FileDocument.java</a> contains
+ <a href = "http://svn.apache.org//jsp/repos/asf/lucene/java/trunk/src/demo/org/apache/lucene/demo/FileDocument.java">FileDocument.java</a> contains
code to create a Document for a file.</li>
<li>
- <a href = "src/demo/org/apache/lucene/demo/IndexFiles.java">IndexFiles.java</a> creates an
+ <a href = "http://svn.apache.org//jsp/repos/asf/lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexFiles.java">IndexFiles.java</a> creates an
index for all the files contained in a directory.</li>
<li>
- <a href = "src/demo/org/apache/lucene/demo/DeleteFiles.java">DeleteFiles.java</a> deletes some
+ <a href = "http://svn.apache.org//jsp/repos/asf/lucene/java/trunk/src/demo/org/apache/lucene/demo/DeleteFiles.java">DeleteFiles.java</a> deletes some
of these files from the index.</li>
<li>
- <a href = "src/demo/org/apache/lucene/demo/SearchFiles.java">SearchFiles.java</a> prompts for
+ <a href = "http://svn.apache.org//jsp/repos/asf/lucene/java/trunk/src/demo/org/apache/lucene/demo/SearchFiles.java">SearchFiles.java</a> prompts for
queries and searches an index.</li>
</ul>
To demonstrate these, try something like:
<blockquote><tt>> <b>java -cp lucene.jar:lucene-demo.jar org.apache.lucene.demo.IndexFiles rec.food.recipes/soups</b></tt>
<br><tt>adding rec.food.recipes/soups/abalone-chowder</tt>
<br><tt> </tt>[ ... ]
+
<p><tt>> <b>java -cp lucene.jar:lucene-demo.jar org.apache.lucene.demo.SearchFiles</b></tt>
<br><tt>Query: <b>chowder</b></tt>
<br><tt>Searching for: chowder</tt>
<br><tt>34 total matching documents</tt>
-<br><tt>0. rec.food.recipes/soups/spam-chowder</tt>
-<br><tt> </tt>[ ... thirty-four documents contain the word "chowder",
-"spam-chowder" with the greatest density.]
-<p><tt>Query: <b>path:chowder</b></tt>
-<br><tt>Searching for: path:chowder</tt>
-<br><tt>31 total matching documents</tt>
-<br><tt>0. rec.food.recipes/soups/abalone-chowder</tt>
-<br><tt> </tt>[ ... only thrity-one have "chowder" in the "path"
-field. ]
-<p><tt>Query: <b>path:"clam chowder"</b></tt>
-<br><tt>Searching for: path:"clam chowder"</tt>
-<br><tt>10 total matching documents</tt>
-<br><tt>0. rec.food.recipes/soups/clam-chowder</tt>
-<br><tt> </tt>[ ... only ten have "clam chowder" in the "path" field.
-]
-<p><tt>Query: <b>path:"clam chowder" AND manhattan</b></tt>
-<br><tt>Searching for: +path:"clam chowder" +manhattan</tt>
+<br><tt>1. rec.food.recipes/soups/spam-chowder</tt>
+<br><tt> </tt>[ ... thirty-four documents contain the word "chowder" ... ]
+
+<p><tt>Query: <b>"clam chowder" AND Manhattan</b></tt>
+<br><tt>Searching for: +"clam chowder" +manhattan</tt>
<br><tt>2 total matching documents</tt>
-<br><tt>0. rec.food.recipes/soups/clam-chowder</tt>
-<br><tt> </tt>[ ... only two also have "manhattan" in the contents.
-]
+<br><tt>1. rec.food.recipes/soups/clam-chowder</tt>
+<br><tt> </tt>[ ... two documents contain the phrase "clam chowder"
+and the word "manhattan" ... ]
<br> [ Note: "+" and "-" are canonical, but "AND", "OR"
and "NOT" may be used. ]</blockquote>
-The <a href = "src/demo/org/apache/lucene/demo/IndexHTML.java">IndexHtml</a> demo is more sophisticated.
+
+The <a href = "http://svn.apache.org//jsp/repos/asf/lucene/java/trunk/src/demo/org/apache/lucene/demo/IndexHTML.java">IndexHtml</a> demo is more sophisticated.
It incrementally maintains an index of HTML files, adding new files as
they appear, deleting old files as they disappear and re-indexing files
as they change.
@@ -139,31 +181,6 @@
<p><tt>> <b>rm java/jdk1.1.6/docs/relnotes/smicopyright.html</b></tt>
<p><tt>> <b>java -cp lucene.jar:lucene-demo.jar org.apache.lucene.demo.IndexHTML java/jdk1.1.6/docs/relnotes</b></tt>
<br><tt>deleting java/jdk1.1.6/docs/relnotes/SMICopyright.html</tt></blockquote>
-HTML indexes are searched using SUN's <a href = "http://jserv.javasoft.com//jsp/products/webserver/index.html">JavaWebServer</a>
-(JWS) and <a href = "src/demo/Search.jhtml">Search.jhtml</a>. To use
-this:
-<ul>
-<li>
-copy <tt>Search.html</tt> and <tt>Search.jhtml</tt> to JWS's <tt>public_html</tt>
-directory;</li>
-
-<li>
-copy lucene.jar to JWS's lib directory;</li>
-<li>
-create and maintain your indexes with demo.IndexHTML in JWS's top-level
-directory;</li>
-
-<li>
-launch JWS, with the <tt>demo</tt> directory on CLASSPATH (only one class
-is actually needed);</li>
-
-<li>
-visit <a href = "src/demo/Search.html">Search.html</a>.</li>
-</ul>
-Note that indexes can be updated while searches are going on. <tt>Search.jhtml</tt>
-will re-open the index when it is updated so that the latest version is
-immediately available.
-<br>
</body>
</html>
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Package.html?rev=411501&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Package.html (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Package.html Sat Jun 3 19:41:13 2006
@@ -0,0 +1 @@
+<html><body>Top-level package.</body></html>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/CharStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/QueryParser/CharStream.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/CharStream.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/CharStream.cs Sat Jun 3 19:41:13 2006
@@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
/* Generated By:JavaCC: Do not edit this line. CharStream.java Version 3.0 */
+
using System;
+
namespace Lucene.Net.QueryParsers
{
@@ -44,17 +47,17 @@
/// <summary> Returns the column position of the character last read.</summary>
/// <deprecated>
/// </deprecated>
- /// <seealso cref="#getEndColumn">
+ /// <seealso cref="getEndColumn">
/// </seealso>
int GetColumn();
/// <summary> Returns the line number of the character last read.</summary>
/// <deprecated>
/// </deprecated>
- /// <seealso cref="#getEndLine">
+ /// <seealso cref="getEndLine">
/// </seealso>
int GetLine();
-
+
/// <summary> Returns the column number of the last character for current token (being
/// matched after the last call to BeginTOken).
/// </summary>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/FastCharStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/QueryParser/FastCharStream.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/FastCharStream.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/FastCharStream.cs Sat Jun 3 19:41:13 2006
@@ -13,14 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
using System;
+
namespace Lucene.Net.QueryParsers
{
/// <summary>An efficient implementation of JavaCC's CharStream interface. <p>Note that
/// this does not do line-number counting, but instead keeps track of the
/// character position of the token in the input, as required by Lucene's {@link
- /// Lucene.Net.Analysis.Token} API.
+ /// Lucene.Net.analysis.Token} API.
/// </summary>
public sealed class FastCharStream : CharStream
{
@@ -77,17 +79,17 @@
bufferPosition = newPosition;
bufferStart += tokenStart;
tokenStart = 0;
+
+ int charsRead = 0;
- int charsRead = 0;
-
- try
- {
+ try
+ {
charsRead = input.Read(buffer, newPosition, buffer.Length - newPosition);
}
- catch
- {
- }
-
+ catch
+ {
+ }
+
if (charsRead <= 0)
throw new System.IO.IOException("read past eof");
else
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/MultiFieldQueryParser.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/QueryParser/MultiFieldQueryParser.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/MultiFieldQueryParser.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/MultiFieldQueryParser.cs Sat Jun 3 19:41:13 2006
@@ -13,47 +13,202 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
using System;
using Analyzer = Lucene.Net.Analysis.Analyzer;
+using BooleanClause = Lucene.Net.Search.BooleanClause;
using BooleanQuery = Lucene.Net.Search.BooleanQuery;
+using MultiPhraseQuery = Lucene.Net.Search.MultiPhraseQuery;
+using PhraseQuery = Lucene.Net.Search.PhraseQuery;
using Query = Lucene.Net.Search.Query;
+
namespace Lucene.Net.QueryParsers
{
/// <summary> A QueryParser which constructs queries to search multiple fields.
///
/// </summary>
- /// <author> <a href="mailto:kelvin@relevanz.com">Kelvin Tan</a>
+ /// <author> <a href="mailto:kelvin@relevanz.com">Kelvin Tan</a>, Daniel Naber
/// </author>
- /// <version> $Revision: 1.4 $
+ /// <version> $Revision: 295117 $
/// </version>
public class MultiFieldQueryParser : QueryParser
{
+
+ private System.String[] fields;
+
+ /// <summary> Creates a MultiFieldQueryParser.
+ ///
+ /// <p>It will, when parse(String query)
+ /// is called, construct a query like this (assuming the query consists of
+ /// two terms and you specify the two fields <code>title</code> and <code>body</code>):</p>
+ ///
+ /// <code>
+ /// (title:term1 body:term1) (title:term2 body:term2)
+ /// </code>
+ ///
+ /// <p>When setDefaultOperator(AND_OPERATOR) is set, the result will be:</p>
+ ///
+ /// <code>
+ /// +(title:term1 body:term1) +(title:term2 body:term2)
+ /// </code>
+ ///
+ /// <p>In other words, all the query's terms must appear, but it doesn't matter in
+ /// what fields they appear.</p>
+ /// </summary>
+ public MultiFieldQueryParser(System.String[] fields, Analyzer analyzer) : base(null, analyzer)
+ {
+ this.fields = fields;
+ }
+
+ protected internal override Query GetFieldQuery(System.String field, System.String queryText, int slop)
+ {
+ if (field == null)
+ {
+ System.Collections.ArrayList clauses = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
+ for (int i = 0; i < fields.Length; i++)
+ {
+ Query q = base.GetFieldQuery(fields[i], queryText);
+ if (q != null)
+ {
+ if (q is PhraseQuery)
+ {
+ ((PhraseQuery) q).SetSlop(slop);
+ }
+ if (q is MultiPhraseQuery)
+ {
+ ((MultiPhraseQuery) q).SetSlop(slop);
+ }
+ clauses.Add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
+ }
+ }
+ if (clauses.Count == 0)
+ // happens for stopwords
+ return null;
+ return GetBooleanQuery(clauses, true);
+ }
+ return base.GetFieldQuery(field, queryText);
+ }
+
+
+ protected internal override Query GetFieldQuery(System.String field, System.String queryText)
+ {
+ return GetFieldQuery(field, queryText, 0);
+ }
+
+ /// <deprecated> use {@link #GetFieldQuery(String, String)}
+ /// </deprecated>
+ protected internal override Query GetFieldQuery(System.String field, Analyzer analyzer, System.String queryText)
+ {
+ return GetFieldQuery(field, queryText);
+ }
+
+ /// <deprecated> use {@link #GetFuzzyQuery(String, String, float)}
+ /// </deprecated>
+ protected internal override Query GetFuzzyQuery(System.String field, System.String termStr)
+ {
+ return GetFuzzyQuery(field, termStr, fuzzyMinSim);
+ }
+
+ protected internal override Query GetFuzzyQuery(System.String field, System.String termStr, float minSimilarity)
+ {
+ if (field == null)
+ {
+ System.Collections.ArrayList clauses = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
+ for (int i = 0; i < fields.Length; i++)
+ {
+ clauses.Add(new BooleanClause(base.GetFuzzyQuery(fields[i], termStr, minSimilarity), BooleanClause.Occur.SHOULD));
+ }
+ return GetBooleanQuery(clauses, true);
+ }
+ return base.GetFuzzyQuery(field, termStr, minSimilarity);
+ }
+
+ protected internal override Query GetPrefixQuery(System.String field, System.String termStr)
+ {
+ if (field == null)
+ {
+ System.Collections.ArrayList clauses = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
+ for (int i = 0; i < fields.Length; i++)
+ {
+ clauses.Add(new BooleanClause(base.GetPrefixQuery(fields[i], termStr), BooleanClause.Occur.SHOULD));
+ }
+ return GetBooleanQuery(clauses, true);
+ }
+ return base.GetPrefixQuery(field, termStr);
+ }
+
+ protected internal override Query GetWildcardQuery(System.String field, System.String termStr)
+ {
+ if (field == null)
+ {
+ System.Collections.ArrayList clauses = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
+ for (int i = 0; i < fields.Length; i++)
+ {
+ clauses.Add(new BooleanClause(base.GetWildcardQuery(fields[i], termStr), BooleanClause.Occur.SHOULD));
+ }
+ return GetBooleanQuery(clauses, true);
+ }
+ return base.GetWildcardQuery(field, termStr);
+ }
+
+ /// <throws> ParseException </throws>
+ /// <deprecated> use {@link #GetRangeQuery(String, String, String, boolean)}
+ /// </deprecated>
+ protected internal override Query GetRangeQuery(System.String field, Analyzer analyzer, System.String part1, System.String part2, bool inclusive)
+ {
+ return GetRangeQuery(field, part1, part2, inclusive);
+ }
+
+ protected internal override Query GetRangeQuery(System.String field, System.String part1, System.String part2, bool inclusive)
+ {
+ if (field == null)
+ {
+ System.Collections.ArrayList clauses = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
+ for (int i = 0; i < fields.Length; i++)
+ {
+ clauses.Add(new BooleanClause(base.GetRangeQuery(fields[i], part1, part2, inclusive), BooleanClause.Occur.SHOULD));
+ }
+ return GetBooleanQuery(clauses, true);
+ }
+ return base.GetRangeQuery(field, part1, part2, inclusive);
+ }
+
+
+ /// <deprecated>
+ /// </deprecated>
public const int NORMAL_FIELD = 0;
+ /// <deprecated>
+ /// </deprecated>
public const int REQUIRED_FIELD = 1;
+ /// <deprecated>
+ /// </deprecated>
public const int PROHIBITED_FIELD = 2;
+ /// <deprecated> use {@link #MultiFieldQueryParser(String[], Analyzer)} instead
+ /// </deprecated>
public MultiFieldQueryParser(QueryParserTokenManager tm):base(tm)
{
}
+ /// <deprecated> use {@link #MultiFieldQueryParser(String[], Analyzer)} instead
+ /// </deprecated>
public MultiFieldQueryParser(CharStream stream):base(stream)
{
}
+ /// <deprecated> use {@link #MultiFieldQueryParser(String[], Analyzer)} instead
+ /// </deprecated>
public MultiFieldQueryParser(System.String f, Analyzer a):base(f, a)
{
}
- /// <summary> <p>
- /// Parses a query which searches on the fields specified.
- /// <p>
+ /// <summary> Parses a query which searches on the fields specified.
/// If x fields are specified, this effectively constructs:
- /// <pre>
+ ///
/// <code>
/// (field1:query) (field2:query) (field3:query)...(fieldx:query)
/// </code>
- /// </pre>
///
/// </summary>
/// <param name="query">Query string to parse
@@ -64,28 +219,67 @@
/// </param>
/// <throws> ParseException if query parsing fails </throws>
/// <throws> TokenMgrError if query parsing fails </throws>
+ /// <deprecated> use {@link #Parse(String)} instead but note that it
+ /// returns a different query for queries where all terms are required:
+ /// its query excepts all terms, no matter in what field they occur whereas
+ /// the query built by this (deprecated) method expected all terms in all fields
+ /// at the same time.
+ /// </deprecated>
public static Query Parse(System.String query, System.String[] fields, Analyzer analyzer)
{
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
Query q = Parse(query, fields[i], analyzer);
- bQuery.Add(q, false, false);
+ bQuery.Add(q, BooleanClause.Occur.SHOULD);
+ }
+ return bQuery;
+ }
+
+ /// <summary> Parses a query which searches on the fields specified.
+ /// <p>
+ /// If x fields are specified, this effectively constructs:
+ /// <pre>
+ /// <code>
+ /// (field1:query1) (field2:query2) (field3:query3)...(fieldx:queryx)
+ /// </code>
+ /// </pre>
+ /// </summary>
+ /// <param name="queries">Queries strings to parse
+ /// </param>
+ /// <param name="fields">Fields to search on
+ /// </param>
+ /// <param name="analyzer">Analyzer to use
+ /// </param>
+ /// <throws> ParseException if query parsing fails </throws>
+ /// <throws> TokenMgrError if query parsing fails </throws>
+ /// <throws> IllegalArgumentException if the length of the queries array differs </throws>
+ /// <summary> from the length of the fields array
+ /// </summary>
+ public static Query Parse(System.String[] queries, System.String[] fields, Analyzer analyzer)
+ {
+ if (queries.Length != fields.Length)
+ throw new System.ArgumentException("queries.length != fields.length");
+ BooleanQuery bQuery = new BooleanQuery();
+ for (int i = 0; i < fields.Length; i++)
+ {
+ QueryParser qp = new QueryParser(fields[i], analyzer);
+ Query q = qp.Parse(queries[i]);
+ bQuery.Add(q, BooleanClause.Occur.SHOULD);
}
return bQuery;
}
- /// <summary> <p>
- /// Parses a query, searching on the fields specified.
+ /// <summary> Parses a query, searching on the fields specified.
/// Use this if you need to specify certain fields as required,
/// and others as prohibited.
/// <p><pre>
/// Usage:
/// <code>
/// String[] fields = {"filename", "contents", "description"};
- /// int[] flags = {MultiFieldQueryParser.NORMAL FIELD,
- /// MultiFieldQueryParser.REQUIRED FIELD,
- /// MultiFieldQueryParser.PROHIBITED FIELD,};
+ /// int[] flags = {MultiFieldQueryParser.NORMAL_FIELD,
+ /// MultiFieldQueryParser.REQUIRED_FIELD,
+ /// MultiFieldQueryParser.PROHIBITED_FIELD,};
/// parse(query, fields, flags, analyzer);
/// </code>
/// </pre>
@@ -108,29 +302,202 @@
/// </param>
/// <throws> ParseException if query parsing fails </throws>
/// <throws> TokenMgrError if query parsing fails </throws>
+ /// <throws> IllegalArgumentException if the length of the fields array differs </throws>
+ /// <summary> from the length of the flags array
+ /// </summary>
+ /// <deprecated> use {@link #Parse(String, String[], BooleanClause.Occur[], Analyzer)} instead
+ /// </deprecated>
public static Query Parse(System.String query, System.String[] fields, int[] flags, Analyzer analyzer)
{
+ if (fields.Length != flags.Length)
+ throw new System.ArgumentException("fields.length != flags.length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.Length; i++)
{
- Query q = Parse(query, fields[i], analyzer);
+ QueryParser qp = new QueryParser(fields[i], analyzer);
+ Query q = qp.Parse(query);
+ int flag = flags[i];
+ switch (flag)
+ {
+
+ case REQUIRED_FIELD:
+ bQuery.Add(q, BooleanClause.Occur.MUST);
+ break;
+
+ case PROHIBITED_FIELD:
+ bQuery.Add(q, BooleanClause.Occur.MUST_NOT);
+ break;
+
+ default:
+ bQuery.Add(q, BooleanClause.Occur.SHOULD);
+ break;
+
+ }
+ }
+ return bQuery;
+ }
+
+ /// <summary> Parses a query, searching on the fields specified.
+ /// Use this if you need to specify certain fields as required,
+ /// and others as prohibited.
+ /// <p><pre>
+ /// Usage:
+ /// <code>
+ /// String[] fields = {"filename", "contents", "description"};
+ /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
+ /// BooleanClause.Occur.MUST,
+ /// BooleanClause.Occur.MUST_NOT};
+ /// MultiFieldQueryParser.parse("query", fields, flags, analyzer);
+ /// </code>
+ /// </pre>
+ /// <p>
+ /// The code above would construct a query:
+ /// <pre>
+ /// <code>
+ /// (filename:query) +(contents:query) -(description:query)
+ /// </code>
+ /// </pre>
+ ///
+ /// </summary>
+ /// <param name="query">Query string to parse
+ /// </param>
+ /// <param name="fields">Fields to search on
+ /// </param>
+ /// <param name="flags">Flags describing the fields
+ /// </param>
+ /// <param name="analyzer">Analyzer to use
+ /// </param>
+ /// <throws> ParseException if query parsing fails </throws>
+ /// <throws> TokenMgrError if query parsing fails </throws>
+ /// <throws> IllegalArgumentException if the length of the fields array differs </throws>
+ /// <summary> from the length of the flags array
+ /// </summary>
+ public static Query Parse(System.String query, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
+ {
+ if (fields.Length != flags.Length)
+ throw new System.ArgumentException("fields.length != flags.length");
+ BooleanQuery bQuery = new BooleanQuery();
+ for (int i = 0; i < fields.Length; i++)
+ {
+ QueryParser qp = new QueryParser(fields[i], analyzer);
+ Query q = qp.Parse(query);
+ bQuery.Add(q, flags[i]);
+ }
+ return bQuery;
+ }
+
+ /// <summary> Parses a query, searching on the fields specified. Use this if you need to
+ /// specify certain fields as required, and others as prohibited.
+ /// <p>
+ /// <pre>
+ /// Usage:
+ /// <code>
+ /// String[] fields = { "filename", "contents", "description" };
+ /// int[] flags = { MultiFieldQueryParser.NORMAL_FIELD,
+ /// MultiFieldQueryParser.REQUIRED_FIELD,
+ /// MultiFieldQueryParser.PROHIBITED_FIELD, };
+ /// parse(query, fields, flags, analyzer);
+ /// </code>
+ /// </pre>
+ ///
+ /// <p>
+ /// The code above would construct a query:
+ /// <pre>
+ /// <code>
+ /// (filename:query1) +(contents:query2) -(description:query3)
+ /// </code>
+ /// </pre>
+ ///
+ /// </summary>
+ /// <param name="queries">Queries string to parse
+ /// </param>
+ /// <param name="fields">Fields to search on
+ /// </param>
+ /// <param name="flags">Flags describing the fields
+ /// </param>
+ /// <param name="analyzer">Analyzer to use
+ /// </param>
+ /// <throws> ParseException if query parsing fails </throws>
+ /// <throws> TokenMgrError if query parsing fails </throws>
+ /// <throws> IllegalArgumentException if the length of the queries, fields, and flags array differ </throws>
+ /// <deprecated> use {@link #Parse(String[], String[], BooleanClause.Occur[], Analyzer)} instead
+ /// </deprecated>
+ public static Query Parse(System.String[] queries, System.String[] fields, int[] flags, Analyzer analyzer)
+ {
+ if (!(queries.Length == fields.Length && queries.Length == flags.Length))
+ throw new System.ArgumentException("queries, fields, and flags array have have different length");
+ BooleanQuery bQuery = new BooleanQuery();
+ for (int i = 0; i < fields.Length; i++)
+ {
+ QueryParser qp = new QueryParser(fields[i], analyzer);
+ Query q = qp.Parse(queries[i]);
int flag = flags[i];
switch (flag)
{
case REQUIRED_FIELD:
- bQuery.Add(q, true, false);
+ bQuery.Add(q, BooleanClause.Occur.MUST);
break;
case PROHIBITED_FIELD:
- bQuery.Add(q, false, true);
+ bQuery.Add(q, BooleanClause.Occur.MUST_NOT);
break;
default:
- bQuery.Add(q, false, false);
+ bQuery.Add(q, BooleanClause.Occur.SHOULD);
break;
}
+ }
+ return bQuery;
+ }
+
+ /// <summary> Parses a query, searching on the fields specified.
+ /// Use this if you need to specify certain fields as required,
+ /// and others as prohibited.
+ /// <p><pre>
+ /// Usage:
+ /// <code>
+ /// String[] query = {"query1", "query2", "query3"};
+ /// String[] fields = {"filename", "contents", "description"};
+ /// BooleanClause.Occur[] flags = {BooleanClause.Occur.SHOULD,
+ /// BooleanClause.Occur.MUST,
+ /// BooleanClause.Occur.MUST_NOT};
+ /// MultiFieldQueryParser.parse(query, fields, flags, analyzer);
+ /// </code>
+ /// </pre>
+ /// <p>
+ /// The code above would construct a query:
+ /// <pre>
+ /// <code>
+ /// (filename:query1) +(contents:query2) -(description:query3)
+ /// </code>
+ /// </pre>
+ ///
+ /// </summary>
+ /// <param name="queries">Queries string to parse
+ /// </param>
+ /// <param name="fields">Fields to search on
+ /// </param>
+ /// <param name="flags">Flags describing the fields
+ /// </param>
+ /// <param name="analyzer">Analyzer to use
+ /// </param>
+ /// <throws> ParseException if query parsing fails </throws>
+ /// <throws> TokenMgrError if query parsing fails </throws>
+ /// <throws> IllegalArgumentException if the length of the queries, fields, </throws>
+ /// <summary> and flags array differ
+ /// </summary>
+ public static Query Parse(System.String[] queries, System.String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
+ {
+ if (!(queries.Length == fields.Length && queries.Length == flags.Length))
+ throw new System.ArgumentException("queries, fields, and flags array have have different length");
+ BooleanQuery bQuery = new BooleanQuery();
+ for (int i = 0; i < fields.Length; i++)
+ {
+ QueryParser qp = new QueryParser(fields[i], analyzer);
+ Query q = qp.Parse(queries[i]);
+ bQuery.Add(q, flags[i]);
}
return bQuery;
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/ParseException.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/QueryParser/ParseException.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/ParseException.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/QueryParser/ParseException.cs Sat Jun 3 19:41:13 2006
@@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
+
using System;
+
namespace Lucene.Net.QueryParsers
{
@@ -27,7 +30,7 @@
/// mechanisms so long as you retain the public fields.
/// </summary>
[Serializable]
- public class ParseException:System.Exception
+ public class ParseException : System.Exception
{
/// <summary> This method has the standard behavior when this object has been
/// created using the standard constructors. Otherwise, it uses