lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [4/6] lucenenet git commit: Restructure classes
Date Fri, 07 Nov 2014 05:39:15 GMT
Restructure classes


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/e27e761d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/e27e761d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/e27e761d

Branch: refs/heads/master
Commit: e27e761df0a9eb3d2d73a8a130d1032aab9edb2a
Parents: f6387ca
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Fri Nov 7 07:35:12 2014 +0200
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Fri Nov 7 07:35:12 2014 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Queries/CustomScoreQuery.cs | 244 ++++++++++++------------
 1 file changed, 123 insertions(+), 121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e27e761d/src/Lucene.Net.Queries/CustomScoreQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/CustomScoreQuery.cs b/src/Lucene.Net.Queries/CustomScoreQuery.cs
index 8ac3636..94e7895 100644
--- a/src/Lucene.Net.Queries/CustomScoreQuery.cs
+++ b/src/Lucene.Net.Queries/CustomScoreQuery.cs
@@ -9,22 +9,22 @@ using Lucene.Net.Util;
 namespace Lucene.Net.Queries
 {
 
-	/*
-	 * 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.
-	 */
+    /*
+     * 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.
+     */
 
     /// <summary>
     /// Query that sets document score as a programmatic function of several (sub) scores:
@@ -46,7 +46,8 @@ namespace Lucene.Net.Queries
         /// <summary>
         /// Create a CustomScoreQuery over input subQuery. </summary>
         /// <param name="subQuery"> the sub query whose scored is being customized.
Must not be null.  </param>
-        public CustomScoreQuery(Query subQuery) : this(subQuery, new FunctionQuery[0])
+        public CustomScoreQuery(Query subQuery)
+            : this(subQuery, new FunctionQuery[0])
         {
         }
 
@@ -56,8 +57,8 @@ namespace Lucene.Net.Queries
         /// <param name="scoringQuery"> a value source query whose scores are used
in the custom score
         /// computation.  This parameter is optional - it can be null. </param>
         public CustomScoreQuery(Query subQuery, FunctionQuery scoringQuery)
-            : this(subQuery, scoringQuery != null ? new FunctionQuery[] {scoringQuery} :
new FunctionQuery[0])
-            // don't want an array that contains a single null..
+            : this(subQuery, scoringQuery != null ? new FunctionQuery[] { scoringQuery }
: new FunctionQuery[0])
+        // don't want an array that contains a single null..
         {
         }
 
@@ -116,7 +117,7 @@ namespace Lucene.Net.Queries
 
         public override object Clone()
         {
-            var clone = (CustomScoreQuery) base.Clone();
+            var clone = (CustomScoreQuery)base.Clone();
             clone.subQuery = (Query)subQuery.Clone();
             clone.scoringQueries = new Query[scoringQueries.Length];
             for (int i = 0; i < scoringQueries.Length; i++)
@@ -157,7 +158,7 @@ namespace Lucene.Net.Queries
             {
                 return false;
             }
-            var other = (CustomScoreQuery) o;
+            var other = (CustomScoreQuery)o;
             if (this.Boost != other.Boost || !this.subQuery.Equals(other.subQuery) || this.strict
!= other.strict ||
                 this.scoringQueries.Length != other.scoringQueries.Length)
             {
@@ -225,7 +226,7 @@ namespace Lucene.Net.Queries
                         if (qStrict)
                         {
                             var _ = valSrcWeight.ValueForNormalization;
-                                // do not include ValueSource part in the query normalization
+                            // do not include ValueSource part in the query normalization
                         }
                         else
                         {
@@ -301,7 +302,7 @@ namespace Lucene.Net.Queries
                 Explanation res = new ComplexExplanation(true, sc, outerInstance.ToString()
+ ", product of:");
                 res.AddDetail(customExp);
                 res.AddDetail(new Explanation(outerInstance.Boost, "queryBoost"));
-                    // actually using the q boost as q weight (== weight value)
+                // actually using the q boost as q weight (== weight value)
                 return res;
             }
 
@@ -310,131 +311,132 @@ namespace Lucene.Net.Queries
                 return false;
             }
 
+        }
 
+        //=========================== S C O R E R ============================
 
-            //=========================== S C O R E R ============================
-
-            /// <summary>
-            /// A scorer that applies a (callback) function on scores of the subQuery.
-            /// </summary>
-            private class CustomScorer : Scorer
-            {
-                private readonly CustomScoreQuery outerInstance;
+        /// <summary>
+        /// A scorer that applies a (callback) function on scores of the subQuery.
+        /// </summary>
+        private class CustomScorer : Scorer
+        {
+            private readonly CustomScoreQuery outerInstance;
 
-                private readonly float qWeight;
-                private readonly Scorer subQueryScorer;
-                private readonly Scorer[] valSrcScorers;
-                private readonly CustomScoreProvider provider;
-                private readonly float[] vScores; // reused in score() to avoid allocating
this array for each doc
+            private readonly float qWeight;
+            private readonly Scorer subQueryScorer;
+            private readonly Scorer[] valSrcScorers;
+            private readonly CustomScoreProvider provider;
+            private readonly float[] vScores; // reused in score() to avoid allocating this
array for each doc
 
-                // constructor
-                internal CustomScorer(CustomScoreQuery outerInstance, CustomScoreProvider
provider, CustomWeight w,
-                    float qWeight, Scorer subQueryScorer, Scorer[] valSrcScorers) : base(w)
-                {
-                    this.outerInstance = outerInstance;
-                    this.qWeight = qWeight;
-                    this.subQueryScorer = subQueryScorer;
-                    this.valSrcScorers = valSrcScorers;
-                    this.vScores = new float[valSrcScorers.Length];
-                    this.provider = provider;
-                }
+            // constructor
+            internal CustomScorer(CustomScoreQuery outerInstance, CustomScoreProvider provider,
CustomWeight w,
+                float qWeight, Scorer subQueryScorer, Scorer[] valSrcScorers)
+                : base(w)
+            {
+                this.outerInstance = outerInstance;
+                this.qWeight = qWeight;
+                this.subQueryScorer = subQueryScorer;
+                this.valSrcScorers = valSrcScorers;
+                this.vScores = new float[valSrcScorers.Length];
+                this.provider = provider;
+            }
 
-                public override int NextDoc()
+            public override int NextDoc()
+            {
+                int doc = subQueryScorer.NextDoc();
+                if (doc != NO_MORE_DOCS)
                 {
-                    int doc = subQueryScorer.NextDoc();
-                    if (doc != NO_MORE_DOCS)
+                    foreach (Scorer valSrcScorer in valSrcScorers)
                     {
-                        foreach (Scorer valSrcScorer in valSrcScorers)
-                        {
-                            valSrcScorer.Advance(doc);
-                        }
+                        valSrcScorer.Advance(doc);
                     }
-                    return doc;
                 }
+                return doc;
+            }
 
-                public override int DocID()
-                {
-                    return subQueryScorer.DocID();
-                }
+            public override int DocID()
+            {
+                return subQueryScorer.DocID();
+            }
 
-                /*(non-Javadoc) @see org.apache.lucene.search.Scorer#score() */
+            /*(non-Javadoc) @see org.apache.lucene.search.Scorer#score() */
 
-                public override float Score()
+            public override float Score()
+            {
+                for (int i = 0; i < valSrcScorers.Length; i++)
                 {
-                    for (int i = 0; i < valSrcScorers.Length; i++)
-                    {
-                        vScores[i] = valSrcScorers[i].Score();
-                    }
-                    return qWeight*provider.CustomScore(subQueryScorer.DocID(), subQueryScorer.Score(),
vScores);
+                    vScores[i] = valSrcScorers[i].Score();
                 }
+                return qWeight * provider.CustomScore(subQueryScorer.DocID(), subQueryScorer.Score(),
vScores);
+            }
 
-                public override int Freq()
-                {
-                    return subQueryScorer.Freq();
-                }
+            public override int Freq()
+            {
+                return subQueryScorer.Freq();
+            }
 
-                public override ICollection<ChildScorer> Children
-                {
-                    get { return Collections.Singleton(new ChildScorer(subQueryScorer, "CUSTOM"));
}
-                }
+            public override ICollection<ChildScorer> Children
+            {
+                get { return Collections.Singleton(new ChildScorer(subQueryScorer, "CUSTOM"));
}
+            }
 
-                public override int Advance(int target)
+            public override int Advance(int target)
+            {
+                int doc = subQueryScorer.Advance(target);
+                if (doc != NO_MORE_DOCS)
                 {
-                    int doc = subQueryScorer.Advance(target);
-                    if (doc != NO_MORE_DOCS)
+                    foreach (Scorer valSrcScorer in valSrcScorers)
                     {
-                        foreach (Scorer valSrcScorer in valSrcScorers)
-                        {
-                            valSrcScorer.Advance(doc);
-                        }
+                        valSrcScorer.Advance(doc);
                     }
-                    return doc;
-                }
-
-                public override long Cost()
-                {
-                    return subQueryScorer.Cost();
                 }
+                return doc;
             }
 
-//            public override Weight CreateWeight(IndexSearcher searcher)
-//            {                
-//                return new CustomWeight(this, searcher);
-//            }
-
-            /// <summary>
-            /// Checks if this is strict custom scoring.
-            /// In strict custom scoring, the <seealso cref="ValueSource"/> part does
not participate in weight normalization.
-            /// This may be useful when one wants full control over how scores are modified,
and does 
-            /// not care about normalizing by the <seealso cref="ValueSource"/> part.
-            /// One particular case where this is useful if for testing this query.   
-            /// <P>
-            /// Note: only has effect when the <seealso cref="ValueSource"/> part is
not null.
-            /// </summary>
-            public virtual bool Strict { get; set; }
-
-
-            /// <summary>
-            /// The sub-query that CustomScoreQuery wraps, affecting both the score and which
documents match. </summary>
-            public virtual Query SubQuery
+            public override long Cost()
             {
-                get { return outerInstance.subQuery; }
+                return subQueryScorer.Cost();
             }
+        }
 
-            /// <summary>
-            /// The scoring queries that only affect the score of CustomScoreQuery. </summary>
-            public virtual Query[] ScoringQueries
-            {
-                get { return outerInstance.scoringQueries; }
-            }
+        //            public override Weight CreateWeight(IndexSearcher searcher)
+        //            {                
+        //                return new CustomWeight(this, searcher);
+        //            }
 
-            /// <summary>
-            /// A short name of this query, used in <seealso cref="#toString(String)"/>.
-            /// </summary>
-            public virtual string Name
-            {
-                get { return "custom"; }
-            }
+        /// <summary>
+        /// Checks if this is strict custom scoring.
+        /// In strict custom scoring, the <seealso cref="ValueSource"/> part does not
participate in weight normalization.
+        /// This may be useful when one wants full control over how scores are modified,
and does 
+        /// not care about normalizing by the <seealso cref="ValueSource"/> part.
+        /// One particular case where this is useful if for testing this query.   
+        /// <P>
+        /// Note: only has effect when the <seealso cref="ValueSource"/> part is not
null.
+        /// </summary>
+        public virtual bool Strict { get; set; }
+
+
+        /// <summary>
+        /// The sub-query that CustomScoreQuery wraps, affecting both the score and which
documents match. </summary>
+        public virtual Query SubQuery
+        {
+            get { return subQuery; }
         }
+
+        /// <summary>
+        /// The scoring queries that only affect the score of CustomScoreQuery. </summary>
+        public virtual Query[] ScoringQueries
+        {
+            get { return scoringQueries; }
+        }
+
+        /// <summary>
+        /// A short name of this query, used in <seealso cref="#toString(String)"/>.
+        /// </summary>
+        public virtual string Name
+        {
+            get { return "custom"; }
+        }
+
     }
 }
\ No newline at end of file


Mime
View raw message