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 [17/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/Sort.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Sort.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs Tue May 1 11:45:26 2007
@@ -30,7 +30,7 @@
/// and does not need to be stored (unless you happen to want it back with the
/// rest of your document data). In other words:
///
- /// <p><code>document.add (new Field ("byNumber", Integer.toString(x), Field.Store.NO, Field.Index.UN_TOKENIZED));</code></p>
+ /// <p><code>document.add (new Fieldable ("byNumber", Integer.toString(x), Fieldable.Store.NO, Fieldable.Index.UN_TOKENIZED));</code></p>
///
///
/// <p><h3>Valid Types of Values</h3>
@@ -86,12 +86,6 @@
/// fields are in the index and <i>might</i> be used to sort - only by
/// the ones actually used to sort a result set.
///
- /// <p>The cache is cleared each time a new <code>IndexReader</code> is
- /// passed in, or if the value returned by <code>maxDoc()</code>
- /// changes for the current IndexReader. This class is not set up to
- /// be able to efficiently sort hits from more than one index
- /// simultaneously.
- ///
/// <p>Created: Feb 12, 2004 10:53:57 AM
///
/// </summary>
@@ -99,7 +93,7 @@
/// </author>
/// <since> lucene 1.4
/// </since>
- /// <version> $Id: Sort.java 150618 2004-10-18 22:36:54Z dnaber $
+ /// <version> $Id: Sort.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
[Serializable]
public class Sort
@@ -131,7 +125,7 @@
/// automatically.
///
/// </summary>
- /// <seealso cref="SortField.AUTO">
+ /// <seealso cref="SortField#AUTO">
/// </seealso>
public Sort(System.String field)
{
@@ -143,7 +137,7 @@
/// determined automatically.
///
/// </summary>
- /// <seealso cref="SortField.AUTO">
+ /// <seealso cref="SortField#AUTO">
/// </seealso>
public Sort(System.String field, bool reverse)
{
@@ -154,7 +148,7 @@
/// <code>field</code> is determined automatically.
///
/// </summary>
- /// <seealso cref="SortField.AUTO">
+ /// <seealso cref="SortField#AUTO">
/// </seealso>
public Sort(System.String[] fields)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SortComparator.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparator.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
namespace Lucene.Net.Search
@@ -107,6 +108,6 @@
/// </seealso>
/// <seealso cref="ScoreDocComparator">
/// </seealso>
- public /*protected internal*/ abstract System.IComparable GetComparable(System.String termtext);
+ public abstract System.IComparable GetComparable(System.String termtext);
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparatorSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SortComparatorSource.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparatorSource.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparatorSource.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
namespace Lucene.Net.Search
@@ -28,7 +29,7 @@
/// </summary>
/// <author> Tim Jones
/// </author>
- /// <version> $Id: SortComparatorSource.java 150348 2004-05-19 23:05:27Z tjones $
+ /// <version> $Id: SortComparatorSource.java 413201 2006-06-10 01:23:22Z gsingers $
/// </version>
/// <since> 1.4
/// </since>
@@ -38,7 +39,7 @@
/// <summary> Creates a comparator for the field in the given index.</summary>
/// <param name="reader">Index to create comparator for.
/// </param>
- /// <param name="fieldname"> Field to create comparator for.
+ /// <param name="fieldname"> Fieldable to create comparator for.
/// </param>
/// <returns> Comparator of ScoreDoc objects.
/// </returns>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortField.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SortField.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortField.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortField.cs Tue May 1 11:45:26 2007
@@ -30,7 +30,7 @@
/// </author>
/// <since> lucene 1.4
/// </since>
- /// <version> $Id: SortField.java 150357 2004-05-24 22:51:42Z tjones $
+ /// <version> $Id: SortField.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
/// <seealso cref="Sort">
/// </seealso>
@@ -126,7 +126,7 @@
/// </param>
public SortField(System.String field, int type)
{
- this.field = (field != null)?String.Intern(field):field;
+ this.field = (field != null) ? String.Intern(field) : field;
this.type = type;
}
@@ -183,7 +183,7 @@
/// </param>
public SortField(System.String field, SortComparatorSource comparator)
{
- this.field = (field != null)?String.Intern(field):field;
+ this.field = (field != null) ? String.Intern(field) : field;
this.type = CUSTOM;
this.factory = comparator;
}
@@ -197,7 +197,7 @@
/// </param>
public SortField(System.String field, SortComparatorSource comparator, bool reverse)
{
- this.field = (field != null)?String.Intern(field):field;
+ this.field = (field != null) ? String.Intern(field) : field;
this.type = CUSTOM;
this.reverse = reverse;
this.factory = comparator;
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs?view=auto&rev=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs Tue May 1 11:45:26 2007
@@ -0,0 +1,348 @@
+/*
+ * 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 IndexReader = Lucene.Net.Index.IndexReader;
+
+namespace Lucene.Net.Search.Spans
+{
+
+ /// <summary>A Spans that is formed from the ordered subspans of a SpanNearQuery
+ /// where the subspans do not overlap and have a maximum slop between them.
+ /// <p>
+ /// The formed spans only contains minimum slop matches.<br>
+ /// The matching slop is computed from the distance(s) between
+ /// the non overlapping matching Spans.<br>
+ /// Successive matches are always formed from the successive Spans
+ /// of the SpanNearQuery.
+ /// <p>
+ /// The formed spans may contain overlaps when the slop is at least 1.
+ /// For example, when querying using
+ /// <pre>t1 t2 t3</pre>
+ /// with slop at least 1, the fragment:
+ /// <pre>t1 t2 t1 t3 t2 t3</pre>
+ /// matches twice:
+ /// <pre>t1 t2 .. t3 </pre>
+ /// <pre> t1 .. t2 t3</pre>
+ /// </summary>
+ class NearSpansOrdered : Spans
+ {
+ internal class AnonymousClassComparator : System.Collections.IComparer
+ {
+ public AnonymousClassComparator(NearSpansOrdered enclosingInstance)
+ {
+ InitBlock(enclosingInstance);
+ }
+ private void InitBlock(NearSpansOrdered enclosingInstance)
+ {
+ this.enclosingInstance = enclosingInstance;
+ }
+ private NearSpansOrdered enclosingInstance;
+ public NearSpansOrdered Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
+
+ }
+ public virtual int Compare(System.Object o1, System.Object o2)
+ {
+ return ((Spans) o1).Doc() - ((Spans) o2).Doc();
+ }
+ }
+ private void InitBlock()
+ {
+ spanDocComparator = new AnonymousClassComparator(this);
+ }
+ private int allowedSlop;
+ private bool firstTime = true;
+ private bool more = false;
+
+ /// <summary>The spans in the same order as the SpanNearQuery </summary>
+ private Spans[] subSpans;
+
+ /// <summary>Indicates that all subSpans have same doc() </summary>
+ private bool inSameDoc = false;
+
+ private int matchDoc = - 1;
+ private int matchStart = - 1;
+ private int matchEnd = - 1;
+
+ private Spans[] subSpansByDoc;
+ private System.Collections.IComparer spanDocComparator;
+
+ private SpanNearQuery query;
+
+ public NearSpansOrdered(SpanNearQuery spanNearQuery, IndexReader reader)
+ {
+ InitBlock();
+ if (spanNearQuery.GetClauses().Length < 2)
+ {
+ throw new System.ArgumentException("Less than 2 clauses: " + spanNearQuery);
+ }
+ allowedSlop = spanNearQuery.GetSlop();
+ SpanQuery[] clauses = spanNearQuery.GetClauses();
+ subSpans = new Spans[clauses.Length];
+ subSpansByDoc = new Spans[clauses.Length];
+ for (int i = 0; i < clauses.Length; i++)
+ {
+ subSpans[i] = clauses[i].GetSpans(reader);
+ subSpansByDoc[i] = subSpans[i]; // used in toSameDoc()
+ }
+ query = spanNearQuery; // kept for toString() only.
+ }
+
+ // inherit javadocs
+ public virtual int Doc()
+ {
+ return matchDoc;
+ }
+
+ // inherit javadocs
+ public virtual int Start()
+ {
+ return matchStart;
+ }
+
+ // inherit javadocs
+ public virtual int End()
+ {
+ return matchEnd;
+ }
+
+ // inherit javadocs
+ public virtual bool Next()
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ for (int i = 0; i < subSpans.Length; i++)
+ {
+ if (!subSpans[i].Next())
+ {
+ more = false;
+ return false;
+ }
+ }
+ more = true;
+ }
+ return AdvanceAfterOrdered();
+ }
+
+ // inherit javadocs
+ public virtual bool SkipTo(int target)
+ {
+ if (firstTime)
+ {
+ firstTime = false;
+ for (int i = 0; i < subSpans.Length; i++)
+ {
+ if (!subSpans[i].SkipTo(target))
+ {
+ more = false;
+ return false;
+ }
+ }
+ more = true;
+ }
+ else if (more && (subSpans[0].Doc() < target))
+ {
+ if (subSpans[0].SkipTo(target))
+ {
+ inSameDoc = false;
+ }
+ else
+ {
+ more = false;
+ return false;
+ }
+ }
+ return AdvanceAfterOrdered();
+ }
+
+ /// <summary>Advances the subSpans to just after an ordered match with a minimum slop
+ /// that is smaller than the slop allowed by the SpanNearQuery.
+ /// </summary>
+ /// <returns> true iff there is such a match.
+ /// </returns>
+ private bool AdvanceAfterOrdered()
+ {
+ while (more && (inSameDoc || ToSameDoc()))
+ {
+ if (StretchToOrder() && ShrinkToAfterShortestMatch())
+ {
+ return true;
+ }
+ }
+ return false; // no more matches
+ }
+
+
+ /// <summary>Advance the subSpans to the same document </summary>
+ private bool ToSameDoc()
+ {
+ System.Array.Sort(subSpansByDoc, spanDocComparator);
+ int firstIndex = 0;
+ int maxDoc = subSpansByDoc[subSpansByDoc.Length - 1].Doc();
+ while (subSpansByDoc[firstIndex].Doc() != maxDoc)
+ {
+ if (!subSpansByDoc[firstIndex].SkipTo(maxDoc))
+ {
+ more = false;
+ inSameDoc = false;
+ return false;
+ }
+ maxDoc = subSpansByDoc[firstIndex].Doc();
+ if (++firstIndex == subSpansByDoc.Length)
+ {
+ firstIndex = 0;
+ }
+ }
+ for (int i = 0; i < subSpansByDoc.Length; i++)
+ {
+
+ System.Diagnostics.Debug.Assert(subSpansByDoc [i].Doc() == maxDoc,
+ " NearSpansOrdered.toSameDoc() spans " + subSpansByDoc[0]
+ + "\n at doc " + subSpansByDoc[i].Doc()
+ + ", but should be at " + maxDoc);
+ }
+ inSameDoc = true;
+ return true;
+ }
+
+ /// <summary>Check whether two Spans in the same document are ordered.</summary>
+ /// <param name="spans1">
+ /// </param>
+ /// <param name="spans2">
+ /// </param>
+ /// <returns> true iff spans1 starts before spans2
+ /// or the spans start at the same position,
+ /// and spans1 ends before spans2.
+ /// </returns>
+ internal static bool DocSpansOrdered(Spans spans1, Spans spans2)
+ {
+ System.Diagnostics.Debug.Assert(spans1.Doc() == spans2.Doc(), "doc1 " + spans1.Doc() + " != doc2 " + spans2.Doc());
+ int start1 = spans1.Start();
+ int start2 = spans2.Start();
+ /* Do not call DocSpansOrdered(int,int,int,int) to avoid invoking .end() : */
+ return (start1 == start2)?(spans1.End() < spans2.End()):(start1 < start2);
+ }
+
+ /// <summary>Like {@link #DocSpansOrdered(Spans,Spans)}, but use the spans
+ /// starts and ends as parameters.
+ /// </summary>
+ private static bool DocSpansOrdered(int start1, int end1, int start2, int end2)
+ {
+ return (start1 == start2) ? (end1 < end2) : (start1 < start2);
+ }
+
+ /// <summary>Order the subSpans within the same document by advancing all later spans
+ /// after the previous one.
+ /// </summary>
+ private bool StretchToOrder()
+ {
+ matchDoc = subSpans[0].Doc();
+ for (int i = 1; inSameDoc && (i < subSpans.Length); i++)
+ {
+ while (!DocSpansOrdered(subSpans[i - 1], subSpans[i]))
+ {
+ if (!subSpans[i].Next())
+ {
+ inSameDoc = false;
+ more = false;
+ break;
+ }
+ else if (matchDoc != subSpans[i].Doc())
+ {
+ inSameDoc = false;
+ break;
+ }
+ }
+ }
+ return inSameDoc;
+ }
+
+ /// <summary>The subSpans are ordered in the same doc, so there is a possible match.
+ /// Compute the slop while making the match as short as possible by advancing
+ /// all subSpans except the last one in reverse order.
+ /// </summary>
+ private bool ShrinkToAfterShortestMatch()
+ {
+ matchStart = subSpans[subSpans.Length - 1].Start();
+ matchEnd = subSpans[subSpans.Length - 1].End();
+ int matchSlop = 0;
+ int lastStart = matchStart;
+ int lastEnd = matchEnd;
+ for (int i = subSpans.Length - 2; i >= 0; i--)
+ {
+ Spans prevSpans = subSpans[i];
+ int prevStart = prevSpans.Start();
+ int prevEnd = prevSpans.End();
+ while (true)
+ {
+ // Advance prevSpans until after (lastStart, lastEnd)
+ if (!prevSpans.Next())
+ {
+ inSameDoc = false;
+ more = false;
+ break; // Check remaining subSpans for final match.
+ }
+ else if (matchDoc != prevSpans.Doc())
+ {
+ inSameDoc = false; // The last subSpans is not advanced here.
+ break; // Check remaining subSpans for last match in this document.
+ }
+ else
+ {
+ int ppStart = prevSpans.Start();
+ int ppEnd = prevSpans.End(); // Cannot avoid invoking .end()
+ if (!DocSpansOrdered(ppStart, ppEnd, lastStart, lastEnd))
+ {
+ break; // Check remaining subSpans.
+ }
+ else
+ {
+ // prevSpans still before (lastStart, lastEnd)
+ prevStart = ppStart;
+ prevEnd = ppEnd;
+ }
+ }
+ }
+ System.Diagnostics.Debug.Assert(prevStart <= matchStart);
+ if (matchStart > prevEnd)
+ {
+ // Only non overlapping spans add to slop.
+ matchSlop += (matchStart - prevEnd);
+ }
+ /* Do not break on (matchSlop > allowedSlop) here to make sure
+ * that subSpans[0] is advanced after the match, if any.
+ */
+ matchStart = prevStart;
+ lastStart = prevStart;
+ lastEnd = prevEnd;
+ }
+ return matchSlop <= allowedSlop; // ordered and allowed slop
+ }
+
+ public override System.String ToString()
+ {
+ return GetType().FullName + "(" + query.ToString() + ")@" + (firstTime?"START":(more?(Doc() + ":" + Start() + "-" + End()):"END"));
+ }
+ }
+}
\ No newline at end of file
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs?view=auto&rev=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs Tue May 1 11:45:26 2007
@@ -0,0 +1,358 @@
+/*
+ * 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 IndexReader = Lucene.Net.Index.IndexReader;
+using PriorityQueue = Lucene.Net.Util.PriorityQueue;
+
+namespace Lucene.Net.Search.Spans
+{
+
+ class NearSpansUnordered : Spans
+ {
+ private SpanNearQuery query;
+
+ private System.Collections.IList ordered = new System.Collections.ArrayList(); // spans in query order
+ private int slop; // from query
+
+ private SpansCell first; // linked list of spans
+ private SpansCell last; // sorted by doc only
+
+ private int totalLength; // sum of current lengths
+
+ private CellQueue queue; // sorted queue of spans
+ private SpansCell max; // max element in queue
+
+ private bool more = true; // true iff not done
+ private bool firstTime = true; // true before first next()
+
+ private class CellQueue : PriorityQueue
+ {
+ private void InitBlock(NearSpansUnordered enclosingInstance)
+ {
+ this.enclosingInstance = enclosingInstance;
+ }
+ private NearSpansUnordered enclosingInstance;
+ public NearSpansUnordered Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
+
+ }
+ public CellQueue(NearSpansUnordered enclosingInstance, int size)
+ {
+ InitBlock(enclosingInstance);
+ Initialize(size);
+ }
+
+ public override bool LessThan(System.Object o1, System.Object o2)
+ {
+ SpansCell spans1 = (SpansCell) o1;
+ SpansCell spans2 = (SpansCell) o2;
+ if (spans1.Doc() == spans2.Doc())
+ {
+ return NearSpansOrdered.DocSpansOrdered(spans1, spans2);
+ }
+ else
+ {
+ return spans1.Doc() < spans2.Doc();
+ }
+ }
+ }
+
+
+ /// <summary>Wraps a Spans, and can be used to form a linked list. </summary>
+ private class SpansCell : Spans
+ {
+ private void InitBlock(NearSpansUnordered enclosingInstance)
+ {
+ this.enclosingInstance = enclosingInstance;
+ }
+ private NearSpansUnordered enclosingInstance;
+ public NearSpansUnordered Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
+
+ }
+ private Spans spans;
+ internal SpansCell next;
+ private int length = - 1;
+ private int index;
+
+ public SpansCell(NearSpansUnordered enclosingInstance, Spans spans, int index)
+ {
+ InitBlock(enclosingInstance);
+ this.spans = spans;
+ this.index = index;
+ }
+
+ public virtual bool Next()
+ {
+ return Adjust(spans.Next());
+ }
+
+ public virtual bool SkipTo(int target)
+ {
+ return Adjust(spans.SkipTo(target));
+ }
+
+ private bool Adjust(bool condition)
+ {
+ if (length != - 1)
+ {
+ Enclosing_Instance.totalLength -= length; // subtract old length
+ }
+ if (condition)
+ {
+ length = End() - Start();
+ Enclosing_Instance.totalLength += length; // add new length
+
+ if (Enclosing_Instance.max == null || Doc() > Enclosing_Instance.max.Doc() || (Doc() == Enclosing_Instance.max.Doc()) && (End() > Enclosing_Instance.max.End()))
+ {
+ Enclosing_Instance.max = this;
+ }
+ }
+ Enclosing_Instance.more = condition;
+ return condition;
+ }
+
+ public virtual int Doc()
+ {
+ return spans.Doc();
+ }
+ public virtual int Start()
+ {
+ return spans.Start();
+ }
+ public virtual int End()
+ {
+ return spans.End();
+ }
+
+ public override System.String ToString()
+ {
+ return spans.ToString() + "#" + index;
+ }
+ }
+
+
+ public NearSpansUnordered(SpanNearQuery query, IndexReader reader)
+ {
+ this.query = query;
+ this.slop = query.GetSlop();
+
+ SpanQuery[] clauses = query.GetClauses();
+ queue = new CellQueue(this, clauses.Length);
+ for (int i = 0; i < clauses.Length; i++)
+ {
+ SpansCell cell = new SpansCell(this, clauses[i].GetSpans(reader), i);
+ ordered.Add(cell);
+ }
+ }
+
+ public virtual bool Next()
+ {
+ if (firstTime)
+ {
+ InitList(true);
+ ListToQueue(); // initialize queue
+ firstTime = false;
+ }
+ else if (more)
+ {
+ if (Min().Next())
+ {
+ // trigger further scanning
+ queue.AdjustTop(); // maintain queue
+ }
+ else
+ {
+ more = false;
+ }
+ }
+
+ while (more)
+ {
+
+ bool queueStale = false;
+
+ if (Min().Doc() != max.Doc())
+ {
+ // maintain list
+ QueueToList();
+ queueStale = true;
+ }
+
+ // skip to doc w/ all clauses
+
+ while (more && first.Doc() < last.Doc())
+ {
+ more = first.SkipTo(last.Doc()); // skip first upto last
+ FirstToLast(); // and move it to the end
+ queueStale = true;
+ }
+
+ if (!more)
+ return false;
+
+ // found doc w/ all clauses
+
+ if (queueStale)
+ {
+ // maintain the queue
+ ListToQueue();
+ queueStale = false;
+ }
+
+ if (AtMatch())
+ {
+ return true;
+ }
+
+ more = Min().Next();
+ if (more)
+ {
+ queue.AdjustTop(); // maintain queue
+ }
+ }
+ return false; // no more matches
+ }
+
+ public virtual bool SkipTo(int target)
+ {
+ if (firstTime)
+ {
+ // initialize
+ InitList(false);
+ for (SpansCell cell = first; more && cell != null; cell = cell.next)
+ {
+ more = cell.SkipTo(target); // skip all
+ }
+ if (more)
+ {
+ ListToQueue();
+ }
+ firstTime = false;
+ }
+ else
+ {
+ // normal case
+ while (more && Min().Doc() < target)
+ {
+ // skip as needed
+ if (Min().SkipTo(target))
+ {
+ queue.AdjustTop();
+ }
+ else
+ {
+ more = false;
+ }
+ }
+ }
+ return more && (AtMatch() || Next());
+ }
+
+ private SpansCell Min()
+ {
+ return (SpansCell) queue.Top();
+ }
+
+ public virtual int Doc()
+ {
+ return Min().Doc();
+ }
+ public virtual int Start()
+ {
+ return Min().Start();
+ }
+ public virtual int End()
+ {
+ return max.End();
+ }
+
+
+ public override System.String ToString()
+ {
+ return GetType().FullName + "(" + query.ToString() + ")@" + (firstTime?"START":(more?(Doc() + ":" + Start() + "-" + End()):"END"));
+ }
+
+ private void InitList(bool next)
+ {
+ for (int i = 0; more && i < ordered.Count; i++)
+ {
+ SpansCell cell = (SpansCell) ordered[i];
+ if (next)
+ more = cell.Next(); // move to first entry
+ if (more)
+ {
+ AddToList(cell); // add to list
+ }
+ }
+ }
+
+ private void AddToList(SpansCell cell)
+ {
+ if (last != null)
+ {
+ // add next to end of list
+ last.next = cell;
+ }
+ else
+ first = cell;
+ last = cell;
+ cell.next = null;
+ }
+
+ private void FirstToLast()
+ {
+ last.next = first; // move first to end of list
+ last = first;
+ first = first.next;
+ last.next = null;
+ }
+
+ private void QueueToList()
+ {
+ last = first = null;
+ while (queue.Top() != null)
+ {
+ AddToList((SpansCell) queue.Pop());
+ }
+ }
+
+ private void ListToQueue()
+ {
+ queue.Clear(); // rebuild queue
+ for (SpansCell cell = first; cell != null; cell = cell.next)
+ {
+ queue.Put(cell); // add to queue from list
+ }
+ }
+
+ private bool AtMatch()
+ {
+ return (Min().Doc() == max.Doc()) && ((max.End() - Min().Start() - totalLength) <= slop);
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/Package.html?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Package.html (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Package.html Tue May 1 11:45:26 2007
@@ -1,76 +1,76 @@
-<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head></head>
-<body>
-The calculus of spans.
-
-<p>A span is a <code><doc,startPosition,endPosition></code> tuple.</p>
-
-<p>The following span query operators are implemented:
-
-<ul>
-
-<li>A <a href = "SpanTermQuery.html">SpanTermQuery</a> matches all spans
-containing a particular <a href = "index/Term.html">Term</a>.</li>
-
-<li> A <a href = "SpanNearQuery.html">SpanNearQuery</a> matches spans
-which occur near one another, and can be used to implement things like
-phrase search (when constructed from <a
-href="SpanTermQuery.html">SpanTermQueries</a>) and inter-phrase
-proximity (when constructed from other <a
-href="SpanNearQuery.html">SpanNearQueries</a>).</li>
-
-<li>A <a href = "SpanOrQuery.html">SpanOrQuery</a> merges spans from a
-number of other <a href = "SpanQuery.html">SpanQueries</a>.</li>
-
-<li>A <a href = "SpanNotQuery.html">SpanNotQuery</a> removes spans
-matching one <a href = "SpanQuery.html">SpanQuery</a> which overlap
-another. This can be used, e.g., to implement within-paragraph
-search.</li>
-
-<li>A <a href = "SpanFirstQuery.html">SpanFirstQuery</a> matches spans
-matching <code>q</code> whose end position is less than
-<code>n</code>. This can be used to constrain matches to the first
-part of the document.</li>
-
-</ul>
-
-In all cases, output spans are minimally inclusive. In other words, a
-span formed by matching a span in x and y starts at the lesser of the
-two starts and ends at the greater of the two ends.
-</p>
-
-<p>For example, a span query which matches "John Kerry" within ten
-words of "George Bush" within the first 100 words of the document
-could be constructed with:
-<pre>
-SpanQuery john = new SpanTermQuery(new Term("content", "john"));
-SpanQuery kerry = new SpanTermQuery(new Term("content", "kerry"));
-SpanQuery george = new SpanTermQuery(new Term("content", "george"));
-SpanQuery bush = new SpanTermQuery(new Term("content", "bush"));
-
-SpanQuery johnKerry =
- new SpanNearQuery(new SpanQuery[] {john, kerry}, 0, true);
-
-SpanQuery georgeBush =
- new SpanNearQuery(new SpanQuery[] {george, bush}, 0, true);
-
-SpanQuery johnKerryNearGeorgeBush =
- new SpanNearQuery(new SpanQuery[] {johnKerry, georgeBush}, 10, false);
-
-SpanQuery johnKerryNearGeorgeBushAtStart =
- new SpanFirstQuery(johnKerryNearGeorgeBush, 100);
-</pre>
-
-<p>Span queries may be freely intermixed with other Lucene queries.
-So, for example, the above query can be restricted to documents which
-also use the word "iraq" with:
-
-<pre>
-Query query = new BooleanQuery();
-query.add(johnKerryNearGeorgeBushAtStart, true, false);
-query.add(new TermQuery("content", "iraq"), true, false);
-</pre>
-
-</body>
-</html>
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head></head>
+<body>
+The calculus of spans.
+
+<p>A span is a <code><doc,startPosition,endPosition></code> tuple.</p>
+
+<p>The following span query operators are implemented:
+
+<ul>
+
+<li>A <a href="SpanTermQuery.html">SpanTermQuery</a> matches all spans
+containing a particular <a href="../../index/Term.html">Term</a>.</li>
+
+<li> A <a href="SpanNearQuery.html">SpanNearQuery</a> matches spans
+which occur near one another, and can be used to implement things like
+phrase search (when constructed from <a
+href="SpanTermQuery.html">SpanTermQueries</a>) and inter-phrase
+proximity (when constructed from other <a
+href="SpanNearQuery.html">SpanNearQueries</a>).</li>
+
+<li>A <a href="SpanOrQuery.html">SpanOrQuery</a> merges spans from a
+number of other <a href="SpanQuery.html">SpanQueries</a>.</li>
+
+<li>A <a href="SpanNotQuery.html">SpanNotQuery</a> removes spans
+matching one <a href="SpanQuery.html">SpanQuery</a> which overlap
+another. This can be used, e.g., to implement within-paragraph
+search.</li>
+
+<li>A <a href="SpanFirstQuery.html">SpanFirstQuery</a> matches spans
+matching <code>q</code> whose end position is less than
+<code>n</code>. This can be used to constrain matches to the first
+part of the document.</li>
+
+</ul>
+
+In all cases, output spans are minimally inclusive. In other words, a
+span formed by matching a span in x and y starts at the lesser of the
+two starts and ends at the greater of the two ends.
+</p>
+
+<p>For example, a span query which matches "John Kerry" within ten
+words of "George Bush" within the first 100 words of the document
+could be constructed with:
+<pre>
+SpanQuery john = new SpanTermQuery(new Term("content", "john"));
+SpanQuery kerry = new SpanTermQuery(new Term("content", "kerry"));
+SpanQuery george = new SpanTermQuery(new Term("content", "george"));
+SpanQuery bush = new SpanTermQuery(new Term("content", "bush"));
+
+SpanQuery johnKerry =
+ new SpanNearQuery(new SpanQuery[] {john, kerry}, 0, true);
+
+SpanQuery georgeBush =
+ new SpanNearQuery(new SpanQuery[] {george, bush}, 0, true);
+
+SpanQuery johnKerryNearGeorgeBush =
+ new SpanNearQuery(new SpanQuery[] {johnKerry, georgeBush}, 10, false);
+
+SpanQuery johnKerryNearGeorgeBushAtStart =
+ new SpanFirstQuery(johnKerryNearGeorgeBush, 100);
+</pre>
+
+<p>Span queries may be freely intermixed with other Lucene queries.
+So, for example, the above query can be restricted to documents which
+also use the word "iraq" with:
+
+<pre>
+Query query = new BooleanQuery();
+query.add(johnKerryNearGeorgeBushAtStart, true, false);
+query.add(new TermQuery("content", "iraq"), true, false);
+</pre>
+
+</body>
+</html>
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Query = Lucene.Net.Search.Query;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
@@ -121,12 +122,12 @@
return match.GetField();
}
- /// <summary>Returns a collection of all terms matched by this query.</summary>
- /// <deprecated> use ExtractTerms instead
- /// </deprecated>
- /// <seealso cref="#ExtractTerms(Set)">
- /// </seealso>
- public override System.Collections.ICollection GetTerms()
+ /// <summary>Returns a collection of all terms matched by this query.</summary>
+ /// <deprecated> use extractTerms instead
+ /// </deprecated>
+ /// <seealso cref="#ExtractTerms(Set)">
+ /// </seealso>
+ public override System.Collections.ICollection GetTerms()
{
return match.GetTerms();
}
@@ -143,12 +144,12 @@
return buffer.ToString();
}
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- match.ExtractTerms(terms);
- }
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ match.ExtractTerms(terms);
+ }
- public override Spans GetSpans(IndexReader reader)
+ public override Spans GetSpans(IndexReader reader)
{
return new AnonymousClassSpans(reader, this);
}
@@ -174,23 +175,23 @@
}
}
- public override bool Equals(System.Object o)
- {
- if (this == o)
- return true;
- if (!(o is SpanFirstQuery))
- return false;
-
- SpanFirstQuery other = (SpanFirstQuery) o;
- return this.end == other.end && this.match.Equals(other.match) && this.GetBoost() == other.GetBoost();
- }
-
- public override int GetHashCode()
- {
- int h = match.GetHashCode();
- h ^= ((h << 8) | ((int) (((uint) h) >> 25))); // reversible
- h ^= System.Convert.ToInt32(GetBoost()) ^ end;
- return h;
- }
- }
+ public override bool Equals(System.Object o)
+ {
+ if (this == o)
+ return true;
+ if (!(o is SpanFirstQuery))
+ return false;
+
+ SpanFirstQuery other = (SpanFirstQuery) o;
+ return this.end == other.end && this.match.Equals(other.match) && this.GetBoost() == other.GetBoost();
+ }
+
+ public override int GetHashCode()
+ {
+ int h = match.GetHashCode();
+ h ^= ((h << 8) | ((int) (((uint) h) >> 25))); // reversible
+ h ^= System.Convert.ToInt32(GetBoost()) ^ end;
+ return h;
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNearQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanNearQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNearQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNearQuery.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Query = Lucene.Net.Search.Query;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
@@ -88,12 +89,12 @@
return field;
}
- /// <summary>Returns a collection of all terms matched by this query.</summary>
- /// <deprecated> use extractTerms instead
- /// </deprecated>
- /// <seealso cref="#extractTerms(Set)">
- /// </seealso>
- public override System.Collections.ICollection GetTerms()
+ /// <summary>Returns a collection of all terms matched by this query.</summary>
+ /// <deprecated> use extractTerms instead
+ /// </deprecated>
+ /// <seealso cref="#ExtractTerms(Set)">
+ /// </seealso>
+ public override System.Collections.ICollection GetTerms()
{
System.Collections.ArrayList terms = new System.Collections.ArrayList();
System.Collections.IEnumerator i = clauses.GetEnumerator();
@@ -105,18 +106,18 @@
return terms;
}
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- System.Collections.IEnumerator i = clauses.GetEnumerator();
- while (i.MoveNext())
- {
- SpanQuery clause = (SpanQuery) i.Current;
- clause.ExtractTerms(terms);
- }
- }
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ System.Collections.IEnumerator i = clauses.GetEnumerator();
+ while (i.MoveNext())
+ {
+ SpanQuery clause = (SpanQuery) i.Current;
+ clause.ExtractTerms(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("spanNear([");
@@ -149,7 +150,7 @@
// optimize 1-clause case
return ((SpanQuery) clauses[0]).GetSpans(reader);
- return new NearSpans(this, reader);
+ return inOrder ? (Spans) new NearSpansOrdered(this, reader) : (Spans) new NearSpansUnordered(this, reader);
}
public override Query Rewrite(IndexReader reader)
@@ -191,34 +192,33 @@
return false;
if (slop != spanNearQuery.slop)
return false;
-
- if (clauses.Count != spanNearQuery.clauses.Count)
- return false;
- System.Collections.IEnumerator iter1 = clauses.GetEnumerator();
- System.Collections.IEnumerator iter2 = spanNearQuery.clauses.GetEnumerator();
- while (iter1.MoveNext() && iter2.MoveNext())
- {
- SpanQuery item1 = (SpanQuery) iter1.Current;
- SpanQuery item2 = (SpanQuery) iter2.Current;
- if (!item1.Equals(item2))
- return false;
- }
+ if (clauses.Count != spanNearQuery.clauses.Count)
+ return false;
+ System.Collections.IEnumerator iter1 = clauses.GetEnumerator();
+ System.Collections.IEnumerator iter2 = spanNearQuery.clauses.GetEnumerator();
+ while (iter1.MoveNext() && iter2.MoveNext())
+ {
+ SpanQuery item1 = (SpanQuery) iter1.Current;
+ SpanQuery item2 = (SpanQuery) iter2.Current;
+ if (!item1.Equals(item2))
+ return false;
+ }
return GetBoost() == spanNearQuery.GetBoost();
}
public override int GetHashCode()
{
- long result;
- result = clauses.GetHashCode();
- // Mix bits before folding in things like boost, since it could cancel the
- // last element of clauses. This particular mix also serves to
- // differentiate SpanNearQuery hashcodes from others.
- result ^= ((result << 14) | (result >> 19)); // reversible
- result += System.Convert.ToInt32(GetBoost());
- result += slop;
- result ^= (inOrder ? (long) 0x99AFD3BD : 0);
- return (int) result;
+ long result;
+ result = clauses.GetHashCode();
+ // Mix bits before folding in things like boost, since it could cancel the
+ // last element of clauses. This particular mix also serves to
+ // differentiate SpanNearQuery hashcodes from others.
+ result ^= ((result << 14) | (result >> 19)); // reversible
+ result += System.Convert.ToInt32(GetBoost());
+ result += slop;
+ result ^= (inOrder ? (long) 0x99AFD3BD : 0);
+ return (int) result;
}
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNotQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanNotQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNotQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNotQuery.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Query = Lucene.Net.Search.Query;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
@@ -39,7 +40,7 @@
this.enclosingInstance = enclosingInstance;
includeSpans = Enclosing_Instance.include.GetSpans(reader);
excludeSpans = Enclosing_Instance.exclude.GetSpans(reader);
- moreExclude = excludeSpans.Next();
+ moreExclude = excludeSpans.Next();
}
private Lucene.Net.Index.IndexReader reader;
private SpanNotQuery enclosingInstance;
@@ -156,20 +157,20 @@
return include.GetField();
}
- /// <summary>Returns a collection of all terms matched by this query.</summary>
- /// <deprecated> use extractTerms instead
- /// </deprecated>
- /// <seealso cref="#ExtractTerms(Set)">
- /// </seealso>
- public override System.Collections.ICollection GetTerms()
+ /// <summary>Returns a collection of all terms matched by this query.</summary>
+ /// <deprecated> use extractTerms instead
+ /// </deprecated>
+ /// <seealso cref="#ExtractTerms(Set)">
+ /// </seealso>
+ public override System.Collections.ICollection GetTerms()
{
return include.GetTerms();
}
-
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- include.ExtractTerms(terms);
- }
+
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ include.ExtractTerms(terms);
+ }
public override System.String ToString(System.String field)
{
@@ -217,26 +218,26 @@
}
}
- /// <summary>Returns true iff <code>o</code> is equal to this. </summary>
- public override bool Equals(System.Object o)
- {
- if (this == o)
- return true;
- if (!(o is SpanNotQuery))
- return false;
-
- SpanNotQuery other = (SpanNotQuery) o;
- return this.include.Equals(other.include) && this.exclude.Equals(other.exclude) && this.GetBoost() == other.GetBoost();
- }
-
- public override int GetHashCode()
- {
- int h = include.GetHashCode();
- h = (h << 1) | ((int) (((uint) h) >> 31)); // rotate left
- h ^= exclude.GetHashCode();
- h = (h << 1) | ((int) (((uint) h) >> 31)); // rotate left
- h ^= System.Convert.ToInt32(GetBoost());
- return h;
- }
- }
+ /// <summary>Returns true iff <code>o</code> is equal to this. </summary>
+ public override bool Equals(System.Object o)
+ {
+ if (this == o)
+ return true;
+ if (!(o is SpanNotQuery))
+ return false;
+
+ SpanNotQuery other = (SpanNotQuery) o;
+ return this.include.Equals(other.include) && this.exclude.Equals(other.exclude) && this.GetBoost() == other.GetBoost();
+ }
+
+ public override int GetHashCode()
+ {
+ int h = include.GetHashCode();
+ h = (h << 1) | ((int) (((uint) h) >> 31)); // rotate left
+ h ^= exclude.GetHashCode();
+ h = (h << 1) | ((int) (((uint) h) >> 31)); // rotate left
+ h ^= System.Convert.ToInt32(GetBoost());
+ return h;
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanOrQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs Tue May 1 11:45:26 2007
@@ -16,10 +16,11 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
-using Query = Lucene.Net.Search.Query;
using PriorityQueue = Lucene.Net.Util.PriorityQueue;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
+using Query = Lucene.Net.Search.Query;
namespace Lucene.Net.Search.Spans
{
@@ -38,14 +39,6 @@
{
this.reader = reader;
this.enclosingInstance = enclosingInstance;
- all = new System.Collections.ArrayList(Enclosing_Instance.clauses.Count);
- queue = new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
- System.Collections.IEnumerator i = Enclosing_Instance.clauses.GetEnumerator();
- while (i.MoveNext())
- {
- // initialize all
- all.Add(((SpanQuery) i.Current).GetSpans(reader));
- }
}
private Lucene.Net.Index.IndexReader reader;
private SpanOrQuery enclosingInstance;
@@ -57,31 +50,28 @@
}
}
- private System.Collections.IList all;
- private SpanQueue queue;
-
- private bool firstTime = true;
+ private SpanQueue queue = null;
- public virtual bool Next()
+ private bool InitSpanQueue(int target)
{
- if (firstTime)
+ queue = new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
+ System.Collections.IEnumerator i = Enclosing_Instance.clauses.GetEnumerator();
+ while (i.MoveNext())
{
- // first time -- initialize
- for (int i = 0; i < all.Count; i++)
+ Spans spans = ((SpanQuery) i.Current).GetSpans(reader);
+ if (((target == - 1) && spans.Next()) || ((target != - 1) && spans.SkipTo(target)))
{
- Spans spans = (Spans) all[i];
- if (spans.Next())
- {
- // move to first entry
- queue.Put(spans); // build queue
- }
- else
- {
- all.RemoveAt(i--);
- }
+ queue.Put(spans);
}
- firstTime = false;
- return queue.Size() != 0;
+ }
+ return queue.Size() != 0;
+ }
+
+ public virtual bool Next()
+ {
+ if (queue == null)
+ {
+ return InitSpanQueue(- 1);
}
if (queue.Size() == 0)
@@ -97,8 +87,7 @@
return true;
}
- all.Remove(queue.Pop()); // exhausted a clause
-
+ queue.Pop(); // exhausted a clause
return queue.Size() != 0;
}
@@ -109,35 +98,20 @@
public virtual bool SkipTo(int target)
{
- if (firstTime)
+ if (queue == null)
{
- for (int i = 0; i < all.Count; i++)
- {
- Spans spans = (Spans) all[i];
- if (spans.SkipTo(target))
- {
- // skip each spans in all
- queue.Put(spans); // build queue
- }
- else
- {
- all.RemoveAt(i--);
- }
- }
- firstTime = false;
+ return InitSpanQueue(target);
}
- else
+
+ while (queue.Size() != 0 && Top().Doc() < target)
{
- while (queue.Size() != 0 && Top().Doc() < target)
+ if (Top().SkipTo(target))
+ {
+ queue.AdjustTop();
+ }
+ else
{
- if (Top().SkipTo(target))
- {
- queue.AdjustTop();
- }
- else
- {
- all.Remove(queue.Pop());
- }
+ queue.Pop();
}
}
@@ -159,7 +133,7 @@
public override System.String ToString()
{
- return "spans(" + Enclosing_Instance + ")@" + (firstTime?"START":(queue.Size() > 0?(Doc() + ":" + Start() + "-" + End()):"END"));
+ return "spans(" + Enclosing_Instance + ")@" + ((queue == null) ? "START" : (queue.Size() > 0 ? (Doc() + ":" + Start() + "-" + End()) : "END"));
}
}
private System.Collections.ArrayList clauses;
@@ -190,7 +164,7 @@
/// <summary>Return the clauses whose spans are matched. </summary>
public virtual SpanQuery[] GetClauses()
{
- return (SpanQuery[]) clauses.ToArray(typeof(SpanQuery[]));
+ return (SpanQuery[]) clauses.ToArray(typeof(SpanQuery[]));
}
public override System.String GetField()
@@ -198,12 +172,12 @@
return field;
}
- /// <summary>Returns a collection of all terms matched by this query.</summary>
- /// <deprecated> use ExtractTerms instead
- /// </deprecated>
- /// <seealso cref="#ExtractTerms(Set)">
- /// </seealso>
- public override System.Collections.ICollection GetTerms()
+ /// <summary>Returns a collection of all terms matched by this query.</summary>
+ /// <deprecated> use extractTerms instead
+ /// </deprecated>
+ /// <seealso cref="#ExtractTerms(Set)">
+ /// </seealso>
+ public override System.Collections.ICollection GetTerms()
{
System.Collections.ArrayList terms = new System.Collections.ArrayList();
System.Collections.IEnumerator i = clauses.GetEnumerator();
@@ -214,19 +188,18 @@
}
return terms;
}
-
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- System.Collections.IEnumerator i = clauses.GetEnumerator();
- while (i.MoveNext())
- {
- SpanQuery clause = (SpanQuery) i.Current;
- clause.ExtractTerms(terms);
- }
- }
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ System.Collections.IEnumerator i = clauses.GetEnumerator();
+ while (i.MoveNext())
+ {
+ SpanQuery clause = (SpanQuery) i.Current;
+ clause.ExtractTerms(terms);
+ }
+ }
- public override Query Rewrite(IndexReader reader)
+ public override Query Rewrite(IndexReader reader)
{
SpanOrQuery clone = null;
for (int i = 0; i < clauses.Count; i++)
@@ -289,10 +262,10 @@
public override int GetHashCode()
{
- int h = clauses.GetHashCode();
- h ^= ((h << 10) | (h >> 23));
- h ^= System.Convert.ToInt32(GetBoost());
- return h;
+ int h = clauses.GetHashCode();
+ h ^= ((h << 10) | (h >> 23));
+ h ^= System.Convert.ToInt32(GetBoost());
+ return h;
}
private class SpanQueue : PriorityQueue
@@ -342,7 +315,7 @@
public override Spans GetSpans(IndexReader reader)
{
if (clauses.Count == 1)
- // optimize 1-clause case
+ // optimize 1-clause case
return ((SpanQuery) clauses[0]).GetSpans(reader);
return new AnonymousClassSpans(reader, this);
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanQuery.cs Tue May 1 11:45:26 2007
@@ -16,10 +16,11 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Query = Lucene.Net.Search.Query;
-using Searcher = Lucene.Net.Search.Searcher;
using Weight = Lucene.Net.Search.Weight;
+using Searcher = Lucene.Net.Search.Searcher;
namespace Lucene.Net.Search.Spans
{
@@ -36,12 +37,12 @@
/// <summary>Returns the name of the field matched by this query.</summary>
public abstract System.String GetField();
- /// <summary>Returns a collection of all terms matched by this query.</summary>
- /// <deprecated> use extractTerms instead
- /// </deprecated>
- /// <seealso cref="Query#extractTerms(Set)">
- /// </seealso>
- public abstract System.Collections.ICollection GetTerms();
+ /// <summary>Returns a collection of all terms matched by this query.</summary>
+ /// <deprecated> use extractTerms instead
+ /// </deprecated>
+ /// <seealso cref="Query#ExtractTerms(Set)">
+ /// </seealso>
+ public abstract System.Collections.ICollection GetTerms();
protected internal override Weight CreateWeight(Searcher searcher)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanScorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanScorer.cs Tue May 1 11:45:26 2007
@@ -16,10 +16,11 @@
*/
using System;
-using Explanation = Lucene.Net.Search.Explanation;
+
+using Weight = Lucene.Net.Search.Weight;
using Scorer = Lucene.Net.Search.Scorer;
+using Explanation = Lucene.Net.Search.Explanation;
using Similarity = Lucene.Net.Search.Similarity;
-using Weight = Lucene.Net.Search.Weight;
namespace Lucene.Net.Search.Spans
{
@@ -44,8 +45,8 @@
this.norms = norms;
this.weight = weight;
this.value_Renamed = weight.GetValue();
- doc = - 1;
- }
+ doc = - 1;
+ }
public override bool Next()
{
@@ -54,55 +55,55 @@
more = spans.Next();
firstTime = false;
}
- return SetFreqCurrentDoc();
- }
+ return SetFreqCurrentDoc();
+ }
public override bool SkipTo(int target)
{
- if (firstTime)
- {
- more = spans.SkipTo(target);
- firstTime = false;
- }
- if (!more)
- {
- return false;
- }
- if (spans.Doc() < target)
- {
- // setFreqCurrentDoc() leaves spans.doc() ahead
- more = spans.SkipTo(target);
- }
- return SetFreqCurrentDoc();
- }
-
- private bool SetFreqCurrentDoc()
- {
- if (!more)
- {
- return false;
- }
- doc = spans.Doc();
- freq = 0.0f;
- while (more && doc == spans.Doc())
- {
- int matchLength = spans.End() - spans.Start();
- freq += GetSimilarity().SloppyFreq(matchLength);
- more = spans.Next();
- }
- return more || (freq != 0);
- }
-
- public override int Doc()
- {
- return doc;
- }
-
- public override float Score()
- {
- float raw = GetSimilarity().Tf(freq) * value_Renamed; // raw score
- return raw * Similarity.DecodeNorm(norms[doc]); // normalize
- }
+ if (firstTime)
+ {
+ more = spans.SkipTo(target);
+ firstTime = false;
+ }
+ if (!more)
+ {
+ return false;
+ }
+ if (spans.Doc() < target)
+ {
+ // setFreqCurrentDoc() leaves spans.doc() ahead
+ more = spans.SkipTo(target);
+ }
+ return SetFreqCurrentDoc();
+ }
+
+ private bool SetFreqCurrentDoc()
+ {
+ if (!more)
+ {
+ return false;
+ }
+ doc = spans.Doc();
+ freq = 0.0f;
+ while (more && doc == spans.Doc())
+ {
+ int matchLength = spans.End() - spans.Start();
+ freq += GetSimilarity().SloppyFreq(matchLength);
+ more = spans.Next();
+ }
+ return more || (freq != 0);
+ }
+
+ public override int Doc()
+ {
+ return doc;
+ }
+
+ public override float Score()
+ {
+ float raw = GetSimilarity().Tf(freq) * value_Renamed; // raw score
+ return raw * Similarity.DecodeNorm(norms[doc]); // normalize
+ }
public override Explanation Explain(int doc)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanTermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanTermQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanTermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanTermQuery.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 TermPositions = Lucene.Net.Index.TermPositions;
@@ -26,7 +27,7 @@
/// <summary>Matches spans containing a term. </summary>
[Serializable]
- public class SpanTermQuery:SpanQuery
+ public class SpanTermQuery : SpanQuery
{
private class AnonymousClassSpans : Spans
{
@@ -136,25 +137,23 @@
return term.Field();
}
- /// <summary>Returns a collection of all terms matched by this query.</summary>
- /// <deprecated> use extractTerms instead
- /// </deprecated>
- /// <seealso cref="#extractTerms(Set)">
- /// </seealso>
- public override System.Collections.ICollection GetTerms()
+ /// <summary>Returns a collection of all terms matched by this query.</summary>
+ /// <deprecated> use extractTerms instead
+ /// </deprecated>
+ /// <seealso cref="#ExtractTerms(Set)">
+ /// </seealso>
+ public override System.Collections.ICollection GetTerms()
{
System.Collections.ArrayList terms = new System.Collections.ArrayList();
terms.Add(term);
return terms;
}
- public override void ExtractTerms(System.Collections.Hashtable terms)
- {
- if (terms.Contains(term) == false)
- {
- terms.Add(term, term);
- }
- }
+ public override void ExtractTerms(System.Collections.Hashtable terms)
+ {
+ if (terms.Contains(term) == false)
+ terms.Add(term, term);
+ }
public override System.String ToString(System.String field)
{
@@ -181,7 +180,7 @@
/// <summary>Returns a hash code value for this object.</summary>
public override int GetHashCode()
{
- return GetBoost().ToString().GetHashCode() ^ term.GetHashCode() ^ unchecked((int) 0xD23FE494); // {{Aroush-1.9}} Is this OK?
+ return GetBoost().ToString().GetHashCode() ^ term.GetHashCode() ^ unchecked((int) 0xD23FE494); // {{Aroush-1.9}} Is this OK?
}
public override Spans GetSpans(IndexReader reader)
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanWeight.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanWeight.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanWeight.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanWeight.cs Tue May 1 11:45:26 2007
@@ -16,14 +16,16 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
-using Explanation = Lucene.Net.Search.Explanation;
using Query = Lucene.Net.Search.Query;
-using Scorer = Lucene.Net.Search.Scorer;
+using Weight = Lucene.Net.Search.Weight;
using Searcher = Lucene.Net.Search.Searcher;
+using Scorer = Lucene.Net.Search.Scorer;
+using Explanation = Lucene.Net.Search.Explanation;
+using ComplexExplanation = Lucene.Net.Search.ComplexExplanation;
using Similarity = Lucene.Net.Search.Similarity;
-using Weight = Lucene.Net.Search.Weight;
namespace Lucene.Net.Search.Spans
{
@@ -44,11 +46,11 @@
{
this.similarity = query.GetSimilarity(searcher);
this.query = query;
- terms = new System.Collections.Hashtable();
- query.ExtractTerms(terms);
+ terms = new System.Collections.Hashtable();
+ query.ExtractTerms(terms);
+
+ System.Collections.ArrayList tmp = new System.Collections.ArrayList(terms.Values);
- System.Collections.ArrayList tmp = new System.Collections.ArrayList(terms.Values);
-
idf = this.query.GetSimilarity(searcher).Idf(tmp, searcher);
}
@@ -82,7 +84,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:");
System.String field = ((SpanQuery) GetQuery()).GetField();
@@ -90,7 +92,7 @@
System.Collections.IEnumerator i = terms.GetEnumerator();
while (i.MoveNext())
{
- System.Collections.DictionaryEntry tmp = (System.Collections.DictionaryEntry) i.Current;
+ System.Collections.DictionaryEntry tmp = (System.Collections.DictionaryEntry) i.Current;
Term term = (Term) tmp.Key;
docFreqs.Append(term.Text());
docFreqs.Append("=");
@@ -121,7 +123,7 @@
result.AddDetail(queryExpl);
// explain field weight
- Explanation fieldExpl = new Explanation();
+ ComplexExplanation fieldExpl = new ComplexExplanation();
fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");
Explanation tfExpl = Scorer(reader).Explain(doc);
@@ -135,9 +137,12 @@
fieldNormExpl.SetDescription("fieldNorm(field=" + 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());
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TermQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.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 TermDocs = Lucene.Net.Index.TermDocs;
+using IndexReader = Lucene.Net.Index.IndexReader;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
namespace Lucene.Net.Search
@@ -101,7 +102,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(docFreq=" + reader.DocFreq(Enclosing_Instance.term) + ")");
@@ -124,7 +125,7 @@
// explain field weight
System.String field = Enclosing_Instance.term.Field();
- Explanation fieldExpl = new Explanation();
+ ComplexExplanation fieldExpl = new ComplexExplanation();
fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.term + " in " + doc + "), product of:");
Explanation tfExpl = Scorer(reader).Explain(doc);
@@ -138,9 +139,12 @@
fieldNormExpl.SetDescription("fieldNorm(field=" + 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());
@@ -171,12 +175,12 @@
public override void ExtractTerms(System.Collections.Hashtable terms)
{
- Term term = GetTerm();
- if (terms.Contains(term) == false)
- {
- terms.Add(term, term);
- }
- }
+ Term term = GetTerm();
+ if (terms.Contains(term) == false)
+ {
+ terms.Add(term, term);
+ }
+ }
/// <summary>Prints a user-readable version of this query. </summary>
public override System.String ToString(System.String field)
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TermScorer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using TermDocs = Lucene.Net.Index.TermDocs;
namespace Lucene.Net.Search
@@ -98,7 +99,7 @@
}
/// <summary>Returns the current document number matching the query.
- /// Initially invalid, until {@link #Next()} is called the first time.
+ /// Initially invalid, until {@link #next()} is called the first time.
/// </summary>
public override int Doc()
{
@@ -177,12 +178,11 @@
}
/// <summary>Returns an explanation of the score for a document.
- /// <br>When this method is used, the {@link #Next()} method
+ /// <br>When this method is used, the {@link #next()} method
/// and the {@link #Score(HitCollector)} method should not be used.
/// </summary>
/// <param name="doc">The document number for the explanation.
/// </param>
- /// <todo> Modify to make use of {@link TermDocs#SkipTo(int)}. </todo>
public override Explanation Explain(int doc)
{
TermQuery query = (TermQuery) weight.GetQuery();
@@ -196,7 +196,7 @@
}
if (tf == 0)
{
- while (termDocs.Next())
+ if (termDocs.SkipTo(doc))
{
if (termDocs.Doc() == doc)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocCollector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TopDocCollector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocCollector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocCollector.cs Tue May 1 11:45:26 2007
@@ -16,72 +16,73 @@
*/
using System;
+
using PriorityQueue = Lucene.Net.Util.PriorityQueue;
namespace Lucene.Net.Search
{
- /// <summary>A {@link HitCollector} implementation that collects the top-scoring
- /// documents, returning them as a {@link TopDocs}. This is used by {@link
- /// IndexSearcher} to implement {@link TopDocs}-based search.
- ///
- /// <p>This may be extended, overriding the collect method to, e.g.,
- /// conditionally invoke <code>super()</code> in order to filter which
- /// documents are collected.
- ///
- /// </summary>
- public class TopDocCollector : HitCollector
- {
- private int numHits;
- private float minScore = 0.0f;
-
- internal int totalHits;
- internal PriorityQueue hq;
-
- /// <summary>Construct to collect a given number of hits.</summary>
- /// <param name="numHits">the maximum number of hits to collect
- /// </param>
- public TopDocCollector(int numHits) : this(numHits, new HitQueue(numHits))
- {
- }
-
- internal TopDocCollector(int numHits, PriorityQueue hq)
- {
- this.numHits = numHits;
- this.hq = hq;
- }
-
- // javadoc inherited
- public override void Collect(int doc, float score)
- {
- if (score > 0.0f)
- {
- totalHits++;
- if (hq.Size() < numHits || score >= minScore)
- {
- hq.Insert(new ScoreDoc(doc, score));
- minScore = ((ScoreDoc) hq.Top()).score; // maintain minScore
- }
- }
- }
-
- /// <summary>The total number of documents that matched this query. </summary>
- public virtual int GetTotalHits()
- {
- return totalHits;
- }
-
- /// <summary>The top-scoring hits. </summary>
- public virtual TopDocs TopDocs()
- {
- ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
- for (int i = hq.Size() - 1; i >= 0; i--)
- // put docs in array
- scoreDocs[i] = (ScoreDoc) hq.Pop();
+ /// <summary>A {@link HitCollector} implementation that collects the top-scoring
+ /// documents, returning them as a {@link TopDocs}. This is used by {@link
+ /// IndexSearcher} to implement {@link TopDocs}-based search.
+ ///
+ /// <p>This may be extended, overriding the collect method to, e.g.,
+ /// conditionally invoke <code>super()</code> in order to filter which
+ /// documents are collected.
+ ///
+ /// </summary>
+ public class TopDocCollector : HitCollector
+ {
+ private int numHits;
+ private float minScore = 0.0f;
+
+ internal int totalHits;
+ internal PriorityQueue hq;
+
+ /// <summary>Construct to collect a given number of hits.</summary>
+ /// <param name="numHits">the maximum number of hits to collect
+ /// </param>
+ public TopDocCollector(int numHits) : this(numHits, new HitQueue(numHits))
+ {
+ }
+
+ internal TopDocCollector(int numHits, PriorityQueue hq)
+ {
+ this.numHits = numHits;
+ this.hq = hq;
+ }
+
+ // javadoc inherited
+ public override void Collect(int doc, float score)
+ {
+ if (score > 0.0f)
+ {
+ totalHits++;
+ if (hq.Size() < numHits || score >= minScore)
+ {
+ hq.Insert(new ScoreDoc(doc, score));
+ minScore = ((ScoreDoc) hq.Top()).score; // maintain minScore
+ }
+ }
+ }
+
+ /// <summary>The total number of documents that matched this query. </summary>
+ public virtual int GetTotalHits()
+ {
+ return totalHits;
+ }
+
+ /// <summary>The top-scoring hits. </summary>
+ public virtual TopDocs TopDocs()
+ {
+ ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
+ for (int i = hq.Size() - 1; i >= 0; i--)
+ // put docs in array
+ scoreDocs[i] = (ScoreDoc) hq.Pop();
- float maxScore = (totalHits == 0) ? System.Single.NegativeInfinity : scoreDocs[0].score;
+ float maxScore = (totalHits == 0) ? System.Single.NegativeInfinity : scoreDocs[0].score;
- return new TopDocs(totalHits, scoreDocs, maxScore);
- }
- }
+ return new TopDocs(totalHits, scoreDocs, maxScore);
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocCollector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TopFieldDocCollector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocCollector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocCollector.cs Tue May 1 11:45:26 2007
@@ -16,54 +16,55 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
namespace Lucene.Net.Search
{
- /// <summary>A {@link HitCollector} implementation that collects the top-sorting
- /// documents, returning them as a {@link TopFieldDocs}. This is used by {@link
- /// IndexSearcher} to implement {@link TopFieldDocs}-based search.
- ///
- /// <p>This may be extended, overriding the collect method to, e.g.,
- /// conditionally invoke <code>super()</code> in order to filter which
- /// documents are collected.
- ///
- /// </summary>
- public class TopFieldDocCollector : TopDocCollector
- {
+ /// <summary>A {@link HitCollector} implementation that collects the top-sorting
+ /// documents, returning them as a {@link TopFieldDocs}. This is used by {@link
+ /// IndexSearcher} to implement {@link TopFieldDocs}-based search.
+ ///
+ /// <p>This may be extended, overriding the collect method to, e.g.,
+ /// conditionally invoke <code>super()</code> in order to filter which
+ /// documents are collected.
+ ///
+ /// </summary>
+ public class TopFieldDocCollector : TopDocCollector
+ {
- /// <summary>Construct to collect a given number of hits.</summary>
- /// <param name="reader">the index to be searched
- /// </param>
- /// <param name="sort">the sort criteria
- /// </param>
- /// <param name="numHits">the maximum number of hits to collect
- /// </param>
- public TopFieldDocCollector(IndexReader reader, Sort sort, int numHits) : base(numHits, new FieldSortedHitQueue(reader, sort.fields, numHits))
- {
- }
+ /// <summary>Construct to collect a given number of hits.</summary>
+ /// <param name="reader">the index to be searched
+ /// </param>
+ /// <param name="sort">the sort criteria
+ /// </param>
+ /// <param name="numHits">the maximum number of hits to collect
+ /// </param>
+ public TopFieldDocCollector(IndexReader reader, Sort sort, int numHits) : base(numHits, new FieldSortedHitQueue(reader, sort.fields, numHits))
+ {
+ }
- // javadoc inherited
- public override void Collect(int doc, float score)
- {
- if (score > 0.0f)
- {
- totalHits++;
- hq.Insert(new FieldDoc(doc, score));
- }
- }
+ // javadoc inherited
+ public override void Collect(int doc, float score)
+ {
+ if (score > 0.0f)
+ {
+ totalHits++;
+ hq.Insert(new FieldDoc(doc, score));
+ }
+ }
- // javadoc inherited
- public override TopDocs TopDocs()
- {
- FieldSortedHitQueue fshq = (FieldSortedHitQueue) hq;
- ScoreDoc[] scoreDocs = new ScoreDoc[fshq.Size()];
- for (int i = fshq.Size() - 1; i >= 0; i--)
- // put docs in array
- scoreDocs[i] = fshq.FillFields((FieldDoc) fshq.Pop());
+ // javadoc inherited
+ public override TopDocs TopDocs()
+ {
+ FieldSortedHitQueue fshq = (FieldSortedHitQueue) hq;
+ ScoreDoc[] scoreDocs = new ScoreDoc[fshq.Size()];
+ for (int i = fshq.Size() - 1; i >= 0; i--)
+ // put docs in array
+ scoreDocs[i] = fshq.FillFields((FieldDoc) fshq.Pop());
- return new TopFieldDocs(totalHits, scoreDocs, fshq.GetFields(), fshq.GetMaxScore());
- }
- }
+ return new TopFieldDocs(totalHits, scoreDocs, fshq.GetFields(), fshq.GetMaxScore());
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TopFieldDocs.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocs.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocs.cs Tue May 1 11:45:26 2007
@@ -19,38 +19,40 @@
namespace Lucene.Net.Search
{
- /// <summary> Expert: Returned by low-level sorted search implementations.
- ///
- /// <p>Created: Feb 12, 2004 8:58:46 AM
- ///
- /// </summary>
- /// <author> Tim Jones (Nacimiento Software)
- /// </author>
- /// <since> lucene 1.4
- /// </since>
- /// <version> $Id: TopFieldDocs.java 354819 2005-12-07 17:48:37Z yonik $
- /// </version>
- /// <seealso cref="Searcher#search(Query,Filter,int,Sort)">
- /// </seealso>
- [Serializable]
- public class TopFieldDocs : TopDocs
- {
+
+
+ /// <summary> Expert: Returned by low-level sorted search implementations.
+ ///
+ /// <p>Created: Feb 12, 2004 8:58:46 AM
+ ///
+ /// </summary>
+ /// <author> Tim Jones (Nacimiento Software)
+ /// </author>
+ /// <since> lucene 1.4
+ /// </since>
+ /// <version> $Id: TopFieldDocs.java 472959 2006-11-09 16:21:50Z yonik $
+ /// </version>
+ /// <seealso cref="Searcher#Search(Query,Filter,int,Sort)">
+ /// </seealso>
+ [Serializable]
+ public class TopFieldDocs : TopDocs
+ {
- /// <summary>The fields which were used to sort results by. </summary>
- public SortField[] fields;
+ /// <summary>The fields which were used to sort results by. </summary>
+ public SortField[] fields;
- /// <summary>Creates one of these objects.</summary>
- /// <param name="totalHits"> Total number of hits for the query.
- /// </param>
- /// <param name="scoreDocs"> The top hits for the query.
- /// </param>
- /// <param name="fields"> The sort criteria used to find the top hits.
- /// </param>
- /// <param name="maxScore"> The maximum score encountered.
- /// </param>
- internal TopFieldDocs(int totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore) : base(totalHits, scoreDocs, maxScore)
- {
- this.fields = fields;
- }
- }
+ /// <summary>Creates one of these objects.</summary>
+ /// <param name="totalHits"> Total number of hits for the query.
+ /// </param>
+ /// <param name="scoreDocs"> The top hits for the query.
+ /// </param>
+ /// <param name="fields"> The sort criteria used to find the top hits.
+ /// </param>
+ /// <param name="maxScore"> The maximum score encountered.
+ /// </param>
+ internal TopFieldDocs(int totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore) : base(totalHits, scoreDocs, maxScore)
+ {
+ this.fields = fields;
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Weight.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Weight.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Weight.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Weight.cs Tue May 1 11:45:26 2007
@@ -16,6 +16,7 @@
*/
using System;
+
using IndexReader = Lucene.Net.Index.IndexReader;
namespace Lucene.Net.Search
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/WildcardQuery.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardQuery.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;
@@ -35,8 +36,11 @@
[Serializable]
public class WildcardQuery : MultiTermQuery
{
+ private bool termContainsWildcard;
+
public WildcardQuery(Term term) : base(term)
{
+ this.termContainsWildcard = (term.Text().IndexOf((System.Char) '*') != - 1) || (term.Text().IndexOf((System.Char) '?') != - 1);
}
protected internal override FilteredTermEnum GetEnum(IndexReader reader)
@@ -51,6 +55,17 @@
return false;
}
+
+ public override Query Rewrite(IndexReader reader)
+ {
+ if (this.termContainsWildcard)
+ {
+ return base.Rewrite(reader);
+ }
+
+ return new TermQuery(GetTerm());
+ }
+
public override int GetHashCode()
{
return base.GetHashCode();
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardTermEnum.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/WildcardTermEnum.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardTermEnum.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardTermEnum.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;
@@ -29,7 +30,7 @@
/// the enumeration is greater than all that precede it.
///
/// </summary>
- /// <version> $Id: WildcardTermEnum.java 329859 2005-10-31 17:05:36Z bmesser $
+ /// <version> $Id: WildcardTermEnum.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
public class WildcardTermEnum : FilteredTermEnum
{
@@ -41,7 +42,7 @@
internal bool endEnum = false;
/// <summary> Creates a new <code>WildcardTermEnum</code>. Passing in a
- /// {@link Lucene.Net.index.Term Term} that does not contain a
+ /// {@link Lucene.Net.Index.Term Term} that does not contain a
/// <code>WILDCARD_CHAR</code> will cause an exception to be thrown.
/// <p>
/// After calling the constructor the enumeration is already pointing to the first
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/BufferedIndexInput.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Store/BufferedIndexInput.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/BufferedIndexInput.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Store/BufferedIndexInput.cs Tue May 1 11:45:26 2007
@@ -40,22 +40,57 @@
public override void ReadBytes(byte[] b, int offset, int len)
{
- if (len < BUFFER_SIZE)
+ if (len <= (bufferLength - bufferPosition))
{
- for (int i = 0; i < len; i++)
- // read byte-by-byte
- b[i + offset] = (byte) ReadByte();
+ // the buffer contains enough data to satistfy this request
+ if (len > 0)
+ // to allow b to be null if len is 0...
+ Array.Copy(buffer, bufferPosition, b, offset, len);
+ bufferPosition += len;
}
else
{
- // read all-at-once
- long start = GetFilePointer();
- SeekInternal(start);
- ReadInternal(b, offset, len);
-
- bufferStart = start + len; // adjust stream variables
- bufferPosition = 0;
- bufferLength = 0; // trigger refill() on read
+ // the buffer does not have enough data. First serve all we've got.
+ int available = bufferLength - bufferPosition;
+ if (available > 0)
+ {
+ Array.Copy(buffer, bufferPosition, b, offset, available);
+ offset += available;
+ len -= available;
+ bufferPosition += available;
+ }
+ // and now, read the remaining 'len' bytes:
+ if (len < BUFFER_SIZE)
+ {
+ // If the amount left to read is small enough, do it in the usual
+ // buffered way: fill the buffer and copy from it:
+ Refill();
+ if (bufferLength < len)
+ {
+ // Throw an exception when refill() could not read len bytes:
+ Array.Copy(buffer, 0, b, offset, bufferLength);
+ throw new System.IO.IOException("read past EOF");
+ }
+ else
+ {
+ Array.Copy(buffer, 0, b, offset, len);
+ bufferPosition = len;
+ }
+ }
+ else
+ {
+ // The amount left to read is larger than the buffer - there's no
+ // performance reason not to read it all at once. Note that unlike
+ // the previous code of this function, there is no need to do a seek
+ // here, because there's no need to reread what we had in the buffer.
+ long after = bufferStart + bufferPosition + len;
+ if (after > Length())
+ throw new System.IO.IOException("read past EOF");
+ ReadInternal(b, offset, len);
+ bufferStart = after;
+ bufferPosition = 0;
+ bufferLength = 0; // trigger refill() on read
+ }
}
}
@@ -64,7 +99,7 @@
long start = bufferStart + bufferPosition;
long end = start + BUFFER_SIZE;
if (end > Length())
- // don't read past EOF
+ // don't read past EOF
end = Length();
bufferLength = (int) (end - start);
if (bufferLength <= 0)
@@ -98,7 +133,7 @@
{
if (pos >= bufferStart && pos < (bufferStart + bufferLength))
bufferPosition = (int) (pos - bufferStart);
- // seek within buffer
+ // seek within buffer
else
{
bufferStart = pos;
@@ -111,7 +146,7 @@
/// <summary>Expert: implements seek. Sets current position in this file, where the
/// next {@link #ReadInternal(byte[],int,int)} will occur.
/// </summary>
- /// <seealso cref="ReadInternal(byte[],int,int)">
+ /// <seealso cref="#ReadInternal(byte[],int,int)">
/// </seealso>
public abstract void SeekInternal(long pos);
@@ -128,7 +163,7 @@
return clone;
}
- static BufferedIndexInput()
+ static BufferedIndexInput()
{
BUFFER_SIZE = BufferedIndexOutput.BUFFER_SIZE;
}