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 2007/05/01 20:45:35 UTC
svn commit: r534192 [16/19] - in /incubator/lucene.net/trunk/C#: ./ src/
src/Demo/ src/Demo/DeleteFiles/ src/Demo/DemoLib/ src/Demo/DemoLib/HTML/
src/Demo/IndexFiles/ src/Demo/IndexHtml/ src/Demo/SearchFiles/
src/Lucene.Net/ src/Lucene.Net/Analysis/ sr...
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitCollector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/HitCollector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitCollector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitCollector.cs Tue May 1 11:45:26 2007
@@ -24,9 +24,9 @@
/// <br>HitCollectors are primarily meant to be used to implement queries,
/// sorting and filtering.
/// </summary>
- /// <seealso cref="Searcher.Search(Query,HitCollector)">
+ /// <seealso cref="Searcher#Search(Query,HitCollector)">
/// </seealso>
- /// <version> $Id: HitCollector.java 155607 2005-02-27 01:29:53Z otis $
+ /// <version> $Id: HitCollector.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
public abstract class HitCollector
{
@@ -47,7 +47,7 @@
/// <p>Note: This is called in an inner search loop. For good search
/// performance, implementations of this method should not call
/// {@link Searcher#Doc(int)} or
- /// {@link Lucene.Net.index.IndexReader#Document(int)} on every
+ /// {@link Lucene.Net.Index.IndexReader#Document(int)} on every
/// document number encountered. Doing so can slow searches by an order
/// of magnitude or more.
/// <p>Note: The <code>score</code> passed to this method is a raw score.
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitIterator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/HitIterator.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitIterator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitIterator.cs Tue May 1 11:45:26 2007
@@ -21,7 +21,7 @@
{
/// <summary> An iterator over {@link Hits} that provides lazy fetching of each document.
- /// {@link Hits#Iterator()} returns an instance of this class. Calls to {@link #next()}
+ /// {@link Hits#Iterator()} returns an instance of this class. Calls to {@link #Next()}
/// return a {@link Hit} instance.
///
/// </summary>
@@ -67,7 +67,7 @@
///
/// </summary>
/// <throws> UnsupportedOperationException </throws>
- public virtual void Remove()
+ public virtual void remove()
{
throw new System.NotSupportedException();
}
@@ -77,11 +77,11 @@
{
return hits.Length();
}
-
- virtual public void Reset()
+
+ virtual public void Reset()
{
// {{Aroush-2.0}} what do we do here?!
throw new System.Exception("{{Aroush}} Reset() needs to be implemented");
- }
+ }
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/HitQueue.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitQueue.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/HitQueue.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using PriorityQueue = Lucene.Net.Util.PriorityQueue;
namespace Lucene.Net.Search
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Hits.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Hits.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Hits.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Hits.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Document = Lucene.Net.Documents.Document;
namespace Lucene.Net.Search
@@ -129,7 +130,7 @@
}
/// <summary> Returns a {@link HitIterator} to navigate the Hits. Each item returned
- /// from {@link Iterator#next()} is a {@link Hit}.
+ /// from {@link Iterator#Next()} is a {@link Hit}.
/// <p>
/// <b>Caution:</b> Iterate only over the hits needed. Iterating over all
/// hits is generally not desirable and may be the source of
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/IndexSearcher.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/IndexSearcher.cs Tue May 1 11:45:26 2007
@@ -16,10 +16,11 @@
*/
using System;
+
+using Directory = Lucene.Net.Store.Directory;
using Document = Lucene.Net.Documents.Document;
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
-using Directory = Lucene.Net.Store.Directory;
namespace Lucene.Net.Search
{
@@ -27,7 +28,7 @@
/// <summary>Implements search over a single IndexReader.
///
/// <p>Applications usually need only call the inherited {@link #Search(Query)}
- /// or {@link #Search(Query,Filter)} methods. For performance reasons it is
+ /// or {@link #search(Query,Filter)} methods. For performance reasons it is
/// recommended to open only one IndexSearcher and use it for all of your searches.
///
/// <p>Note that you can only access Hits from an IndexSearcher as long as it is
@@ -75,7 +76,7 @@
get { return reader; }
}
- /// <summary>Creates a searcher searching the index in the named directory. </summary>
+ /// <summary>Creates a searcher searching the index in the named directory. </summary>
public IndexSearcher(System.String path) : this(IndexReader.Open(path), true)
{
}
@@ -110,12 +111,7 @@
public override void Close()
{
if (closeReader)
- {
- FieldSortedHitQueue.Close(reader);
- Lucene.Net.Search.FieldCache_Fields.DEFAULT.Close(reader);
-
reader.Close();
- }
}
// inherit javadoc
@@ -140,23 +136,23 @@
public override TopDocs Search(Weight weight, Filter filter, int nDocs)
{
- if (nDocs <= 0)
- // null might be returned from hq.top() below.
- throw new System.ArgumentException("nDocs must be > 0");
+ if (nDocs <= 0)
+ // null might be returned from hq.top() below.
+ throw new System.ArgumentException("nDocs must be > 0");
- TopDocCollector collector = new TopDocCollector(nDocs);
- Search(weight, filter, collector);
- return collector.TopDocs();
- }
+ TopDocCollector collector = new TopDocCollector(nDocs);
+ Search(weight, filter, collector);
+ return collector.TopDocs();
+ }
// inherit javadoc
public override TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort)
{
- TopFieldDocCollector collector = new TopFieldDocCollector(reader, sort, nDocs);
- Search(weight, filter, collector);
- return (TopFieldDocs) collector.TopDocs();
- }
+ TopFieldDocCollector collector = new TopFieldDocCollector(reader, sort, nDocs);
+ Search(weight, filter, collector);
+ return (TopFieldDocs) collector.TopDocs();
+ }
// inherit javadoc
public override void Search(Weight weight, Filter filter, HitCollector results)
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MatchAllDocsQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/MatchAllDocsQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MatchAllDocsQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MatchAllDocsQuery.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
@@ -35,7 +36,7 @@
{
}
- private class MatchAllScorer:Scorer
+ private class MatchAllScorer : Scorer
{
private void InitBlock(MatchAllDocsQuery enclosingInstance)
{
@@ -52,18 +53,18 @@
}
internal IndexReader reader;
- internal int id;
+ internal int id;
internal int maxId;
- internal float score_Renamed_Field;
+ internal float score;
- internal MatchAllScorer(MatchAllDocsQuery enclosingInstance, IndexReader reader, Similarity similarity, Weight w) : base(similarity)
+ internal MatchAllScorer(MatchAllDocsQuery enclosingInstance, IndexReader reader, Similarity similarity, Weight w):base(similarity)
{
- InitBlock(enclosingInstance);
- this.reader = reader;
- id = - 1;
- maxId = reader.MaxDoc() - 1;
- score_Renamed_Field = w.GetValue();
- }
+ InitBlock(enclosingInstance);
+ this.reader = reader;
+ id = - 1;
+ maxId = reader.MaxDoc() - 1;
+ score = w.GetValue();
+ }
public override Explanation Explain(int doc)
{
@@ -90,13 +91,13 @@
public override float Score()
{
- return score_Renamed_Field;
+ return score;
}
public override bool SkipTo(int target)
{
- id = target - 1;
- return Next();
+ id = target - 1;
+ return Next();
}
}
@@ -116,14 +117,14 @@
}
}
- private Searcher searcher;
- private float queryWeight;
- private float queryNorm;
+ private Similarity similarity;
+ private float queryWeight;
+ private float queryNorm;
public MatchAllDocsWeight(MatchAllDocsQuery enclosingInstance, Searcher searcher)
{
InitBlock(enclosingInstance);
- this.searcher = searcher;
+ this.similarity = searcher.GetSimilarity();
}
public override System.String ToString()
@@ -143,32 +144,30 @@
public virtual float SumOfSquaredWeights()
{
- queryWeight = Enclosing_Instance.GetBoost();
- return queryWeight * queryWeight;
- }
+ queryWeight = Enclosing_Instance.GetBoost();
+ return queryWeight * queryWeight;
+ }
public virtual void Normalize(float queryNorm)
{
- this.queryNorm = queryNorm;
- queryWeight *= this.queryNorm;
- }
+ this.queryNorm = queryNorm;
+ queryWeight *= this.queryNorm;
+ }
public virtual Scorer Scorer(IndexReader reader)
{
- return new MatchAllScorer(enclosingInstance, reader, Enclosing_Instance.GetSimilarity(searcher), this);
+ return new MatchAllScorer(enclosingInstance, reader, similarity, this);
}
public virtual Explanation Explain(IndexReader reader, int doc)
{
// explain query weight
- Explanation queryExpl = new Explanation();
- queryExpl.SetDescription("MatchAllDocsQuery, product of:");
- queryExpl.SetValue(GetValue());
- if (Enclosing_Instance.GetBoost() != 1.0f)
- {
- queryExpl.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost"));
- }
- queryExpl.AddDetail(new Explanation(queryNorm, "queryNorm"));
+ Explanation queryExpl = new ComplexExplanation(true, GetValue(), "MatchAllDocsQuery, product of:");
+ if (Enclosing_Instance.GetBoost() != 1.0f)
+ {
+ queryExpl.AddDetail(new Explanation(Enclosing_Instance.GetBoost(), "boost"));
+ }
+ queryExpl.AddDetail(new Explanation(queryNorm, "queryNorm"));
return queryExpl;
}
@@ -179,11 +178,11 @@
return new MatchAllDocsWeight(this, searcher);
}
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- }
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ }
- public override System.String ToString(System.String field)
+ public override System.String ToString(System.String field)
{
System.Text.StringBuilder buffer = new System.Text.StringBuilder();
buffer.Append("MatchAllDocsQuery");
@@ -201,7 +200,7 @@
public override int GetHashCode()
{
- return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0);
+ return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0) ^ 0x1AA71190;
}
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiPhraseQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/MultiPhraseQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiPhraseQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiPhraseQuery.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using MultipleTermPositions = Lucene.Net.Index.MultipleTermPositions;
using Term = Lucene.Net.Index.Term;
@@ -47,7 +48,7 @@
private int slop = 0;
/// <summary>Sets the phrase slop for this query.</summary>
- /// <seealso cref="PhraseQuery.SetSlop(int)">
+ /// <seealso cref="PhraseQuery#SetSlop(int)">
/// </seealso>
public virtual void SetSlop(int s)
{
@@ -55,7 +56,7 @@
}
/// <summary>Sets the phrase slop for this query.</summary>
- /// <seealso cref="PhraseQuery.GetSlop()">
+ /// <seealso cref="PhraseQuery#GetSlop()">
/// </seealso>
public virtual int GetSlop()
{
@@ -63,7 +64,7 @@
}
/// <summary>Add a single term at the next position in the phrase.</summary>
- /// <seealso cref="PhraseQuery.Add(Term)">
+ /// <seealso cref="PhraseQuery#Add(Term)">
/// </seealso>
public virtual void Add(Term term)
{
@@ -74,7 +75,7 @@
/// may match.
///
/// </summary>
- /// <seealso cref="PhraseQuery.Add(Term)">
+ /// <seealso cref="PhraseQuery#Add(Term)">
/// </seealso>
public virtual void Add(Term[] terms)
{
@@ -88,11 +89,11 @@
/// <summary> Allows to specify the relative position of terms within the phrase.
///
/// </summary>
- /// <seealso cref="PhraseQuery.Add(Term, int)">
+ /// <seealso cref="int)">
/// </seealso>
- /// <param name="terms">
+ /// <param name="">terms
/// </param>
- /// <param name="position">
+ /// <param name="">position
/// </param>
public virtual void Add(Term[] terms, int position)
{
@@ -111,15 +112,15 @@
positions.Add((System.Int32) position);
}
- /// <summary> Returns a List<Term[]> of the terms in the multiphrase.
- /// Do not modify the List or its contents.
- /// </summary>
- public virtual System.Collections.IList GetTermArrays()
- {
- return (System.Collections.IList) System.Collections.ArrayList.ReadOnly(new System.Collections.ArrayList(termArrays));
- }
-
- /// <summary> Returns the relative positions of terms in this phrase.</summary>
+ /// <summary> Returns a List<Term[]> of the terms in the multiphrase.
+ /// Do not modify the List or its contents.
+ /// </summary>
+ public virtual System.Collections.IList GetTermArrays()
+ {
+ return (System.Collections.IList) System.Collections.ArrayList.ReadOnly(new System.Collections.ArrayList(termArrays));
+ }
+
+ /// <summary> Returns the relative positions of terms in this phrase.</summary>
public virtual int[] GetPositions()
{
int[] result = new int[positions.Count];
@@ -128,22 +129,21 @@
return result;
}
- // inherit javadoc
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- for (System.Collections.IEnumerator iter = termArrays.GetEnumerator(); iter.MoveNext(); )
- {
- Term[] arr = (Term[]) iter.Current;
- for (int i = 0; i < arr.Length; i++)
- {
- Term tmp = arr[i];
- terms.Add(tmp, tmp);
- }
- }
- }
+ // inherit javadoc
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ for (System.Collections.IEnumerator iter = termArrays.GetEnumerator(); iter.MoveNext(); )
+ {
+ Term[] arr = (Term[]) iter.Current;
+ for (int i = 0; i < arr.Length; i++)
+ {
+ terms.Add(arr[i], arr[i]);
+ }
+ }
+ }
- [Serializable]
+ [Serializable]
private class MultiPhraseWeight : Weight
{
private void InitBlock(MultiPhraseQuery enclosingInstance)
@@ -207,7 +207,7 @@
public virtual Scorer Scorer(IndexReader reader)
{
if (Enclosing_Instance.termArrays.Count == 0)
- // optimize zero-term case
+ // optimize zero-term case
return null;
TermPositions[] tps = new TermPositions[Enclosing_Instance.termArrays.Count];
@@ -235,7 +235,7 @@
public virtual Explanation Explain(IndexReader reader, int doc)
{
- Explanation result = new Explanation();
+ ComplexExplanation result = new ComplexExplanation();
result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
Explanation idfExpl = new Explanation(idf, "idf(" + GetQuery() + ")");
@@ -258,7 +258,7 @@
result.AddDetail(queryExpl);
// explain field weight
- Explanation fieldExpl = new Explanation();
+ ComplexExplanation fieldExpl = new ComplexExplanation();
fieldExpl.SetDescription("fieldWeight(" + GetQuery() + " in " + doc + "), product of:");
Explanation tfExpl = Scorer(reader).Explain(doc);
@@ -272,9 +272,12 @@
fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
fieldExpl.AddDetail(fieldNormExpl);
+ fieldExpl.SetMatch(tfExpl.IsMatch());
fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());
result.AddDetail(fieldExpl);
+ System.Boolean tempAux = fieldExpl.GetMatch();
+ result.SetMatch(tempAux);
// combine them
result.SetValue(queryExpl.GetValue() * fieldExpl.GetValue());
@@ -321,17 +324,10 @@
buffer.Append(":");
}
- bool appendSpace = false;
-
buffer.Append("\"");
System.Collections.IEnumerator i = termArrays.GetEnumerator();
while (i.MoveNext())
{
- if (appendSpace == true)
- buffer.Append(" ");
- else
- appendSpace = true;
-
Term[] terms = (Term[]) i.Current;
if (terms.Length > 1)
{
@@ -348,6 +344,8 @@
{
buffer.Append(terms[0].Text());
}
+ if (i.MoveNext())
+ buffer.Append(" ");
}
buffer.Append("\"");
@@ -363,12 +361,12 @@
}
- /// <summary>Returns true if <code>o</code> is equal to this. </summary>
- public override bool Equals(System.Object o)
- {
- if (!(o is MultiPhraseQuery))
- return false;
- MultiPhraseQuery other = (MultiPhraseQuery) o;
+ /// <summary>Returns true if <code>o</code> is equal to this. </summary>
+ public override bool Equals(System.Object o)
+ {
+ if (!(o is MultiPhraseQuery))
+ return false;
+ MultiPhraseQuery other = (MultiPhraseQuery) o;
if (this.GetBoost() == other.GetBoost() && this.slop == other.slop)
{
System.Collections.IEnumerator iter1 = this.termArrays.GetEnumerator();
@@ -393,10 +391,10 @@
return true;
}
- /// <summary>Returns a hash code value for this object.</summary>
- public override int GetHashCode()
- {
+ /// <summary>Returns a hash code value for this object.</summary>
+ public override int GetHashCode()
+ {
return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0) ^ slop ^ termArrays.GetHashCode() ^ positions.GetHashCode() ^ 0x4AC65113;
- }
+ }
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/MultiSearcher.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiSearcher.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Document = Lucene.Net.Documents.Document;
using Term = Lucene.Net.Index.Term;
@@ -25,7 +26,7 @@
/// <summary>Implements search over a set of <code>Searchables</code>.
///
/// <p>Applications usually need only call the inherited {@link #Search(Query)}
- /// or {@link #Search(Query,Filter)} methods.
+ /// or {@link #search(Query,Filter)} methods.
/// </summary>
public class MultiSearcher : Searcher
{
@@ -195,7 +196,7 @@
}
- /// <summary>Returns index of the searcher for document <code>n</code> in the array
+ /// <summary>Returns index of the searcher for document <code>n</code> in the array
/// used to construct this searcher.
/// </summary>
public virtual int SubSearcher(int n)
@@ -263,7 +264,7 @@
ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()];
for (int i = hq.Size() - 1; i >= 0; i--)
- // put docs in array
+ // put docs in array
scoreDocs2[i] = (ScoreDoc) hq.Pop();
float maxScore = (totalHits == 0) ? System.Single.NegativeInfinity : scoreDocs2[0].score;
@@ -300,7 +301,7 @@
ScoreDoc[] scoreDocs2 = new ScoreDoc[hq.Size()];
for (int i = hq.Size() - 1; i >= 0; i--)
- // put docs in array
+ // put docs in array
scoreDocs2[i] = (ScoreDoc) hq.Pop();
return new TopFieldDocs(totalHits, scoreDocs2, hq.GetFields(), maxScore);
@@ -365,7 +366,7 @@
System.Collections.IEnumerator e = terms.Keys.GetEnumerator();
while (e.MoveNext())
allTermsArray[index++] = e.Current as Term;
- int[] aggregatedDfs = new int[terms.Count];
+ int[] aggregatedDfs = new int[terms.Count];
for (int i = 0; i < searchables.Length; i++)
{
int[] dfs = searchables[i].DocFreqs(allTermsArray);
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiTermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/MultiTermQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiTermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/MultiTermQuery.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Package.html?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Package.html (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Package.html Tue May 1 11:45:26 2007
@@ -1,15 +1,358 @@
-<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="Author" content="Doug Cutting">
-</head>
-<body>
-Search over indices.
-
-Applications usually call {@link
-org.apache.lucene.search.Searcher#search(Query)} or {@link
-org.apache.lucene.search.Searcher#search(Query,Filter)}.
-
-</body>
-</html>
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="Author" content="Doug Cutting">
+ <meta content="Grant Ingersoll" name="Author">
+</head>
+<body>
+<h2>Table Of Contents</h2>
+<p>
+ <ol>
+ <li><a href="#search">Search Basics</a></li>
+ <li><a href="#query">The Query Classes</a></li>
+ <li><a href="#scoring">Changing the Scoring</a></li>
+ </ol>
+</p>
+<a name="search"></a>
+<h2>Search</h2>
+<p>
+Search over indices.
+
+Applications usually call {@link
+Lucene.Net.Search.Searcher#search(Query)} or {@link
+Lucene.Net.Search.Searcher#search(Query,Filter)}.
+
+ <!-- FILL IN MORE HERE -->
+</p>
+<a name="query"></a>
+<h2>Query Classes</h2>
+<h4>
+ <a href="TermQuery.html">TermQuery</a>
+</h4>
+
+<p>Of the various implementations of
+ <a href="Query.html">Query</a>, the
+ <a href="TermQuery.html">TermQuery</a>
+ is the easiest to understand and the most often used in applications. A <a
+ href="TermQuery.html">TermQuery</a> matches all the documents that contain the
+ specified
+ <a href="../index/Term.html">Term</a>,
+ which is a word that occurs in a certain
+ <a href="../document/Field.html">Field</a>.
+ Thus, a <a href="TermQuery.html">TermQuery</a> identifies and scores all
+ <a href="../document/Document.html">Document</a>s that have a <a
+ href="../document/Field.html">Field</a> with the specified string in it.
+ Constructing a <a
+ href="TermQuery.html">TermQuery</a>
+ is as simple as:
+ <pre>
+ TermQuery tq = new TermQuery(new Term("fieldName", "term");
+ </pre>In this example, the <a href="Query.html">Query</a> identifies all <a
+ href="../document/Document.html">Document</a>s that have the <a
+ href="../document/Field.html">Field</a> named <tt>"fieldName"</tt> and
+ contain the word <tt>"term"</tt>.
+</p>
+<h4>
+ <a href="BooleanQuery.html">BooleanQuery</a>
+</h4>
+
+<p>Things start to get interesting when one combines multiple
+ <a href="TermQuery.html">TermQuery</a> instances into a <a
+ href="BooleanQuery.html">BooleanQuery</a>.
+ A <a href="BooleanQuery.html">BooleanQuery</a> contains multiple
+ <a href="BooleanClause.html">BooleanClause</a>s,
+ where each clause contains a sub-query (<a href="Query.html">Query</a>
+ instance) and an operator (from <a
+ href="BooleanClause.Occur.html">BooleanClause.Occur</a>)
+ describing how that sub-query is combined with the other clauses:
+ <ol>
+
+ <li><p>SHOULD -- Use this operator when a clause can occur in the result set, but is not required.
+ If a query is made up of all SHOULD clauses, then every document in the result
+ set matches at least one of these clauses.</p></li>
+
+ <li><p>MUST -- Use this operator when a clause is required to occur in the result set. Every
+ document in the result set will match
+ all such clauses.</p></li>
+
+ <li><p>MUST NOT -- Use this operator when a
+ clause must not occur in the result set. No
+ document in the result set will match
+ any such clauses.</p></li>
+ </ol>
+ Boolean queries are constructed by adding two or more
+ <a href="BooleanClause.html">BooleanClause</a>
+ instances. If too many clauses are added, a <a href="BooleanQuery.TooManyClauses.html">TooManyClauses</a>
+ exception will be thrown during searching. This most often occurs
+ when a <a href="Query.html">Query</a>
+ is rewritten into a <a href="BooleanQuery.html">BooleanQuery</a> with many
+ <a href="TermQuery.html">TermQuery</a> clauses,
+ for example by <a href="WildcardQuery.html">WildcardQuery</a>.
+ The default setting for the maximum number
+ of clauses 1024, but this can be changed via the
+ static method <a href="BooleanQuery.html#setMaxClauseCount(int)">setMaxClauseCount</a>
+ in <a href="BooleanQuery.html">BooleanQuery</a>.
+</p>
+
+<h4>Phrases</h4>
+
+<p>Another common search is to find documents containing certain phrases. This
+ is handled in two different ways.
+ <ol>
+ <li>
+ <p><a href="PhraseQuery.html">PhraseQuery</a>
+ -- Matches a sequence of
+ <a href="../index/Term.html">Terms</a>.
+ <a href="PhraseQuery.html">PhraseQuery</a> uses a slop factor to determine
+ how many positions may occur between any two terms in the phrase and still be considered a match.</p>
+ </li>
+ <li>
+ <p><a href="spans/SpanNearQuery.html">SpanNearQuery</a>
+ -- Matches a sequence of other
+ <a href="spans/SpanQuery.html">SpanQuery</a>
+ instances. <a href="spans/SpanNearQuery.html">SpanNearQuery</a> allows for
+ much more
+ complicated phrase queries since it is constructed from other to <a
+ href="spans/SpanQuery.html">SpanQuery</a>
+ instances, instead of only <a href="TermQuery.html">TermQuery</a>
+ instances.</p>
+ </li>
+ </ol>
+</p>
+<h4>
+ <a href="RangeQuery.html">RangeQuery</a>
+</h4>
+
+<p>The
+ <a href="RangeQuery.html">RangeQuery</a>
+ matches all documents that occur in the
+ exclusive range of a lower
+ <a href="../index/Term.html">Term</a>
+ and an upper
+ <a href="../index/Term.html">Term</a>.
+ For example, one could find all documents
+ that have terms beginning with the letters <tt>a</tt> through <tt>c</tt>. This type of <a
+ href="Query.html">Query</a> is frequently used to
+ find
+ documents that occur in a specific date range.
+</p>
+<h4>
+ <a href="PrefixQuery.html">PrefixQuery</a>,
+ <a href="WildcardQuery.html">WildcardQuery</a>
+</h4>
+
+<p>While the
+ <a href="PrefixQuery.html">PrefixQuery</a>
+ has a different implementation, it is essentially a special case of the
+ <a href="WildcardQuery.html">WildcardQuery</a>.
+ The <a href="PrefixQuery.html">PrefixQuery</a> allows an application
+ to identify all documents with terms that begin with a certain string. The <a
+ href="WildcardQuery.html">WildcardQuery</a> generalizes this by allowing
+ for the use of <tt>*</tt> (matches 0 or more characters) and <tt>?</tt> (matches exactly one character) wildcards.
+ Note that the <a href="WildcardQuery.html">WildcardQuery</a> can be quite slow. Also
+ note that
+ <a href="WildcardQuery.html">WildcardQuery</a> should
+ not start with <tt>*</tt> and <tt>?</tt>, as these are extremely slow. For tricks on how to search using a wildcard
+ at
+ the beginning of a term, see
+ <a href="http://www.gossamer-threads.com/lists/lucene/java-user/13373#13373">
+ Starts With x and Ends With x Queries</a>
+ from the Lucene users's mailing list.
+</p>
+<h4>
+ <a href="FuzzyQuery.html">FuzzyQuery</a>
+</h4>
+
+<p>A
+ <a href="FuzzyQuery.html">FuzzyQuery</a>
+ matches documents that contain terms similar to the specified term. Similarity is
+ determined using
+ <a href="http://en.wikipedia.org/wiki/Levenshtein">Levenshtein (edit) distance</a>.
+ This type of query can be useful when accounting for spelling variations in the collection.
+</p>
+<a name="changingSimilarity"></a>
+<h2>Changing Similarity</h2>
+
+<p>Chances are <a href="DefaultSimilarity.html">DefaultSimilarity</a> is sufficient for all
+ your searching needs.
+ However, in some applications it may be necessary to customize your <a
+ href="Similarity.html">Similarity</a> implementation. For instance, some
+ applications do not need to
+ distinguish between shorter and longer documents (see <a
+ href="http://www.gossamer-threads.com/lists/lucene/java-user/38967#38967">a "fair" similarity</a>).</p>
+
+<p>To change <a href="Similarity.html">Similarity</a>, one must do so for both indexing and
+ searching, and the changes must happen before
+ either of these actions take place. Although in theory there is nothing stopping you from changing mid-stream, it
+ just isn't well-defined what is going to happen.
+</p>
+
+<p>To make this change, implement your own <a href="Similarity.html">Similarity</a> (likely
+ you'll want to simply subclass
+ <a href="DefaultSimilarity.html">DefaultSimilarity</a>) and then use the new
+ class by calling
+ <a href="../index/IndexWriter.html#setSimilarity(Lucene.Net.Search.Similarity)">IndexWriter.setSimilarity</a>
+ before indexing and
+ <a href="Searcher.html#setSimilarity(Lucene.Net.Search.Similarity)">Searcher.setSimilarity</a>
+ before searching.
+</p>
+
+<p>
+ If you are interested in use cases for changing your similarity, see the Lucene users's mailing list at <a
+ href="http://www.nabble.com/Overriding-Similarity-tf2128934.html">Overriding Similarity</a>.
+ In summary, here are a few use cases:
+ <ol>
+ <li><p><a href="api/org/apache/lucene/misc/SweetSpotSimilarity.html">SweetSpotSimilarity</a> -- <a
+ href="api/org/apache/lucene/misc/SweetSpotSimilarity.html">SweetSpotSimilarity</a> gives small increases
+ as the frequency increases a small amount
+ and then greater increases when you hit the "sweet spot", i.e. where you think the frequency of terms is
+ more significant.</p></li>
+ <li><p>Overriding tf -- In some applications, it doesn't matter what the score of a document is as long as a
+ matching term occurs. In these
+ cases people have overridden Similarity to return 1 from the tf() method.</p></li>
+ <li><p>Changing Length Normalization -- By overriding <a
+ href="Similarity.html#lengthNorm(java.lang.String,%20int)">lengthNorm</a>,
+ it is possible to discount how the length of a field contributes
+ to a score. In <a href="DefaultSimilarity.html">DefaultSimilarity</a>,
+ lengthNorm = 1 / (numTerms in field)^0.5, but if one changes this to be
+ 1 / (numTerms in field), all fields will be treated
+ <a href="http://www.gossamer-threads.com/lists/lucene/java-user/38967#38967">"fairly"</a>.</p></li>
+ </ol>
+ In general, Chris Hostetter sums it up best in saying (from <a
+ href="http://www.gossamer-threads.com/lists/lucene/java-user/39125#39125">the Lucene users's mailing list</a>):
+ <blockquote>[One would override the Similarity in] ... any situation where you know more about your data then just
+ that
+ it's "text" is a situation where it *might* make sense to to override your
+ Similarity method.</blockquote>
+</p>
+<a name="scoring"></a>
+<h2>Changing Scoring -- Expert Level</h2>
+
+<p>Changing scoring is an expert level task, so tread carefully and be prepared to share your code if
+ you want help.
+</p>
+
+<p>With the warning out of the way, it is possible to change a lot more than just the Similarity
+ when it comes to scoring in Lucene. Lucene's scoring is a complex mechanism that is grounded by
+ <span >three main classes</span>:
+ <ol>
+ <li>
+ <a href="Query.html">Query</a> -- The abstract object representation of the
+ user's information need.</li>
+ <li>
+ <a href="Weight.html">Weight</a> -- The internal interface representation of
+ the user's Query, so that Query objects may be reused.</li>
+ <li>
+ <a href="Scorer.html">Scorer</a> -- An abstract class containing common
+ functionality for scoring. Provides both scoring and explanation capabilities.</li>
+ </ol>
+ Details on each of these classes, and their children can be found in the subsections below.
+</p>
+<h4>The Query Class</h4>
+ <p>In some sense, the
+ <a href="Query.html">Query</a>
+ class is where it all begins. Without a Query, there would be
+ nothing to score. Furthermore, the Query class is the catalyst for the other scoring classes as it
+ is often responsible
+ for creating them or coordinating the functionality between them. The
+ <a href="Query.html">Query</a> class has several methods that are important for
+ derived classes:
+ <ol>
+ <li>createWeight(Searcher searcher) -- A
+ <a href="Weight.html">Weight</a> is the internal representation of the
+ Query, so each Query implementation must
+ provide an implementation of Weight. See the subsection on <a
+ href="#The Weight Interface">The Weight Interface</a> below for details on implementing the Weight
+ interface.</li>
+ <li>rewrite(IndexReader reader) -- Rewrites queries into primitive queries. Primitive queries are:
+ <a href="TermQuery.html">TermQuery</a>,
+ <a href="BooleanQuery.html">BooleanQuery</a>, <span
+ >OTHERS????</span></li>
+ </ol>
+ </p>
+<h4>The Weight Interface</h4>
+ <p>The
+ <a href="Weight.html">Weight</a>
+ interface provides an internal representation of the Query so that it can be reused. Any
+ <a href="Searcher.html">Searcher</a>
+ dependent state should be stored in the Weight implementation,
+ not in the Query class. The interface defines 6 methods that must be implemented:
+ <ol>
+ <li>
+ <a href="Weight.html#getQuery()">Weight#getQuery()</a> -- Pointer to the
+ Query that this Weight represents.</li>
+ <li>
+ <a href="Weight.html#getValue()">Weight#getValue()</a> -- The weight for
+ this Query. For example, the TermQuery.TermWeight value is
+ equal to the idf^2 * boost * queryNorm <!-- DOUBLE CHECK THIS --></li>
+ <li>
+ <a href="Weight.html#sumOfSquaredWeights()">
+ Weight#sumOfSquaredWeights()</a> -- The sum of squared weights. Tor TermQuery, this is (idf *
+ boost)^2</li>
+ <li>
+ <a href="Weight.html#normalize(float)">
+ Weight#normalize(float)</a> -- Determine the query normalization factor. The query normalization may
+ allow for comparing scores between queries.</li>
+ <li>
+ <a href="Weight.html#scorer(IndexReader)">
+ Weight#scorer(IndexReader)</a> -- Construct a new
+ <a href="Scorer.html">Scorer</a>
+ for this Weight. See
+ <a href="#The Scorer Class">The Scorer Class</a>
+ below for help defining a Scorer. As the name implies, the
+ Scorer is responsible for doing the actual scoring of documents given the Query.
+ </li>
+ <li>
+ <a href="Weight.html#explain(IndexReader, int)">
+ Weight#explain(IndexReader, int)</a> -- Provide a means for explaining why a given document was
+ scored
+ the way it was.</li>
+ </ol>
+ </p>
+<h4>The Scorer Class</h4>
+ <p>The
+ <a href="Scorer.html">Scorer</a>
+ abstract class provides common scoring functionality for all Scorer implementations and
+ is the heart of the Lucene scoring process. The Scorer defines the following abstract methods which
+ must be implemented:
+ <ol>
+ <li>
+ <a href="Scorer.html#next()">Scorer#next()</a> -- Advances to the next
+ document that matches this Query, returning true if and only
+ if there is another document that matches.</li>
+ <li>
+ <a href="Scorer.html#doc()">Scorer#doc()</a> -- Returns the id of the
+ <a href="../document/Document.html">Document</a>
+ that contains the match. Is not valid until next() has been called at least once.
+ </li>
+ <li>
+ <a href="Scorer.html#score()">Scorer#score()</a> -- Return the score of the
+ current document. This value can be determined in any
+ appropriate way for an application. For instance, the
+ <a href="http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/TermScorer.java?view=log">TermScorer</a>
+ returns the tf * Weight.getValue() * fieldNorm.
+ </li>
+ <li>
+ <a href="Scorer.html#skipTo(int)">Scorer#skipTo(int)</a> -- Skip ahead in
+ the document matches to the document whose id is greater than
+ or equal to the passed in value. In many instances, skipTo can be
+ implemented more efficiently than simply looping through all the matching documents until
+ the target document is identified.</li>
+ <li>
+ <a href="Scorer.html#explain(int)">Scorer#explain(int)</a> -- Provides
+ details on why the score came about.</li>
+ </ol>
+ </p>
+<h4>Why would I want to add my own Query?</h4>
+
+ <p>In a nutshell, you want to add your own custom Query implementation when you think that Lucene's
+ aren't appropriate for the
+ task that you want to do. You might be doing some cutting edge research or you need more information
+ back
+ out of Lucene (similar to Doug adding SpanQuery functionality).</p>
+<h4>Examples</h4>
+ <p >FILL IN HERE</p>
+
+</body>
+</html>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ParallelMultiSearcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ParallelMultiSearcher.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ParallelMultiSearcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ParallelMultiSearcher.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Term = Lucene.Net.Index.Term;
using PriorityQueue = Lucene.Net.Util.PriorityQueue;
@@ -25,7 +26,7 @@
/// <summary>Implements parallel search over a set of <code>Searchables</code>.
///
/// <p>Applications usually need only call the inherited {@link #Search(Query)}
- /// or {@link #Search(Query,Filter)} methods.
+ /// or {@link #search(Query,Filter)} methods.
/// </summary>
public class ParallelMultiSearcher : MultiSearcher
{
@@ -97,7 +98,7 @@
{
msta[i].Join();
}
- catch (System.Threading.ThreadInterruptedException)
+ catch (System.Threading.ThreadInterruptedException ie)
{
; // TODO: what should we do with this???
}
@@ -149,7 +150,7 @@
{
msta[i].Join();
}
- catch (System.Threading.ThreadInterruptedException)
+ catch (System.Threading.ThreadInterruptedException ie)
{
; // TODO: what should we do with this???
}
@@ -206,7 +207,7 @@
/*
* TODO: this one could be parallelized too
- * @see Lucene.Net.search.Searchable#rewrite(Lucene.Net.search.Query)
+ * @see Lucene.Net.Search.Searchable#rewrite(Lucene.Net.Search.Query)
*/
public override Query Rewrite(Query original)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhrasePositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhrasePositions.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhrasePositions.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhrasePositions.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Lucene.Net.Index;
namespace Lucene.Net.Search
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhraseQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQuery.cs Tue May 1 11:45:26 2007
@@ -16,9 +16,10 @@
*/
using System;
-using IndexReader = Lucene.Net.Index.IndexReader;
+
using Term = Lucene.Net.Index.Term;
using TermPositions = Lucene.Net.Index.TermPositions;
+using IndexReader = Lucene.Net.Index.IndexReader;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
namespace Lucene.Net.Search
@@ -82,9 +83,9 @@
/// or phrases with gaps (e.g. in connection with stopwords).
///
/// </summary>
- /// <param name="term">
+ /// <param name="">term
/// </param>
- /// <param name="position">
+ /// <param name="">position
/// </param>
public virtual void Add(Term term, int position)
{
@@ -248,7 +249,7 @@
Explanation fieldNormExpl = new Explanation();
byte[] fieldNorms = reader.Norms(Enclosing_Instance.field);
- float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]):0.0f;
+ float fieldNorm = fieldNorms != null ? Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;
fieldNormExpl.SetValue(fieldNorm);
fieldNormExpl.SetDescription("fieldNorm(field=" + Enclosing_Instance.field + ", doc=" + doc + ")");
fieldExpl.AddDetail(fieldNormExpl);
@@ -280,18 +281,18 @@
return new PhraseWeight(this, searcher);
}
- /// <seealso cref="Lucene.Net.search.Query.ExtractTerms(java.util.Set)">
+ /// <seealso cref="Lucene.Net.Search.Query#ExtractTerms(java.util.Set)">
/// </seealso>
public override void ExtractTerms(System.Collections.Hashtable queryTerms)
{
- foreach (Term term in terms)
- {
- if (queryTerms.Contains(term) == false)
- {
- queryTerms.Add(term, term);
- }
- }
- }
+ foreach (Term term in terms)
+ {
+ if (queryTerms.Contains(term) == false)
+ {
+ queryTerms.Add(term, term);
+ }
+ }
+ }
/// <summary>Prints a user-readable version of this query. </summary>
public override System.String ToString(System.String f)
@@ -323,22 +324,22 @@
return buffer.ToString();
}
- /// <summary>Returns true iff <code>o</code> is equal to this. </summary>
- public override bool Equals(System.Object o)
- {
- if (!(o is PhraseQuery))
- return false;
- PhraseQuery other = (PhraseQuery) o;
+ /// <summary>Returns true iff <code>o</code> is equal to this. </summary>
+ public override bool Equals(System.Object o)
+ {
+ if (!(o is PhraseQuery))
+ return false;
+ PhraseQuery other = (PhraseQuery) o;
return (this.GetBoost() == other.GetBoost()) &&
(this.slop == other.slop) &&
this.terms.Equals(other.terms) &&
this.positions.Equals(other.positions);
- }
+ }
- /// <summary>Returns a hash code value for this object.</summary>
- public override int GetHashCode()
- {
- return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0) ^ slop ^ terms.GetHashCode() ^ positions.GetHashCode();
- }
- }
+ /// <summary>Returns a hash code value for this object.</summary>
+ public override int GetHashCode()
+ {
+ return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0) ^ slop ^ terms.GetHashCode() ^ positions.GetHashCode();
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhraseQueue.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQueue.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQueue.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using PriorityQueue = Lucene.Net.Util.PriorityQueue;
namespace Lucene.Net.Search
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhraseScorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseScorer.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Lucene.Net.Index;
namespace Lucene.Net.Search
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PrefixFilter.cs?view=auto&rev=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixFilter.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixFilter.cs Tue May 1 11:45:26 2007
@@ -0,0 +1,147 @@
+/*
+ * 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.
+ */
+
+using System;
+
+using Term = Lucene.Net.Index.Term;
+using IndexReader = Lucene.Net.Index.IndexReader;
+using TermEnum = Lucene.Net.Index.TermEnum;
+using TermDocs = Lucene.Net.Index.TermDocs;
+
+namespace Lucene.Net.Search
+{
+
+ /// <author> yonik
+ /// </author>
+ /// <version> $Id$
+ /// </version>
+ [Serializable]
+ public class PrefixFilter : Filter
+ {
+ private class AnonymousClassPrefixGenerator : PrefixGenerator
+ {
+ private void InitBlock(System.Collections.BitArray bitSet, PrefixFilter enclosingInstance)
+ {
+ this.bitSet = bitSet;
+ this.enclosingInstance = enclosingInstance;
+ }
+ private System.Collections.BitArray bitSet;
+ private PrefixFilter enclosingInstance;
+ public PrefixFilter Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
+
+ }
+ internal AnonymousClassPrefixGenerator(System.Collections.BitArray bitSet, PrefixFilter enclosingInstance, Lucene.Net.Index.Term Param1):base(Param1)
+ {
+ InitBlock(bitSet, enclosingInstance);
+ }
+ public override void HandleDoc(int doc)
+ {
+ bitSet.Set(doc, true);
+ }
+ }
+
+ protected internal Term prefix;
+
+ public PrefixFilter(Term prefix)
+ {
+ this.prefix = prefix;
+ }
+
+ public virtual Term GetPrefix()
+ {
+ return prefix;
+ }
+
+ public override System.Collections.BitArray Bits(IndexReader reader)
+ {
+ System.Collections.BitArray bitSet = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
+ new AnonymousClassPrefixGenerator(bitSet, this, prefix).Generate(reader);
+ return bitSet;
+ }
+
+ /// <summary>Prints a user-readable version of this query. </summary>
+ public override System.String ToString()
+ {
+ System.Text.StringBuilder buffer = new System.Text.StringBuilder();
+ buffer.Append("PrefixFilter(");
+ buffer.Append(prefix.ToString());
+ buffer.Append(")");
+ return buffer.ToString();
+ }
+ }
+
+ // keep this protected until I decide if it's a good way
+ // to separate id generation from collection (or should
+ // I just reuse hitcollector???)
+ internal interface IdGenerator
+ {
+ void Generate(IndexReader reader);
+ void HandleDoc(int doc);
+ }
+
+
+ abstract class PrefixGenerator : IdGenerator
+ {
+ protected internal Term prefix;
+
+ internal PrefixGenerator(Term prefix)
+ {
+ this.prefix = prefix;
+ }
+
+ public virtual void Generate(IndexReader reader)
+ {
+ TermEnum enumerator = reader.Terms(prefix);
+ TermDocs termDocs = reader.TermDocs();
+
+ try
+ {
+
+ System.String prefixText = prefix.Text();
+ System.String prefixField = prefix.Field();
+ do
+ {
+ Term term = enumerator.Term();
+ if (term != null && term.Text().StartsWith(prefixText) && (System.Object) term.Field() == (System.Object) prefixField)
+ {
+ termDocs.Seek(term);
+ while (termDocs.Next())
+ {
+ HandleDoc(termDocs.Doc());
+ }
+ }
+ else
+ {
+ break;
+ }
+ }
+ while (enumerator.Next());
+ }
+ finally
+ {
+ termDocs.Close();
+ enumerator.Close();
+ }
+ }
+ public abstract void HandleDoc(int param1);
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PrefixQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixQuery.cs Tue May 1 11:45:26 2007
@@ -16,9 +16,10 @@
*/
using System;
-using IndexReader = Lucene.Net.Index.IndexReader;
+
using Term = Lucene.Net.Index.Term;
using TermEnum = Lucene.Net.Index.TermEnum;
+using IndexReader = Lucene.Net.Index.IndexReader;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
namespace Lucene.Net.Search
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Query.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Query.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Query.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Query.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
namespace Lucene.Net.Search
@@ -33,11 +34,11 @@
/// <li> {@link MultiPhraseQuery}
/// <li> {@link FuzzyQuery}
/// <li> {@link RangeQuery}
- /// <li> {@link Lucene.Net.search.spans.SpanQuery}
+ /// <li> {@link Lucene.Net.Search.Spans.SpanQuery}
/// </ul>
/// <p>A parser for queries is contained in:
/// <ul>
- /// <li>{@link Lucene.Net.queryParser.QueryParser QueryParser}
+ /// <li>{@link Lucene.Net.QueryParsers.QueryParser QueryParser}
/// </ul>
/// </summary>
[Serializable]
@@ -63,21 +64,21 @@
return boost;
}
- /// <summary>Prints a query to a string, with <code>field</code> assumed to be the
- /// default field and omitted.
- /// <p>The representation used is one that is supposed to be readable
- /// by {@link org.apache.lucene.queryParser.QueryParser QueryParser}. However,
- /// there are the following limitations:
- /// <ul>
- /// <li>If the query was created by the parser, the printed
- /// representation may not be exactly what was parsed. For example,
- /// characters that need to be escaped will be represented without
- /// the required backslash.</li>
- /// <li>Some of the more complicated queries (e.g. span queries)
- /// don't have a representation that can be parsed by QueryParser.</li>
- /// </ul>
- /// </summary>
- public abstract System.String ToString(System.String field);
+ /// <summary>Prints a query to a string, with <code>field</code> assumed to be the
+ /// default field and omitted.
+ /// <p>The representation used is one that is supposed to be readable
+ /// by {@link Lucene.Net.QueryParsers.QueryParser QueryParser}. However,
+ /// there are the following limitations:
+ /// <ul>
+ /// <li>If the query was created by the parser, the printed
+ /// representation may not be exactly what was parsed. For example,
+ /// characters that need to be escaped will be represented without
+ /// the required backslash.</li>
+ /// <li>Some of the more complicated queries (e.g. span queries)
+ /// don't have a representation that can be parsed by QueryParser.</li>
+ /// </ul>
+ /// </summary>
+ public abstract System.String ToString(System.String field);
/// <summary>Prints a query to a string. </summary>
public override System.String ToString()
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/QueryFilter.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryFilter.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using System.Runtime.InteropServices;
using IndexReader = Lucene.Net.Index.IndexReader;
@@ -33,7 +34,7 @@
/// once per day.
///
/// </summary>
- /// <version> $Id: QueryFilter.java 328729 2005-10-26 21:05:35Z yonik $
+ /// <version> $Id: QueryFilter.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
[Serializable]
public class QueryFilter : Filter
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryTermVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/QueryTermVector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryTermVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryTermVector.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Analyzer = Lucene.Net.Analysis.Analyzer;
using Token = Lucene.Net.Analysis.Token;
using TokenStream = Lucene.Net.Analysis.TokenStream;
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RangeFilter.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeFilter.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
using TermDocs = Lucene.Net.Index.TermDocs;
@@ -29,8 +30,8 @@
///
/// <p>
/// This code borrows heavily from {@link RangeQuery}, but is implemented as a Filter
- ///
- /// </p>
+ ///
+ /// </p>
/// </summary>
[Serializable]
public class RangeFilter : Filter
@@ -113,7 +114,7 @@
bool checkLower = false;
if (!includeLower)
- // make adjustments to set to exclusive
+ // make adjustments to set to exclusive
checkLower = true;
TermDocs termDocs = reader.TermDocs();
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RangeQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeQuery.cs Tue May 1 11:45:26 2007
@@ -16,19 +16,32 @@
*/
using System;
-using IndexReader = Lucene.Net.Index.IndexReader;
+
using Term = Lucene.Net.Index.Term;
using TermEnum = Lucene.Net.Index.TermEnum;
+using IndexReader = Lucene.Net.Index.IndexReader;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
namespace Lucene.Net.Search
{
/// <summary> A Query that matches documents within an exclusive range. A RangeQuery
- /// is built by QueryParser for input like <code>[010 TO 120]</code>.
+ /// is built by QueryParser for input like <code>[010 TO 120]</code> but only if the QueryParser has
+ /// the useOldRangeQuery property set to true. The QueryParser default behaviour is to use
+ /// the newer ConstantScoreRangeQuery class. This is generally preferable because:
+ /// <ul>
+ /// <li>It is faster than RangeQuery</li>
+ /// <li>Unlike RangeQuery, it does not cause a BooleanQuery.TooManyClauses exception if the range of values is large</li>
+ /// <li>Unlike RangeQuery it does not influence scoring based on the scarcity of individual terms that may match</li>
+ /// </ul>
+ ///
///
/// </summary>
- /// <version> $Id: RangeQuery.java 329381 2005-10-29 09:26:21Z ehatcher $
+ /// <seealso cref="ConstantScoreRangeQuery">
+ ///
+ ///
+ /// </seealso>
+ /// <version> $Id: RangeQuery.java 475435 2006-11-15 21:26:09Z mharwood $
/// </version>
[Serializable]
public class RangeQuery : Query
@@ -122,7 +135,7 @@
/// <summary>Returns the field name for this query </summary>
public virtual System.String GetField()
{
- return (lowerTerm != null?lowerTerm.Field():upperTerm.Field());
+ return (lowerTerm != null ? lowerTerm.Field() : upperTerm.Field());
}
/// <summary>Returns the lower term of this range query </summary>
@@ -153,7 +166,7 @@
buffer.Append(GetField());
buffer.Append(":");
}
- buffer.Append(inclusive?"[":"{");
+ buffer.Append(inclusive ? "[" : "{");
buffer.Append(lowerTerm != null ? lowerTerm.Text() : "null");
buffer.Append(" TO ");
buffer.Append(upperTerm != null ? upperTerm.Text() : "null");
@@ -186,14 +199,14 @@
/// <summary>Returns a hash code value for this object.</summary>
public override int GetHashCode()
{
- int h = BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0);
- h ^= (lowerTerm != null ? lowerTerm.GetHashCode() : 0);
- // reversible mix to make lower and upper position dependent and
- // to prevent them from cancelling out.
- h ^= ((h << 25) | (h >> 8));
- h ^= (upperTerm != null ? upperTerm.GetHashCode() : 0);
- h ^= (this.inclusive ? 0x2742E74A : 0);
- return h;
- }
+ int h = BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0);
+ h ^= (lowerTerm != null ? lowerTerm.GetHashCode() : 0);
+ // reversible mix to make lower and upper position dependent and
+ // to prevent them from cancelling out.
+ h ^= ((h << 25) | (h >> 8));
+ h ^= (upperTerm != null ? upperTerm.GetHashCode() : 0);
+ h ^= (this.inclusive ? 0x2742E74A : 0);
+ return h;
+ }
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteSearchable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RemoteSearchable.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteSearchable.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteSearchable.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using Document = Lucene.Net.Documents.Document;
using Term = Lucene.Net.Index.Term;
@@ -25,7 +26,7 @@
/// <summary> A remote searchable implementation.
///
/// </summary>
- /// <version> $Id: RemoteSearchable.java 351472 2005-12-01 21:15:53Z bmesser $
+ /// <version> $Id: RemoteSearchable.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
[Serializable]
public class RemoteSearchable : System.MarshalByRefObject, Lucene.Net.Search.Searchable
@@ -91,7 +92,7 @@
{
return local.Explain(weight, doc);
}
-
+
/// <summary>Exports a searcher for the index in args[0] named
/// "//localhost/Searchable".
/// </summary>
@@ -107,15 +108,15 @@
if (indexName == null)
{
- System.Console.Out.WriteLine("Usage: Lucene.Net.search.RemoteSearchable <index>");
+ System.Console.Out.WriteLine("Usage: Lucene.Net.Search.RemoteSearchable <index>");
return ;
}
// create and install a security manager
- if (true) // if (System_Renamed.getSecurityManager() == null) // {{Aroush-1.4.3}} Do we need this line?!
- {
- // System_Renamed.setSecurityManager(new RMISecurityManager()); // {{Aroush-1.4.3}} Do we need this line?!
- }
+ if (true) // if (System_Renamed.getSecurityManager() == null) // {{Aroush-1.4.3}} Do we need this line?!
+ {
+ // System_Renamed.setSecurityManager(new RMISecurityManager()); // {{Aroush-1.4.3}} Do we need this line?!
+ }
Lucene.Net.Search.Searchable local = new IndexSearcher(indexName);
RemoteSearchable impl = new RemoteSearchable(local);
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqExclScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ReqExclScorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqExclScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqExclScorer.cs Tue May 1 11:45:26 2007
@@ -116,7 +116,7 @@
}
/// <summary>Returns the score of the current document matching the query.
- /// Initially invalid, until {@link #Next()} is called the first time.
+ /// Initially invalid, until {@link #next()} is called the first time.
/// </summary>
/// <returns> The score of the required scorer.
/// </returns>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqOptSumScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ReqOptSumScorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqOptSumScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqOptSumScorer.cs Tue May 1 11:45:26 2007
@@ -62,7 +62,7 @@
}
/// <summary>Returns the score of the current document matching the query.
- /// Initially invalid, until {@link #Next()} is called the first time.
+ /// Initially invalid, until {@link #next()} is called the first time.
/// </summary>
/// <returns> The score of the required scorer, eventually increased by the score
/// of the optional scorer when it also matches the current document.
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDoc.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ScoreDoc.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDoc.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDoc.cs Tue May 1 11:45:26 2007
@@ -30,7 +30,7 @@
public float score;
/// <summary>Expert: A hit document's number.</summary>
- /// <seealso cref="Searcher.Doc(int)">
+ /// <seealso cref="Searcher#Doc(int)">
/// </seealso>
public int doc;
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDocComparator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ScoreDocComparator.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDocComparator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDocComparator.cs Tue May 1 11:45:26 2007
@@ -30,7 +30,7 @@
/// </author>
/// <since> lucene 1.4
/// </since>
- /// <version> $Id: ScoreDocComparator.java 150348 2004-05-19 23:05:27Z tjones $
+ /// <version> $Id: ScoreDocComparator.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
public struct ScoreDocComparator_Fields
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Scorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Scorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Scorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Scorer.cs Tue May 1 11:45:26 2007
@@ -105,7 +105,7 @@
/// <p>Behaves as if written: <pre>
/// boolean skipTo(int target) {
/// do {
- /// if (!next())
+ /// if (!Next())
/// return false;
/// } while (target > doc());
/// return true;
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Searchable.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs Tue May 1 11:45:26 2007
@@ -16,12 +16,14 @@
*/
using System;
+
using Document = Lucene.Net.Documents.Document;
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
namespace Lucene.Net.Search
{
+ // for javadoc
/// <summary>The interface for search implementations.
///
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Searcher.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs Tue May 1 11:45:26 2007
@@ -16,8 +16,9 @@
*/
using System;
-using Document = Lucene.Net.Documents.Document;
+
using Term = Lucene.Net.Index.Term;
+using Document = Lucene.Net.Documents.Document;
namespace Lucene.Net.Search
{
@@ -136,7 +137,7 @@
/// <p>Called by {@link Hits}.
///
/// <p>Applications should usually call {@link Searcher#Search(Query)} or
- /// {@link Searcher#Search(Query,Filter)} instead.
+ /// {@link Searcher#search(Query,Filter)} instead.
/// </summary>
/// <throws> BooleanQuery.TooManyClauses </throws>
public virtual TopDocs Search(Query query, Filter filter, int n)
@@ -163,7 +164,7 @@
/// <summary>Expert: Set the Similarity implementation used by this Searcher.
///
/// </summary>
- /// <seealso cref="Similarity.SetDefault(Similarity)">
+ /// <seealso cref="Similarity#SetDefault(Similarity)">
/// </seealso>
public virtual void SetSimilarity(Similarity similarity)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Similarity.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Similarity.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Similarity.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Similarity.cs Tue May 1 11:45:26 2007
@@ -16,7 +16,7 @@
*/
using System;
-using Field = Lucene.Net.Documents.Field;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using IndexWriter = Lucene.Net.Index.IndexWriter;
using Term = Lucene.Net.Index.Term;
@@ -28,61 +28,265 @@
/// <summary>Expert: Scoring API.
/// <p>Subclasses implement search scoring.
///
- /// <p>The score of query <code>q</code> for document <code>d</code> is defined
- /// in terms of these methods as follows:
+ /// <p>The score of query <code>q</code> for document <code>d</code> correlates to the
+ /// cosine-distance or dot-product between document and query vectors in a
+ /// <a href="http://en.wikipedia.org/wiki/Vector_Space_Model">
+ /// Vector Space Model (VSM) of Information Retrieval</a>.
+ /// A document whose vector is closer to the query vector in that model is scored higher.
+ ///
+ /// The score is computed as follows:
///
- /// <table cellpadding="0" cellspacing="0" border="0">
+ /// <P>
+ /// <table cellpadding="1" cellspacing="0" border="1" align="center">
+ /// <tr><td>
+ /// <table cellpadding="1" cellspacing="0" border="0" align="center">
/// <tr>
- /// <td valign="middle" align="right" rowspan="2">score(q,d) =<br></td>
- /// <td valign="middle" align="center">
- /// <big><big><big><big><big>Σ</big></big></big></big></big></td>
- /// <td valign="middle"><small>
- /// ( {@link #Tf(int) tf}(t in d) *
- /// {@link #Idf(Term,Searcher) idf}(t)^2 *
- /// {@link Query#getBoost getBoost}(t in q) *
- /// {@link Field#getBoost getBoost}(t.field in d) *
- /// {@link #LengthNorm(String,int) lengthNorm}(t.field in d) )
- /// </small></td>
- /// <td valign="middle" rowspan="2"> *
- /// {@link #Coord(int,int) coord}(q,d) *
- /// {@link #QueryNorm(float) queryNorm}(sumOfSqaredWeights)
+ /// <td valign="middle" align="right" rowspan="1">
+ /// score(q,d) =
+ /// <A HREF="#formula_coord">coord(q,d)</A> ·
+ /// <A HREF="#formula_queryNorm">queryNorm(q)</A> ·
/// </td>
+ /// <td valign="bottom" align="center" rowspan="1">
+ /// <big><big><big>∑</big></big></big>
+ /// </td>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// <big><big>(</big></big>
+ /// <A HREF="#formula_tf">tf(t in d)</A> ·
+ /// <A HREF="#formula_idf">idf(t)</A><sup>2</sup> ·
+ /// <A HREF="#formula_termBoost">t.getBoost()</A> ·
+ /// <A HREF="#formula_norm">norm(t,d)</A>
+ /// <big><big>)</big></big>
+ /// </td>
+ /// </tr>
+ /// <tr valigh="top">
+ /// <td></td>
+ /// <td align="center"><small>t in q</small></td>
+ /// <td></td>
/// </tr>
+ /// </table>
+ /// </td></tr>
+ /// </table>
+ ///
+ /// <p> where
+ /// <ol>
+ /// <li>
+ /// <A NAME="formula_tf"></A>
+ /// <b>tf(t in d)</b>
+ /// correlates to the term's <i>frequency</i>,
+ /// defined as the number of times term <i>t</i> appears in the currently scored document <i>d</i>.
+ /// Documents that have more occurrences of a given term receive a higher score.
+ /// The default computation for <i>tf(t in d)</i> in
+ /// {@link Lucene.Net.Search.DefaultSimilarity#Tf(float) DefaultSimilarity} is:
+ ///
+ /// <br> <br>
+ /// <table cellpadding="2" cellspacing="2" border="0" align="center">
/// <tr>
- /// <td valign="top" align="right">
- /// <small>t in q</small>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// {@link Lucene.Net.Search.DefaultSimilarity#Tf(float) tf(t in d)} =
+ /// </td>
+ /// <td valign="top" align="center" rowspan="1">
+ /// frequency<sup><big>½</big></sup>
/// </td>
/// </tr>
/// </table>
+ /// <br> <br>
+ /// </li>
///
- /// <p> where
+ /// <li>
+ /// <A NAME="formula_idf"></A>
+ /// <b>idf(t)</b> stands for Inverse Document Frequency. This value
+ /// correlates to the inverse of <i>docFreq</i>
+ /// (the number of documents in which the term <i>t</i> appears).
+ /// This means rarer terms give higher contribution to the total score.
+ /// The default computation for <i>idf(t)</i> in
+ /// {@link Lucene.Net.Search.DefaultSimilarity#Idf(int, int) DefaultSimilarity} is:
///
- /// <table cellpadding="0" cellspacing="0" border="0">
+ /// <br> <br>
+ /// <table cellpadding="2" cellspacing="2" border="0" align="center">
/// <tr>
- /// <td valign="middle" align="right" rowspan="2">sumOfSqaredWeights =<br></td>
+ /// <td valign="middle" align="right">
+ /// {@link Lucene.Net.Search.DefaultSimilarity#Idf(int, int) idf(t)} =
+ /// </td>
+ /// <td valign="middle" align="center">
+ /// 1 + log <big>(</big>
+ /// </td>
+ /// <td valign="middle" align="center">
+ /// <table>
+ /// <tr><td align="center"><small>numDocs</small></td></tr>
+ /// <tr><td align="center">–––––––––</td></tr>
+ /// <tr><td align="center"><small>docFreq+1</small></td></tr>
+ /// </table>
+ /// </td>
/// <td valign="middle" align="center">
- /// <big><big><big><big><big>Σ</big></big></big></big></big></td>
- /// <td valign="middle"><small>
- /// ( {@link #Idf(Term,Searcher) idf}(t) *
- /// {@link Query#getBoost getBoost}(t in q) )^2
- /// </small></td>
+ /// <big>)</big>
+ /// </td>
/// </tr>
+ /// </table>
+ /// <br> <br>
+ /// </li>
+ ///
+ /// <li>
+ /// <A NAME="formula_coord"></A>
+ /// <b>coord(q,d)</b>
+ /// is a score factor based on how many of the query terms are found in the specified document.
+ /// Typically, a document that contains more of the query's terms will receive a higher score
+ /// than another document with fewer query terms.
+ /// This is a search time factor computed in
+ /// {@link #Coord(int, int) coord(q,d)}
+ /// by the Similarity in effect at search time.
+ /// <br> <br>
+ /// </li>
+ ///
+ /// <li><b>
+ /// <A NAME="formula_queryNorm"></A>
+ /// queryNorm(q)
+ /// </b>
+ /// is a normalizing factor used to make scores between queries comparable.
+ /// This factor does not affect document ranking (since all ranked documents are multiplied by the same factor),
+ /// but rather just attempts to make scores from different queries (or even different indexes) comparable.
+ /// This is a search time factor computed by the Similarity in effect at search time.
+ ///
+ /// The default computation in
+ /// {@link Lucene.Net.Search.DefaultSimilarity#QueryNorm(float) DefaultSimilarity}
+ /// is:
+ /// <br> <br>
+ /// <table cellpadding="1" cellspacing="0" border="0" align="center">
/// <tr>
- /// <td valign="top" align="right">
- /// <small>t in q</small>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// queryNorm(q) =
+ /// {@link Lucene.Net.Search.DefaultSimilarity#QueryNorm(float) queryNorm(sumOfSquaredWeights)}
+ /// =
/// </td>
+ /// <td valign="middle" align="center" rowspan="1">
+ /// <table>
+ /// <tr><td align="center"><big>1</big></td></tr>
+ /// <tr><td align="center"><big>
+ /// ––––––––––––––
+ /// </big></td></tr>
+ /// <tr><td align="center">sumOfSquaredWeights<sup><big>½</big></sup></td></tr>
+ /// </table>
+ /// </td>
+ /// </tr>
+ /// </table>
+ /// <br> <br>
+ ///
+ /// The sum of squared weights (of the query terms) is
+ /// computed by the query {@link Lucene.Net.Search.Weight} object.
+ /// For example, a {@link Lucene.Net.Search.BooleanQuery boolean query}
+ /// computes this value as:
+ ///
+ /// <br> <br>
+ /// <table cellpadding="1" cellspacing="0" border="0"n align="center">
+ /// <tr>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// {@link Lucene.Net.Search.Weight#SumOfSquaredWeights() sumOfSquaredWeights} =
+ /// {@link Lucene.Net.Search.Query#GetBoost() q.getBoost()} <sup><big>2</big></sup>
+ /// ·
+ /// </td>
+ /// <td valign="bottom" align="center" rowspan="1">
+ /// <big><big><big>∑</big></big></big>
+ /// </td>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// <big><big>(</big></big>
+ /// <A HREF="#formula_idf">idf(t)</A> ·
+ /// <A HREF="#formula_termBoost">t.getBoost()</A>
+ /// <big><big>) <sup>2</sup> </big></big>
+ /// </td>
+ /// </tr>
+ /// <tr valigh="top">
+ /// <td></td>
+ /// <td align="center"><small>t in q</small></td>
+ /// <td></td>
/// </tr>
/// </table>
+ /// <br> <br>
+ ///
+ /// </li>
///
- /// <p> Note that the above formula is motivated by the cosine-distance or dot-product
- /// between document and query vector, which is implemented by {@link DefaultSimilarity}.
+ /// <li>
+ /// <A NAME="formula_termBoost"></A>
+ /// <b>t.getBoost()</b>
+ /// is a search time boost of term <i>t</i> in the query <i>q</i> as
+ /// specified in the query text
+ /// (see <A HREF="../../../../../queryparsersyntax.html#Boosting a Term">query syntax</A>),
+ /// or as set by application calls to
+ /// {@link Lucene.Net.Search.Query#SetBoost(float) setBoost()}.
+ /// Notice that there is really no direct API for accessing a boost of one term in a multi term query,
+ /// but rather multi terms are represented in a query as multi
+ /// {@link Lucene.Net.Search.TermQuery TermQuery} objects,
+ /// and so the boost of a term in the query is accessible by calling the sub-query
+ /// {@link Lucene.Net.Search.Query#GetBoost() getBoost()}.
+ /// <br> <br>
+ /// </li>
+ ///
+ /// <li>
+ /// <A NAME="formula_norm"></A>
+ /// <b>norm(t,d)</b> encapsulates a few (indexing time) boost and length factors:
+ ///
+ /// <ul>
+ /// <li><b>Document boost</b> - set by calling
+ /// {@link Lucene.Net.Documents.Document#SetBoost(float) doc.setBoost()}
+ /// before adding the document to the index.
+ /// </li>
+ /// <li><b>Field boost</b> - set by calling
+ /// {@link Lucene.Net.Documents.Fieldable#SetBoost(float) field.setBoost()}
+ /// before adding the field to a document.
+ /// </li>
+ /// <li>{@link #LengthNorm(String, int) <b>lengthNorm</b>(field)} - computed
+ /// when the document is added to the index in accordance with the number of tokens
+ /// of this field in the document, so that shorter fields contribute more to the score.
+ /// LengthNorm is computed by the Similarity class in effect at indexing.
+ /// </li>
+ /// </ul>
+ ///
+ /// <p>
+ /// When a document is added to the index, all the above factors are multiplied.
+ /// If the document has multiple fields with the same name, all their boosts are multiplied together:
+ ///
+ /// <br> <br>
+ /// <table cellpadding="1" cellspacing="0" border="0"n align="center">
+ /// <tr>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// norm(t,d) =
+ /// {@link Lucene.Net.Documents.Document#GetBoost() doc.getBoost()}
+ /// ·
+ /// {@link #LengthNorm(String, int) lengthNorm(field)}
+ /// ·
+ /// </td>
+ /// <td valign="bottom" align="center" rowspan="1">
+ /// <big><big><big>∏</big></big></big>
+ /// </td>
+ /// <td valign="middle" align="right" rowspan="1">
+ /// {@link Lucene.Net.Documents.Fieldable#GetBoost() f.getBoost}()
+ /// </td>
+ /// </tr>
+ /// <tr valigh="top">
+ /// <td></td>
+ /// <td align="center"><small>field <i><b>f</b></i> in <i>d</i> named as <i><b>t</b></i></small></td>
+ /// <td></td>
+ /// </tr>
+ /// </table>
+ /// <br> <br>
+ /// However the resulted <i>norm</i> value is {@link #EncodeNorm(float) encoded} as a single byte
+ /// before being stored.
+ /// At search time, the norm byte value is read from the index
+ /// {@link Lucene.Net.Store.Directory directory} and
+ /// {@link #DecodeNorm(byte) decoded} back to a float <i>norm</i> value.
+ /// This encoding/decoding, while reducing index size, comes with the price of
+ /// precision loss - it is not guaranteed that decode(encode(x)) = x.
+ /// For instance, decode(encode(0.89)) = 0.75.
+ /// Also notice that search time is too late to modify this <i>norm</i> part of scoring, e.g. by
+ /// using a different {@link Similarity} for search.
+ /// <br> <br>
+ /// </li>
+ /// </ol>
///
/// </summary>
- /// <seealso cref="SetDefault(Similarity)">
+ /// <seealso cref="#SetDefault(Similarity)">
/// </seealso>
- /// <seealso cref="IndexWriter.SetSimilarity(Similarity)">
+ /// <seealso cref="IndexWriter#SetSimilarity(Similarity)">
/// </seealso>
- /// <seealso cref="Searcher.SetSimilarity(Similarity)">
+ /// <seealso cref="Searcher#SetSimilarity(Similarity)">
/// </seealso>
[Serializable]
public abstract class Similarity
@@ -94,9 +298,9 @@
/// code.
///
/// </summary>
- /// <seealso cref="Searcher.SetSimilarity(Similarity)">
+ /// <seealso cref="Searcher#SetSimilarity(Similarity)">
/// </seealso>
- /// <seealso cref="IndexWriter.SetSimilarity(Similarity)">
+ /// <seealso cref="IndexWriter#SetSimilarity(Similarity)">
/// </seealso>
public static void SetDefault(Similarity similarity)
{
@@ -109,9 +313,9 @@
/// <p>This is initially an instance of {@link DefaultSimilarity}.
///
/// </summary>
- /// <seealso cref="Searcher.SetSimilarity(Similarity)">
+ /// <seealso cref="Searcher#SetSimilarity(Similarity)">
/// </seealso>
- /// <seealso cref="IndexWriter.SetSimilarity(Similarity)">
+ /// <seealso cref="IndexWriter#SetSimilarity(Similarity)">
/// </seealso>
public static Similarity GetDefault()
{
@@ -122,7 +326,7 @@
private static readonly float[] NORM_TABLE = new float[256];
/// <summary>Decodes a normalization factor stored in an index.</summary>
- /// <seealso cref="EncodeNorm(float)">
+ /// <seealso cref="#EncodeNorm(float)">
/// </seealso>
public static float DecodeNorm(byte b)
{
@@ -130,7 +334,7 @@
}
/// <summary>Returns a table for decoding normalization bytes.</summary>
- /// <seealso cref="EncodeNorm(float)">
+ /// <seealso cref="#EncodeNorm(float)">
/// </seealso>
public static float[] GetNormDecoder()
{
@@ -147,7 +351,7 @@
/// and larger values when <code>numTokens</code> is small.
///
/// <p>That these values are computed under {@link
- /// IndexWriter#AddDocument(Lucene.Net.document.Document)} and stored then using
+ /// IndexWriter#AddDocument(Lucene.Net.Documents.Document)} and stored then using
/// {@link #EncodeNorm(float)}. Thus they have limited precision, and documents
/// must be re-indexed if this method is altered.
///
@@ -160,7 +364,7 @@
/// <returns> a normalization factor for hits on this field of this document
///
/// </returns>
- /// <seealso cref="Field.SetBoost(float)">
+ /// <seealso cref="Lucene.Net.Documents.Field#SetBoost(float)">
/// </seealso>
public abstract float LengthNorm(System.String fieldName, int numTokens);
@@ -190,7 +394,7 @@
/// value.
///
/// </summary>
- /// <seealso cref="Field.SetBoost(float)">
+ /// <seealso cref="Lucene.Net.Documents.Field#SetBoost(float)">
/// </seealso>
/// <seealso cref="SmallFloat">
/// </seealso>
@@ -232,7 +436,7 @@
/// when it is large.
///
/// </summary>
- /// <seealso cref="PhraseQuery.SetSlop(int)">
+ /// <seealso cref="PhraseQuery#SetSlop(int)">
/// </seealso>
/// <param name="distance">the edit distance of this sloppy phrase match
/// </param>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SloppyPhraseScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SloppyPhraseScorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SloppyPhraseScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SloppyPhraseScorer.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using TermPositions = Lucene.Net.Index.TermPositions;
namespace Lucene.Net.Search