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 2008/06/25 04:51:26 UTC
svn commit: r671402 [5/5] - in
/incubator/lucene.net/trunk/C#/src/Lucene.Net/Search: ./ Function/ Payload/
Spans/
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- 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 Jun 24 19:51:24 2008
@@ -19,7 +19,6 @@
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
-using TermPositions = Lucene.Net.Index.TermPositions;
using ToStringUtils = Lucene.Net.Util.ToStringUtils;
namespace Lucene.Net.Search.Spans
@@ -29,96 +28,7 @@
[Serializable]
public class SpanTermQuery : SpanQuery
{
- private class AnonymousClassSpans : Spans
- {
- public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader, SpanTermQuery enclosingInstance)
- {
- InitBlock(reader, enclosingInstance);
- }
- private void InitBlock(Lucene.Net.Index.IndexReader reader, SpanTermQuery enclosingInstance)
- {
- this.reader = reader;
- this.enclosingInstance = enclosingInstance;
- positions = reader.TermPositions(Enclosing_Instance.term);
- }
- private Lucene.Net.Index.IndexReader reader;
- private SpanTermQuery enclosingInstance;
- public SpanTermQuery Enclosing_Instance
- {
- get
- {
- return enclosingInstance;
- }
-
- }
- private TermPositions positions;
-
- private int doc = - 1;
- private int freq;
- private int count;
- private int position;
-
- public virtual bool Next()
- {
- if (count == freq)
- {
- if (!positions.Next())
- {
- doc = System.Int32.MaxValue;
- return false;
- }
- doc = positions.Doc();
- freq = positions.Freq();
- count = 0;
- }
- position = positions.NextPosition();
- count++;
- return true;
- }
-
- public virtual bool SkipTo(int target)
- {
- // are we already at the correct position?
- if (doc >= target)
- {
- return true;
- }
-
- if (!positions.SkipTo(target))
- {
- doc = System.Int32.MaxValue;
- return false;
- }
-
- doc = positions.Doc();
- freq = positions.Freq();
- count = 0;
-
- position = positions.NextPosition();
- count++;
-
- return true;
- }
-
- public virtual int Doc()
- {
- return doc;
- }
- public virtual int Start()
- {
- return position;
- }
- public virtual int End()
- {
- return position + 1;
- }
-
- public override System.String ToString()
- {
- return "spans(" + Enclosing_Instance.ToString() + ")@" + (doc == - 1 ? "START" : ((doc == System.Int32.MaxValue) ? "END" : doc + "-" + position));
- }
- }
- private Term term;
+ protected internal Term term;
/// <summary>Construct a SpanTermQuery matching the named term's spans. </summary>
public SpanTermQuery(Term term)
@@ -185,7 +95,7 @@
public override Spans GetSpans(IndexReader reader)
{
- return new AnonymousClassSpans(reader, this);
+ return new TermSpans(reader.TermPositions(term), term);
}
}
}
\ No newline at end of file
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- 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 Jun 24 19:51:24 2008
@@ -19,28 +19,24 @@
using IndexReader = Lucene.Net.Index.IndexReader;
using Term = Lucene.Net.Index.Term;
-using Query = Lucene.Net.Search.Query;
-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 Lucene.Net.Search;
+using Searchable = Lucene.Net.Search.Searchable;
namespace Lucene.Net.Search.Spans
{
+ /// <summary> Expert-only. Public for use by other weight implementations</summary>
[Serializable]
- class SpanWeight : Weight
+ public class SpanWeight : Weight
{
- private Similarity similarity;
- private float value_Renamed;
- private float idf;
- private float queryNorm;
- private float queryWeight;
+ protected internal Similarity similarity;
+ protected internal float value_Renamed;
+ protected internal float idf;
+ protected internal float queryNorm;
+ protected internal float queryWeight;
- private System.Collections.Hashtable terms;
- private SpanQuery query;
+ protected internal System.Collections.Hashtable terms;
+ protected internal SpanQuery query;
public SpanWeight(SpanQuery query, Searcher searcher)
{
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/TermSpans.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/TermSpans.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/TermSpans.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/TermSpans.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,115 @@
+/*
+ * 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 TermPositions = Lucene.Net.Index.TermPositions;
+
+namespace Lucene.Net.Search.Spans
+{
+
+ /// <summary> Expert:
+ /// Public for extension only
+ /// </summary>
+ public class TermSpans : Spans
+ {
+ protected internal TermPositions positions;
+ protected internal Term term;
+ protected internal int doc;
+ protected internal int freq;
+ protected internal int count;
+ protected internal int position;
+
+
+ public TermSpans(TermPositions positions, Term term)
+ {
+
+ this.positions = positions;
+ this.term = term;
+ doc = - 1;
+ }
+
+ public virtual bool Next()
+ {
+ if (count == freq)
+ {
+ if (!positions.Next())
+ {
+ doc = System.Int32.MaxValue;
+ return false;
+ }
+ doc = positions.Doc();
+ freq = positions.Freq();
+ count = 0;
+ }
+ position = positions.NextPosition();
+ count++;
+ return true;
+ }
+
+ public virtual bool SkipTo(int target)
+ {
+ // are we already at the correct position?
+ if (doc >= target)
+ {
+ return true;
+ }
+
+ if (!positions.SkipTo(target))
+ {
+ doc = System.Int32.MaxValue;
+ return false;
+ }
+
+ doc = positions.Doc();
+ freq = positions.Freq();
+ count = 0;
+
+ position = positions.NextPosition();
+ count++;
+
+ return true;
+ }
+
+ public virtual int Doc()
+ {
+ return doc;
+ }
+
+ public virtual int Start()
+ {
+ return position;
+ }
+
+ public virtual int End()
+ {
+ return position + 1;
+ }
+
+ public override System.String ToString()
+ {
+ return "spans(" + term.ToString() + ")@" + (doc == - 1 ? "START" : ((doc == System.Int32.MaxValue) ? "END" : doc + "-" + position));
+ }
+
+
+ public virtual TermPositions GetPositions()
+ {
+ return positions;
+ }
+ }
+}
\ No newline at end of file
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs Tue Jun 24 19:51:24 2008
@@ -17,9 +17,9 @@
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
@@ -105,7 +105,7 @@
ComplexExplanation result = new ComplexExplanation();
result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
- Explanation idfExpl = new Explanation(idf, "idf(docFreq=" + reader.DocFreq(Enclosing_Instance.term) + ")");
+ Explanation idfExpl = new Explanation(idf, "idf(docFreq=" + reader.DocFreq(Enclosing_Instance.term) + ", numDocs=" + reader.NumDocs() + ")");
// explain query weight
Explanation queryExpl = new Explanation();
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs Tue Jun 24 19:51:24 2008
@@ -73,7 +73,7 @@
{
// for docs in window
int f = freqs[pointer];
- float score = f < SCORE_CACHE_SIZE?scoreCache[f]:similarity.Tf(f) * weightValue; // cache miss
+ float score = f < SCORE_CACHE_SIZE ? scoreCache[f] : similarity.Tf(f) * weightValue; // cache miss
score *= normDecoder[norms[doc] & 0xFF]; // normalize for field
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocCollector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocCollector.cs Tue Jun 24 19:51:24 2008
@@ -33,8 +33,8 @@
/// </summary>
public class TopDocCollector : HitCollector
{
- private int numHits;
- private float minScore = 0.0f;
+
+ private ScoreDoc reusableSD;
internal int totalHits;
internal PriorityQueue hq;
@@ -48,7 +48,6 @@
internal TopDocCollector(int numHits, PriorityQueue hq)
{
- this.numHits = numHits;
this.hq = hq;
}
@@ -58,11 +57,23 @@
if (score > 0.0f)
{
totalHits++;
- if (hq.Size() < numHits || score >= minScore)
+ if (reusableSD == null)
+ {
+ reusableSD = new ScoreDoc(doc, score);
+ }
+ else if (score >= reusableSD.score)
+ {
+ // reusableSD holds the last "rejected" entry, so, if
+ // this new score is not better than that, there's no
+ // need to try inserting it
+ reusableSD.doc = doc;
+ reusableSD.score = score;
+ }
+ else
{
- hq.Insert(new ScoreDoc(doc, score));
- minScore = ((ScoreDoc) hq.Top()).score; // maintain minScore
+ return ;
}
+ reusableSD = (ScoreDoc) hq.InsertWithOverflow(reusableSD);
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TopDocs.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocs.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocs.cs Tue Jun 24 19:51:24 2008
@@ -48,7 +48,7 @@
}
/// <summary>Expert: Constructs a TopDocs.</summary>
- internal TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore)
+ public TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore)
{
this.totalHits = totalHits;
this.scoreDocs = scoreDocs;
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocCollector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocCollector.cs Tue Jun 24 19:51:24 2008
@@ -34,6 +34,8 @@
public class TopFieldDocCollector : TopDocCollector
{
+ private FieldDoc reusableFD;
+
/// <summary>Construct to collect a given number of hits.</summary>
/// <param name="reader">the index to be searched
/// </param>
@@ -51,7 +53,19 @@
if (score > 0.0f)
{
totalHits++;
- hq.Insert(new FieldDoc(doc, score));
+ if (reusableFD == null)
+ reusableFD = new FieldDoc(doc, score);
+ else
+ {
+ // Whereas TopDocCollector can skip this if the
+ // score is not competitive, we cannot because the
+ // comparators in the FieldSortedHitQueue.lessThan
+ // aren't in general congruent with "higher score
+ // wins"
+ reusableFD.score = score;
+ reusableFD.doc = doc;
+ }
+ reusableFD = (FieldDoc) hq.InsertWithOverflow(reusableFD);
}
}
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?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/WildcardQuery.cs Tue Jun 24 19:51:24 2008
@@ -40,7 +40,7 @@
public WildcardQuery(Term term) : base(term)
{
- this.termContainsWildcard = (term.Text().IndexOf((System.Char) '*') != - 1) || (term.Text().IndexOf((System.Char) '?') != - 1);
+ this.termContainsWildcard = (term.Text().IndexOf('*') != - 1) || (term.Text().IndexOf('?') != - 1);
}
protected internal override FilteredTermEnum GetEnum(IndexReader reader)