You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/09/19 16:19:53 UTC
[20/21] git commit: More work on Lucene.Net.Queries
More work on Lucene.Net.Queries
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ba0f3c7d
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ba0f3c7d
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ba0f3c7d
Branch: refs/heads/master
Commit: ba0f3c7d439cf400c7329022bf29df99c64e4610
Parents: 2b55e53
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Fri Sep 19 17:18:15 2014 +0300
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Fri Sep 19 17:18:15 2014 +0300
----------------------------------------------------------------------
src/Lucene.Net.Queries/BooleanFilter.cs | 384 ++--
src/Lucene.Net.Queries/BoostingQuery.cs | 8 +-
src/Lucene.Net.Queries/ChainedFilter.cs | 507 +++--
src/Lucene.Net.Queries/CommonTermsQuery.cs | 944 +++++-----
src/Lucene.Net.Queries/CustomScoreProvider.cs | 349 ++--
src/Lucene.Net.Queries/CustomScoreQuery.cs | 197 +-
src/Lucene.Net.Queries/FilterClause.cs | 166 +-
src/Lucene.Net.Queries/Function/BoostedQuery.cs | 545 +++---
.../Function/DocValues/BoolDocValues.cs | 230 ++-
.../DocValues/DocTermsIndexDocValues.cs | 413 ++--
.../Function/DocValues/DoubleDocValues.cs | 497 +++--
.../Function/DocValues/FloatDocValues.cs | 220 ++-
.../Function/DocValues/IntDocValues.cs | 348 ++--
.../Function/DocValues/LongDocValues.cs | 368 ++--
.../Function/DocValues/StrDocValues.cs | 146 +-
.../Function/FunctionQuery.cs | 511 +++--
.../Function/FunctionValues.cs | 717 +++----
src/Lucene.Net.Queries/Function/ValueSource.cs | 415 ++---
.../Function/ValueSourceScorer.cs | 214 +--
.../Function/ValueSources/BoolFunction.cs | 18 +-
.../Function/ValueSources/ByteFieldSource.cs | 258 ++-
.../ValueSources/BytesRefFieldSource.cs | 238 ++-
.../Function/ValueSources/ConstNumberSource.cs | 26 +-
.../Function/ValueSources/ConstValueSource.cs | 14 +-
.../Function/ValueSources/DefFunction.cs | 67 +-
.../Function/ValueSources/DivFloatFunction.cs | 42 +-
.../Function/ValueSources/DocFreqValueSource.cs | 306 ++-
.../ValueSources/DoubleConstValueSource.cs | 39 +-
.../Function/ValueSources/DoubleFieldSource.cs | 33 +-
.../Function/ValueSources/DualFloatFunction.cs | 157 +-
.../Function/ValueSources/EnumFieldSource.cs | 48 +-
.../Function/ValueSources/FieldCacheSource.cs | 94 +-
.../Function/ValueSources/FloatFieldSource.cs | 8 +-
.../Function/ValueSources/IDFValueSource.cs | 7 +-
.../Function/ValueSources/IfFunction.cs | 50 +-
.../Function/ValueSources/IntFieldSource.cs | 14 +-
.../ValueSources/JoinDocFreqValueSource.cs | 6 +-
.../ValueSources/LinearFloatFunction.cs | 24 +-
.../Function/ValueSources/LiteralValueSource.cs | 8 +-
.../Function/ValueSources/LongFieldSource.cs | 10 +-
.../Function/ValueSources/MaxDocValueSource.cs | 8 +-
.../Function/ValueSources/MaxFloatFunction.cs | 2 +-
.../Function/ValueSources/MinFloatFunction.cs | 2 +-
.../Function/ValueSources/MultiBoolFunction.cs | 14 +-
.../Function/ValueSources/MultiFloatFunction.cs | 17 +-
.../Function/ValueSources/MultiFunction.cs | 280 ++-
.../Function/ValueSources/NormValueSource.cs | 12 +-
.../Function/ValueSources/NumDocsValueSource.cs | 4 +-
.../Function/ValueSources/OrdFieldSource.cs | 6 +-
.../Function/ValueSources/PowFloatFunction.cs | 2 +-
.../ValueSources/ProductFloatFunction.cs | 2 +-
.../Function/ValueSources/QueryValueSource.cs | 16 +-
.../ValueSources/RangeMapFloatFunction.cs | 34 +-
.../ValueSources/ReciprocalFloatFunction.cs | 24 +-
.../ValueSources/ReverseOrdFieldSource.cs | 6 +-
.../Function/ValueSources/ScaleFloatFunction.cs | 40 +-
.../Function/ValueSources/ShortFieldSource.cs | 18 +-
.../Function/ValueSources/SimpleBoolFunction.cs | 16 +-
.../ValueSources/SimpleFloatFunction.cs | 8 +-
.../Function/ValueSources/SingleFunction.cs | 6 +-
.../Function/ValueSources/SumFloatFunction.cs | 2 +-
.../ValueSources/SumTotalTermFreqValueSource.cs | 12 +-
.../Function/ValueSources/TFValueSource.cs | 51 +-
.../ValueSources/TermFreqValueSource.cs | 6 +-
.../ValueSources/TotalTermFreqValueSource.cs | 12 +-
.../Function/ValueSources/VectorValueSource.cs | 106 +-
src/Lucene.Net.Queries/Mlt/MoreLikeThis.cs | 1758 ++++++++----------
src/Lucene.Net.Queries/Mlt/MoreLikeThisQuery.cs | 7 +-
src/Lucene.Net.Queries/TermFilter.cs | 255 ++-
src/Lucene.Net.Queries/TermsFilter.cs | 97 +-
70 files changed, 5471 insertions(+), 5998 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/BooleanFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/BooleanFilter.cs b/src/Lucene.Net.Queries/BooleanFilter.cs
index bcbc6fb..65b6d4e 100644
--- a/src/Lucene.Net.Queries/BooleanFilter.cs
+++ b/src/Lucene.Net.Queries/BooleanFilter.cs
@@ -1,204 +1,202 @@
-using System.Collections.Generic;
+using System.Collections;
+using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Util;
-using org.apache.lucene.queries;
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>
- /// A container Filter that allows Boolean composition of Filters.
- /// Filters are allocated into one of three logical constructs;
- /// SHOULD, MUST NOT, MUST
- /// The results Filter BitSet is constructed as follows:
- /// SHOULD Filters are OR'd together
- /// The resulting Filter is NOT'd with the NOT Filters
- /// The resulting Filter is AND'd with the MUST Filters
- /// </summary>
- public class BooleanFilter : Filter, IEnumerable<FilterClause>
- {
-
- private readonly IList<FilterClause> clauses_Renamed = new List<FilterClause>();
-
- /// <summary>
- /// Returns the a DocIdSetIterator representing the Boolean composition
- /// of the filters that have been added.
- /// </summary>
- public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
- {
- FixedBitSet res = null;
- AtomicReader reader = context.reader();
-
- bool hasShouldClauses = false;
- foreach (FilterClause fc in clauses_Renamed)
- {
- if (fc.Occur == BooleanClause.Occur.SHOULD)
- {
- hasShouldClauses = true;
- DocIdSetIterator disi = getDISI(fc.Filter, context);
- if (disi == null)
- {
- continue;
- }
- if (res == null)
- {
- res = new FixedBitSet(reader.MaxDoc());
- }
- res.or(disi);
- }
- }
- if (hasShouldClauses && res == null)
- {
- return null;
- }
-
- foreach (FilterClause fc in clauses_Renamed)
- {
- if (fc.Occur == BooleanClause.Occur.MUST_NOT)
- {
- if (res == null)
- {
- Debug.Assert(!hasShouldClauses);
- res = new FixedBitSet(reader.MaxDoc());
- res.Set(0, reader.MaxDoc()); // NOTE: may set bits on deleted docs
- }
-
- DocIdSetIterator disi = GetDISI(fc.Filter, context);
- if (disi != null)
- {
- res.AndNot(disi);
- }
- }
- }
-
- foreach (FilterClause fc in clauses_Renamed)
- {
- if (fc.Occur == BooleanClause.Occur.MUST)
- {
- DocIdSetIterator disi = GetDISI(fc.Filter, context);
- if (disi == null)
- {
- return null; // no documents can match
- }
- if (res == null)
- {
- res = new FixedBitSet(reader.maxDoc());
- res.or(disi);
- }
- else
- {
- res.and(disi);
- }
- }
- }
-
- return BitsFilteredDocIdSet.wrap(res, acceptDocs);
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private static org.apache.lucene.search.DocIdSetIterator getDISI(org.apache.lucene.search.Filter filter, org.apache.lucene.index.AtomicReaderContext context) throws java.io.IOException
- private static DocIdSetIterator GetDISI(Filter filter, AtomicReaderContext context)
- {
- // we dont pass acceptDocs, we will filter at the end using an additional filter
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.DocIdSet set = filter.getDocIdSet(context, null);
- DocIdSet set = filter.GetDocIdSet(context, null);
- return set == null ? null : set.GetEnumerator();
- }
-
- /// <summary>
- /// Adds a new FilterClause to the Boolean Filter container </summary>
- /// <param name="filterClause"> A FilterClause object containing a Filter and an Occur parameter </param>
- public virtual void Add(FilterClause filterClause)
- {
- clauses_Renamed.Add(filterClause);
- }
-
- public void Add(Filter filter, BooleanClause.Occur occur)
- {
- Add(new FilterClause(filter, occur));
- }
-
- /// <summary>
- /// Returns the list of clauses
- /// </summary>
- public virtual IList<FilterClause> clauses()
- {
- return clauses_Renamed;
- }
-
- /// <summary>
- /// Returns an iterator on the clauses in this query. It implements the <seealso cref="Iterable"/> interface to
- /// make it possible to do:
- /// <pre class="prettyprint">for (FilterClause clause : booleanFilter) {}</pre>
- /// </summary>
- public IEnumerator<FilterClause> GetEnumerator()
- {
- return clauses().GetEnumerator();
- }
-
- public override bool Equals(object obj)
- {
- if (this == obj)
- {
- return true;
- }
-
- if ((obj == null) || (obj.GetType() != this.GetType()))
- {
- return false;
- }
-
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final BooleanFilter other = (BooleanFilter)obj;
- BooleanFilter other = (BooleanFilter)obj;
- return clauses_Renamed.Equals(other.clauses_Renamed);
- }
-
- public override int GetHashCode()
- {
- return 657153718 ^ clauses_Renamed.GetHashCode();
- }
-
- /// <summary>
- /// Prints a user-readable version of this Filter. </summary>
- public override string ToString()
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final StringBuilder buffer = new StringBuilder("BooleanFilter(");
- StringBuilder buffer = new StringBuilder("BooleanFilter(");
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int minLen = buffer.length();
- int minLen = buffer.Length;
- foreach (FilterClause c in clauses_Renamed)
- {
- if (buffer.Length > minLen)
- {
- buffer.Append(' ');
- }
- buffer.Append(c);
- }
- return buffer.Append(')').ToString();
- }
- }
-
+ /// A container Filter that allows Boolean composition of Filters.
+ /// Filters are allocated into one of three logical constructs;
+ /// SHOULD, MUST NOT, MUST
+ /// The results Filter BitSet is constructed as follows:
+ /// SHOULD Filters are OR'd together
+ /// The resulting Filter is NOT'd with the NOT Filters
+ /// The resulting Filter is AND'd with the MUST Filters
+ /// </summary>
+ public class BooleanFilter : Filter, IEnumerable<FilterClause>
+ {
+
+ private readonly IList<FilterClause> clauses = new List<FilterClause>();
+
+ /// <summary>
+ /// Returns the a DocIdSetIterator representing the Boolean composition
+ /// of the filters that have been added.
+ /// </summary>
+ public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
+ {
+ FixedBitSet res = null;
+ AtomicReader reader = context.AtomicReader;
+
+ bool hasShouldClauses = false;
+ foreach (FilterClause fc in clauses)
+ {
+ if (fc.Occur == BooleanClause.Occur.SHOULD)
+ {
+ hasShouldClauses = true;
+ DocIdSetIterator disi = GetDISI(fc.Filter, context);
+ if (disi == null)
+ {
+ continue;
+ }
+ if (res == null)
+ {
+ res = new FixedBitSet(reader.MaxDoc);
+ }
+ res.Or(disi);
+ }
+ }
+ if (hasShouldClauses && res == null)
+ {
+ return null;
+ }
+
+ foreach (FilterClause fc in clauses)
+ {
+ if (fc.Occur == BooleanClause.Occur.MUST_NOT)
+ {
+ if (res == null)
+ {
+ Debug.Assert(!hasShouldClauses);
+ res = new FixedBitSet(reader.MaxDoc);
+ res.Set(0, reader.MaxDoc); // NOTE: may set bits on deleted docs
+ }
+
+ DocIdSetIterator disi = GetDISI(fc.Filter, context);
+ if (disi != null)
+ {
+ res.AndNot(disi);
+ }
+ }
+ }
+
+ foreach (FilterClause fc in clauses)
+ {
+ if (fc.Occur == BooleanClause.Occur.MUST)
+ {
+ DocIdSetIterator disi = GetDISI(fc.Filter, context);
+ if (disi == null)
+ {
+ return null; // no documents can match
+ }
+ if (res == null)
+ {
+ res = new FixedBitSet(reader.MaxDoc);
+ res.Or(disi);
+ }
+ else
+ {
+ res.And(disi);
+ }
+ }
+ }
+
+ return BitsFilteredDocIdSet.Wrap(res, acceptDocs);
+ }
+
+ private static DocIdSetIterator GetDISI(Filter filter, AtomicReaderContext context)
+ {
+ // we dont pass acceptDocs, we will filter at the end using an additional filter
+ DocIdSet set = filter.GetDocIdSet(context, null);
+ return set == null ? null : set.GetEnumerator();
+ }
+
+ /// <summary>
+ /// Adds a new FilterClause to the Boolean Filter container </summary>
+ /// <param name="filterClause"> A FilterClause object containing a Filter and an Occur parameter </param>
+ public virtual void Add(FilterClause filterClause)
+ {
+ clauses.Add(filterClause);
+ }
+
+ public void Add(Filter filter, BooleanClause.Occur occur)
+ {
+ Add(new FilterClause(filter, occur));
+ }
+
+ /// <summary>
+ /// Returns the list of clauses
+ /// </summary>
+ public virtual IList<FilterClause> Clauses
+ {
+ get { return clauses; }
+ }
+
+ /// <summary>
+ /// Returns an iterator on the clauses in this query. It implements the <seealso cref="Iterable"/> interface to
+ /// make it possible to do:
+ /// <pre class="prettyprint">for (FilterClause clause : booleanFilter) {}</pre>
+ /// </summary>
+ public IEnumerator<FilterClause> GetEnumerator()
+ {
+ return Clauses.GetEnumerator();
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+
+ if ((obj == null) || (obj.GetType() != this.GetType()))
+ {
+ return false;
+ }
+
+ BooleanFilter other = (BooleanFilter)obj;
+ return clauses.Equals(other.clauses);
+ }
+
+ public override int GetHashCode()
+ {
+ return 657153718 ^ clauses.GetHashCode();
+ }
+
+ /// <summary>
+ /// Prints a user-readable version of this Filter. </summary>
+ public override string ToString()
+ {
+ //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+ //ORIGINAL LINE: final StringBuilder buffer = new StringBuilder("BooleanFilter(");
+ StringBuilder buffer = new StringBuilder("BooleanFilter(");
+ //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+ //ORIGINAL LINE: final int minLen = buffer.length();
+ int minLen = buffer.Length;
+ foreach (FilterClause c in clauses)
+ {
+ if (buffer.Length > minLen)
+ {
+ buffer.Append(' ');
+ }
+ buffer.Append(c);
+ }
+ return buffer.Append(')').ToString();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/BoostingQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/BoostingQuery.cs b/src/Lucene.Net.Queries/BoostingQuery.cs
index 203a2ae..8212f98 100644
--- a/src/Lucene.Net.Queries/BoostingQuery.cs
+++ b/src/Lucene.Net.Queries/BoostingQuery.cs
@@ -72,8 +72,8 @@
}
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public Weight createWeight(IndexSearcher searcher) throws java.io.IOException
- public override Weight createWeight(IndexSearcher searcher)
+//ORIGINAL LINE: @Override public Weight CreateWeight(IndexSearcher searcher) throws java.io.IOException
+ public override Weight CreateWeight(IndexSearcher searcher)
{
return new BooleanWeightAnonymousInnerClassHelper(this, searcher);
}
@@ -111,7 +111,7 @@
{
const int prime = 31;
int result = base.GetHashCode();
- result = prime * result + float.floatToIntBits(boost);
+ result = prime * result + Number.FloatToIntBits(boost);
result = prime * result + ((context == null) ? 0 : context.GetHashCode());
result = prime * result + ((match == null) ? 0 : match.GetHashCode());
return result;
@@ -138,7 +138,7 @@
}
BoostingQuery other = (BoostingQuery) obj;
- if (float.floatToIntBits(boost) != float.floatToIntBits(other.boost))
+ if (Number.FloatToIntBits(boost) != Number.FloatToIntBits(other.boost))
{
return false;
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/ChainedFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/ChainedFilter.cs b/src/Lucene.Net.Queries/ChainedFilter.cs
index c6aec63..e0c1112 100644
--- a/src/Lucene.Net.Queries/ChainedFilter.cs
+++ b/src/Lucene.Net.Queries/ChainedFilter.cs
@@ -1,285 +1,266 @@
using System.Text;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Util;
-namespace org.apache.lucene.queries
+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>
+ /// <para>
+ /// Allows multiple <seealso cref="Filter"/>s to be chained.
+ /// Logical operations such as <b>NOT</b> and <b>XOR</b>
+ /// are applied between filters. One operation can be used
+ /// for all filters, or a specific operation can be declared
+ /// for each filter.
+ /// </para>
+ /// <para>
+ /// Order in which filters are called depends on
+ /// the position of the filter in the chain. It's probably
+ /// more efficient to place the most restrictive filters
+ /// /least computationally-intensive filters first.
+ /// </para>
+ /// </summary>
+ public class ChainedFilter : Filter
+ {
- using AtomicReader = org.apache.lucene.index.AtomicReader;
- using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
- using BitsFilteredDocIdSet = org.apache.lucene.search.BitsFilteredDocIdSet;
- using DocIdSet = org.apache.lucene.search.DocIdSet;
- using DocIdSetIterator = org.apache.lucene.search.DocIdSetIterator;
- using Filter = org.apache.lucene.search.Filter;
- using Bits = org.apache.lucene.util.Bits;
- using FixedBitSet = org.apache.lucene.util.FixedBitSet;
+ public const int OR = 0;
+ public const int AND = 1;
+ public const int ANDNOT = 2;
+ public const int XOR = 3;
+ /// <summary>
+ /// Logical operation when none is declared. Defaults to OR.
+ /// </summary>
+ public const int DEFAULT = OR;
- /// <summary>
- /// <para>
- /// Allows multiple <seealso cref="Filter"/>s to be chained.
- /// Logical operations such as <b>NOT</b> and <b>XOR</b>
- /// are applied between filters. One operation can be used
- /// for all filters, or a specific operation can be declared
- /// for each filter.
- /// </para>
- /// <para>
- /// Order in which filters are called depends on
- /// the position of the filter in the chain. It's probably
- /// more efficient to place the most restrictive filters
- /// /least computationally-intensive filters first.
- /// </para>
- /// </summary>
- public class ChainedFilter : Filter
- {
+ /// <summary>
+ /// The filter chain
+ /// </summary>
+ private Filter[] chain = null;
- public const int OR = 0;
- public const int AND = 1;
- public const int ANDNOT = 2;
- public const int XOR = 3;
- /// <summary>
- /// Logical operation when none is declared. Defaults to OR.
- /// </summary>
- public const int DEFAULT = OR;
+ private int[] logicArray;
- /// <summary>
- /// The filter chain
- /// </summary>
- private Filter[] chain = null;
+ private int logic = -1;
- private int[] logicArray;
+ /// <summary>
+ /// Ctor.
+ /// </summary>
+ /// <param name="chain"> The chain of filters </param>
+ public ChainedFilter(Filter[] chain)
+ {
+ this.chain = chain;
+ }
- private int logic = -1;
+ /// <summary>
+ /// Ctor.
+ /// </summary>
+ /// <param name="chain"> The chain of filters </param>
+ /// <param name="logicArray"> Logical operations to apply between filters </param>
+ public ChainedFilter(Filter[] chain, int[] logicArray)
+ {
+ this.chain = chain;
+ this.logicArray = logicArray;
+ }
- /// <summary>
- /// Ctor.
- /// </summary>
- /// <param name="chain"> The chain of filters </param>
- public ChainedFilter(Filter[] chain)
- {
- this.chain = chain;
- }
+ /// <summary>
+ /// Ctor.
+ /// </summary>
+ /// <param name="chain"> The chain of filters </param>
+ /// <param name="logic"> Logical operation to apply to ALL filters </param>
+ public ChainedFilter(Filter[] chain, int logic)
+ {
+ this.chain = chain;
+ this.logic = logic;
+ }
- /// <summary>
- /// Ctor.
- /// </summary>
- /// <param name="chain"> The chain of filters </param>
- /// <param name="logicArray"> Logical operations to apply between filters </param>
- public ChainedFilter(Filter[] chain, int[] logicArray)
- {
- this.chain = chain;
- this.logicArray = logicArray;
- }
+ /// <summary>
+ /// <seealso cref="Filter#GetDocIdSet"/>.
+ /// </summary>
+ public override DocIdSet GetDocIdSet(AtomicReaderContext context, Bits acceptDocs)
+ {
+ int[] index = new int[1]; // use array as reference to modifiable int;
+ index[0] = 0; // an object attribute would not be thread safe.
+ if (logic != -1)
+ {
+ return BitsFilteredDocIdSet.Wrap(GetDocIdSet(context, logic, index), acceptDocs);
+ }
+ else if (logicArray != null)
+ {
+ return BitsFilteredDocIdSet.Wrap(GetDocIdSet(context, logicArray, index), acceptDocs);
+ }
- /// <summary>
- /// Ctor.
- /// </summary>
- /// <param name="chain"> The chain of filters </param>
- /// <param name="logic"> Logical operation to apply to ALL filters </param>
- public ChainedFilter(Filter[] chain, int logic)
- {
- this.chain = chain;
- this.logic = logic;
- }
+ return BitsFilteredDocIdSet.Wrap(GetDocIdSet(context, DEFAULT, index), acceptDocs);
+ }
- /// <summary>
- /// <seealso cref="Filter#getDocIdSet"/>.
- /// </summary>
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.search.DocIdSet getDocIdSet(org.apache.lucene.index.AtomicReaderContext context, org.apache.lucene.util.Bits acceptDocs) throws java.io.IOException
- public override DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs)
- {
- int[] index = new int[1]; // use array as reference to modifiable int;
- index[0] = 0; // an object attribute would not be thread safe.
- if (logic != -1)
- {
- return BitsFilteredDocIdSet.wrap(getDocIdSet(context, logic, index), acceptDocs);
- }
- else if (logicArray != null)
- {
- return BitsFilteredDocIdSet.wrap(getDocIdSet(context, logicArray, index), acceptDocs);
- }
+ private DocIdSetIterator GetDISI(Filter filter, AtomicReaderContext context)
+ {
+ // we dont pass acceptDocs, we will filter at the end using an additional filter
+ DocIdSet docIdSet = filter.GetDocIdSet(context, null);
+ if (docIdSet == null)
+ {
+ return DocIdSetIterator.Empty();
+ }
+ else
+ {
+ DocIdSetIterator iter = docIdSet.GetEnumerator();
+ if (iter == null)
+ {
+ return DocIdSetIterator.Empty();
+ }
+ else
+ {
+ return iter;
+ }
+ }
+ }
- return BitsFilteredDocIdSet.wrap(getDocIdSet(context, DEFAULT, index), acceptDocs);
- }
+ private FixedBitSet InitialResult(AtomicReaderContext context, int logic, int[] index)
+ {
+ AtomicReader reader = context.AtomicReader;
+ FixedBitSet result = new FixedBitSet(reader.MaxDoc);
+ if (logic == AND)
+ {
+ result.Or(GetDISI(chain[index[0]], context));
+ ++index[0];
+ }
+ else if (logic == ANDNOT)
+ {
+ result.Or(GetDISI(chain[index[0]], context));
+ result.Flip(0, reader.MaxDoc); // NOTE: may set bits for deleted docs.
+ ++index[0];
+ }
+ return result;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private org.apache.lucene.search.DocIdSetIterator getDISI(org.apache.lucene.search.Filter filter, org.apache.lucene.index.AtomicReaderContext context) throws java.io.IOException
- private DocIdSetIterator getDISI(Filter filter, AtomicReaderContext context)
- {
- // we dont pass acceptDocs, we will filter at the end using an additional filter
- DocIdSet docIdSet = filter.getDocIdSet(context, null);
- if (docIdSet == null)
- {
- return DocIdSetIterator.empty();
- }
- else
- {
- DocIdSetIterator iter = docIdSet.GetEnumerator();
- if (iter == null)
- {
- return DocIdSetIterator.empty();
- }
- else
- {
- return iter;
- }
- }
- }
+ /// <summary>
+ /// Delegates to each filter in the chain.
+ /// </summary>
+ /// <param name="context"> AtomicReaderContext </param>
+ /// <param name="logic"> Logical operation </param>
+ /// <returns> DocIdSet </returns>
+ private DocIdSet GetDocIdSet(AtomicReaderContext context, int logic, int[] index)
+ {
+ FixedBitSet result = InitialResult(context, logic, index);
+ for (; index[0] < chain.Length; index[0]++)
+ {
+ // we dont pass acceptDocs, we will filter at the end using an additional filter
+ doChain(result, logic, chain[index[0]].GetDocIdSet(context, null));
+ }
+ return result;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private org.apache.lucene.util.FixedBitSet initialResult(org.apache.lucene.index.AtomicReaderContext context, int logic, int[] index) throws java.io.IOException
- private FixedBitSet initialResult(AtomicReaderContext context, int logic, int[] index)
- {
- AtomicReader reader = context.reader();
- FixedBitSet result = new FixedBitSet(reader.maxDoc());
- if (logic == AND)
- {
- result.or(getDISI(chain[index[0]], context));
- ++index[0];
- }
- else if (logic == ANDNOT)
- {
- result.or(getDISI(chain[index[0]], context));
- result.flip(0, reader.maxDoc()); // NOTE: may set bits for deleted docs.
- ++index[0];
- }
- return result;
- }
+ /// <summary>
+ /// Delegates to each filter in the chain.
+ /// </summary>
+ /// <param name="context"> AtomicReaderContext </param>
+ /// <param name="logic"> Logical operation </param>
+ /// <returns> DocIdSet </returns>
+ private DocIdSet GetDocIdSet(AtomicReaderContext context, int[] logic, int[] index)
+ {
+ if (logic.Length != chain.Length)
+ {
+ throw new System.ArgumentException("Invalid number of elements in logic array");
+ }
- /// <summary>
- /// Delegates to each filter in the chain.
- /// </summary>
- /// <param name="context"> AtomicReaderContext </param>
- /// <param name="logic"> Logical operation </param>
- /// <returns> DocIdSet </returns>
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private org.apache.lucene.search.DocIdSet getDocIdSet(org.apache.lucene.index.AtomicReaderContext context, int logic, int[] index) throws java.io.IOException
- private DocIdSet getDocIdSet(AtomicReaderContext context, int logic, int[] index)
- {
- FixedBitSet result = initialResult(context, logic, index);
- for (; index[0] < chain.Length; index[0]++)
- {
- // we dont pass acceptDocs, we will filter at the end using an additional filter
- doChain(result, logic, chain[index[0]].getDocIdSet(context, null));
- }
- return result;
- }
+ FixedBitSet result = InitialResult(context, logic[0], index);
+ for (; index[0] < chain.Length; index[0]++)
+ {
+ // we dont pass acceptDocs, we will filter at the end using an additional filter
+ doChain(result, logic[index[0]], chain[index[0]].GetDocIdSet(context, null));
+ }
+ return result;
+ }
- /// <summary>
- /// Delegates to each filter in the chain.
- /// </summary>
- /// <param name="context"> AtomicReaderContext </param>
- /// <param name="logic"> Logical operation </param>
- /// <returns> DocIdSet </returns>
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private org.apache.lucene.search.DocIdSet getDocIdSet(org.apache.lucene.index.AtomicReaderContext context, int[] logic, int[] index) throws java.io.IOException
- private DocIdSet getDocIdSet(AtomicReaderContext context, int[] logic, int[] index)
- {
- if (logic.Length != chain.Length)
- {
- throw new System.ArgumentException("Invalid number of elements in logic array");
- }
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.Append("ChainedFilter: [");
+ foreach (Filter aChain in chain)
+ {
+ sb.Append(aChain);
+ sb.Append(' ');
+ }
+ sb.Append(']');
+ return sb.ToString();
+ }
- FixedBitSet result = initialResult(context, logic[0], index);
- for (; index[0] < chain.Length; index[0]++)
- {
- // we dont pass acceptDocs, we will filter at the end using an additional filter
- doChain(result, logic[index[0]], chain[index[0]].getDocIdSet(context, null));
- }
- return result;
- }
-
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("ChainedFilter: [");
- foreach (Filter aChain in chain)
- {
- sb.Append(aChain);
- sb.Append(' ');
- }
- sb.Append(']');
- return sb.ToString();
- }
-
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: private void doChain(org.apache.lucene.util.FixedBitSet result, int logic, org.apache.lucene.search.DocIdSet dis) throws java.io.IOException
- private void doChain(FixedBitSet result, int logic, DocIdSet dis)
- {
- if (dis is FixedBitSet)
- {
- // optimized case for FixedBitSets
- switch (logic)
- {
- case OR:
- result.or((FixedBitSet) dis);
- break;
- case AND:
- result.and((FixedBitSet) dis);
- break;
- case ANDNOT:
- result.andNot((FixedBitSet) dis);
- break;
- case XOR:
- result.xor((FixedBitSet) dis);
- break;
- default:
- doChain(result, DEFAULT, dis);
- break;
- }
- }
- else
- {
- DocIdSetIterator disi;
- if (dis == null)
- {
- disi = DocIdSetIterator.empty();
- }
- else
- {
- disi = dis.GetEnumerator();
- if (disi == null)
- {
- disi = DocIdSetIterator.empty();
- }
- }
-
- switch (logic)
- {
- case OR:
- result.or(disi);
- break;
- case AND:
- result.and(disi);
- break;
- case ANDNOT:
- result.andNot(disi);
- break;
- case XOR:
- result.xor(disi);
- break;
- default:
- doChain(result, DEFAULT, dis);
- break;
- }
- }
- }
-
- }
+ //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
+ //ORIGINAL LINE: private void doChain(org.apache.lucene.util.FixedBitSet result, int logic, org.apache.lucene.search.DocIdSet dis) throws java.io.IOException
+ private void doChain(FixedBitSet result, int logic, DocIdSet dis)
+ {
+ if (dis is FixedBitSet)
+ {
+ // optimized case for FixedBitSets
+ switch (logic)
+ {
+ case OR:
+ result.Or((FixedBitSet)dis);
+ break;
+ case AND:
+ result.And((FixedBitSet)dis);
+ break;
+ case ANDNOT:
+ result.AndNot((FixedBitSet)dis);
+ break;
+ case XOR:
+ result.Xor((FixedBitSet)dis);
+ break;
+ default:
+ doChain(result, DEFAULT, dis);
+ break;
+ }
+ }
+ else
+ {
+ DocIdSetIterator disi;
+ if (dis == null)
+ {
+ disi = DocIdSetIterator.Empty();
+ }
+ else
+ {
+ disi = dis.GetEnumerator();
+ if (disi == null)
+ {
+ disi = DocIdSetIterator.Empty();
+ }
+ }
+ switch (logic)
+ {
+ case OR:
+ result.Or(disi);
+ break;
+ case AND:
+ result.And(disi);
+ break;
+ case ANDNOT:
+ result.AndNot(disi);
+ break;
+ case XOR:
+ result.Xor(disi);
+ break;
+ default:
+ doChain(result, DEFAULT, dis);
+ break;
+ }
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ba0f3c7d/src/Lucene.Net.Queries/CommonTermsQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Queries/CommonTermsQuery.cs b/src/Lucene.Net.Queries/CommonTermsQuery.cs
index 0d78a68..70f093d 100644
--- a/src/Lucene.Net.Queries/CommonTermsQuery.cs
+++ b/src/Lucene.Net.Queries/CommonTermsQuery.cs
@@ -1,526 +1,480 @@
using System;
-using System.Diagnostics;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
using System.Text;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Search.Similarities;
+using Lucene.Net.Support;
+using Lucene.Net.Util;
-namespace org.apache.lucene.queries
+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.
- */
- using AtomicReaderContext = org.apache.lucene.index.AtomicReaderContext;
- using Fields = org.apache.lucene.index.Fields;
- using IndexReader = org.apache.lucene.index.IndexReader;
- using Term = org.apache.lucene.index.Term;
- using TermContext = org.apache.lucene.index.TermContext;
- using Terms = org.apache.lucene.index.Terms;
- using TermsEnum = org.apache.lucene.index.TermsEnum;
- using BooleanClause = org.apache.lucene.search.BooleanClause;
- using Occur = org.apache.lucene.search.BooleanClause.Occur;
- using BooleanQuery = org.apache.lucene.search.BooleanQuery;
- using Query = org.apache.lucene.search.Query;
- using TermQuery = org.apache.lucene.search.TermQuery;
- using Similarity = org.apache.lucene.search.similarities.Similarity;
- using ToStringUtils = org.apache.lucene.util.ToStringUtils;
-
-
- /// <summary>
- /// A query that executes high-frequency terms in a optional sub-query to prevent
- /// slow queries due to "common" terms like stopwords. This query
- /// builds 2 queries off the <seealso cref="#add(Term) added"/> terms: low-frequency
- /// terms are added to a required boolean clause and high-frequency terms are
- /// added to an optional boolean clause. The optional clause is only executed if
- /// the required "low-frequency" clause matches. Scores produced by this query
- /// will be slightly different than plain <seealso cref="BooleanQuery"/> scorer mainly due to
- /// differences in the <seealso cref="Similarity#coord(int,int) number of leaf queries"/>
- /// in the required boolean clause. In most cases, high-frequency terms are
- /// unlikely to significantly contribute to the document score unless at least
- /// one of the low-frequency terms are matched. This query can improve
- /// query execution times significantly if applicable.
- /// <para>
- /// <seealso cref="CommonTermsQuery"/> has several advantages over stopword filtering at
- /// index or query time since a term can be "classified" based on the actual
- /// document frequency in the index and can prevent slow queries even across
- /// domains without specialized stopword files.
- /// </para>
- /// <para>
- /// <b>Note:</b> if the query only contains high-frequency terms the query is
- /// rewritten into a plain conjunction query ie. all high-frequency terms need to
- /// match in order to match a document.
- /// </para>
- /// </summary>
- public class CommonTermsQuery : Query
- {
- /*
- * TODO maybe it would make sense to abstract this even further and allow to
- * rewrite to dismax rather than boolean. Yet, this can already be subclassed
- * to do so.
- */
- protected internal readonly IList<Term> terms = new List<Term>();
- protected internal readonly bool disableCoord;
- protected internal readonly float maxTermFrequency;
- protected internal readonly BooleanClause.Occur lowFreqOccur;
- protected internal readonly BooleanClause.Occur highFreqOccur;
- protected internal float lowFreqBoost = 1.0f;
- protected internal float highFreqBoost = 1.0f;
- protected internal float lowFreqMinNrShouldMatch = 0;
- protected internal float highFreqMinNrShouldMatch = 0;
-
- /// <summary>
- /// Creates a new <seealso cref="CommonTermsQuery"/>
- /// </summary>
- /// <param name="highFreqOccur">
- /// <seealso cref="Occur"/> used for high frequency terms </param>
- /// <param name="lowFreqOccur">
- /// <seealso cref="Occur"/> used for low frequency terms </param>
- /// <param name="maxTermFrequency">
- /// a value in [0..1) (or absolute number >=1) representing the
- /// maximum threshold of a terms document frequency to be considered a
- /// low frequency term. </param>
- /// <exception cref="IllegalArgumentException">
- /// if <seealso cref="Occur#MUST_NOT"/> is pass as lowFreqOccur or
- /// highFreqOccur </exception>
- public CommonTermsQuery(BooleanClause.Occur highFreqOccur, BooleanClause.Occur lowFreqOccur, float maxTermFrequency) : this(highFreqOccur, lowFreqOccur, maxTermFrequency, false)
- {
- }
+ /*
+ * 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>
+ /// A query that executes high-frequency terms in a optional sub-query to prevent
+ /// slow queries due to "common" terms like stopwords. This query
+ /// builds 2 queries off the <seealso cref="#add(Term) added"/> terms: low-frequency
+ /// terms are added to a required boolean clause and high-frequency terms are
+ /// added to an optional boolean clause. The optional clause is only executed if
+ /// the required "low-frequency" clause matches. Scores produced by this query
+ /// will be slightly different than plain <seealso cref="BooleanQuery"/> scorer mainly due to
+ /// differences in the <seealso cref="Similarity#coord(int,int) number of leaf queries"/>
+ /// in the required boolean clause. In most cases, high-frequency terms are
+ /// unlikely to significantly contribute to the document score unless at least
+ /// one of the low-frequency terms are matched. This query can improve
+ /// query execution times significantly if applicable.
+ /// <para>
+ /// <seealso cref="CommonTermsQuery"/> has several advantages over stopword filtering at
+ /// index or query time since a term can be "classified" based on the actual
+ /// document frequency in the index and can prevent slow queries even across
+ /// domains without specialized stopword files.
+ /// </para>
+ /// <para>
+ /// <b>Note:</b> if the query only contains high-frequency terms the query is
+ /// rewritten into a plain conjunction query ie. all high-frequency terms need to
+ /// match in order to match a document.
+ /// </para>
+ /// </summary>
+ public class CommonTermsQuery : Query
+ {
+ /*
+ * TODO maybe it would make sense to abstract this even further and allow to
+ * rewrite to dismax rather than boolean. Yet, this can already be subclassed
+ * to do so.
+ */
+ protected internal readonly IList<Term> terms = new List<Term>();
+ protected internal readonly bool disableCoord;
+ protected internal readonly float maxTermFrequency;
+ protected internal readonly BooleanClause.Occur lowFreqOccur;
+ protected internal readonly BooleanClause.Occur highFreqOccur;
+ protected internal float lowFreqBoost = 1.0f;
+ protected internal float highFreqBoost = 1.0f;
+
- /// <summary>
- /// Creates a new <seealso cref="CommonTermsQuery"/>
- /// </summary>
- /// <param name="highFreqOccur">
- /// <seealso cref="Occur"/> used for high frequency terms </param>
- /// <param name="lowFreqOccur">
- /// <seealso cref="Occur"/> used for low frequency terms </param>
- /// <param name="maxTermFrequency">
- /// a value in [0..1) (or absolute number >=1) representing the
- /// maximum threshold of a terms document frequency to be considered a
- /// low frequency term. </param>
- /// <param name="disableCoord">
- /// disables <seealso cref="Similarity#coord(int,int)"/> in scoring for the low
- /// / high frequency sub-queries </param>
- /// <exception cref="IllegalArgumentException">
- /// if <seealso cref="Occur#MUST_NOT"/> is pass as lowFreqOccur or
- /// highFreqOccur </exception>
- public CommonTermsQuery(BooleanClause.Occur highFreqOccur, BooleanClause.Occur lowFreqOccur, float maxTermFrequency, bool disableCoord)
- {
- if (highFreqOccur == BooleanClause.Occur.MUST_NOT)
- {
- throw new System.ArgumentException("highFreqOccur should be MUST or SHOULD but was MUST_NOT");
- }
- if (lowFreqOccur == BooleanClause.Occur.MUST_NOT)
- {
- throw new System.ArgumentException("lowFreqOccur should be MUST or SHOULD but was MUST_NOT");
- }
- this.disableCoord = disableCoord;
- this.highFreqOccur = highFreqOccur;
- this.lowFreqOccur = lowFreqOccur;
- this.maxTermFrequency = maxTermFrequency;
- }
+ /// <summary>
+ /// Creates a new <seealso cref="CommonTermsQuery"/>
+ /// </summary>
+ /// <param name="highFreqOccur">
+ /// <seealso cref="BooleanClause.Occur"/> used for high frequency terms </param>
+ /// <param name="lowFreqOccur">
+ /// <seealso cref="BooleanClause.Occur"/> used for low frequency terms </param>
+ /// <param name="maxTermFrequency">
+ /// a value in [0..1) (or absolute number >=1) representing the
+ /// maximum threshold of a terms document frequency to be considered a
+ /// low frequency term. </param>
+ /// <exception cref="ArgumentException">
+ /// if <seealso cref="BooleanClause.Occur#MUST_NOT"/> is pass as lowFreqOccur or
+ /// highFreqOccur </exception>
+ public CommonTermsQuery(BooleanClause.Occur highFreqOccur, BooleanClause.Occur lowFreqOccur, float maxTermFrequency)
+ : this(highFreqOccur, lowFreqOccur, maxTermFrequency, false)
+ {
+ }
- /// <summary>
- /// Adds a term to the <seealso cref="CommonTermsQuery"/>
- /// </summary>
- /// <param name="term">
- /// the term to add </param>
- public virtual void add(Term term)
- {
- if (term == null)
- {
- throw new System.ArgumentException("Term must not be null");
- }
- this.terms.Add(term);
- }
+ /// <summary>
+ /// Creates a new <seealso cref="CommonTermsQuery"/>
+ /// </summary>
+ /// <param name="highFreqOccur">
+ /// <seealso cref="BooleanClause.Occur"/> used for high frequency terms </param>
+ /// <param name="lowFreqOccur">
+ /// <seealso cref="BooleanClause.Occur"/> used for low frequency terms </param>
+ /// <param name="maxTermFrequency">
+ /// a value in [0..1) (or absolute number >=1) representing the
+ /// maximum threshold of a terms document frequency to be considered a
+ /// low frequency term. </param>
+ /// <param name="disableCoord">
+ /// disables <seealso cref="Similarity#coord(int,int)"/> in scoring for the low
+ /// / high frequency sub-queries </param>
+ /// <exception cref="ArgumentException">
+ /// if <seealso cref="BooleanClause.Occur#MUST_NOT"/> is pass as lowFreqOccur or
+ /// highFreqOccur </exception>
+ public CommonTermsQuery(BooleanClause.Occur highFreqOccur, BooleanClause.Occur lowFreqOccur,
+ float maxTermFrequency, bool disableCoord)
+ {
+ if (highFreqOccur == BooleanClause.Occur.MUST_NOT)
+ {
+ throw new System.ArgumentException("highFreqOccur should be MUST or SHOULD but was MUST_NOT");
+ }
+ if (lowFreqOccur == BooleanClause.Occur.MUST_NOT)
+ {
+ throw new System.ArgumentException("lowFreqOccur should be MUST or SHOULD but was MUST_NOT");
+ }
+ this.disableCoord = disableCoord;
+ this.highFreqOccur = highFreqOccur;
+ this.lowFreqOccur = lowFreqOccur;
+ this.maxTermFrequency = maxTermFrequency;
+ LowFreqMinimumNumberShouldMatch = 0;
+ HighFreqMinimumNumberShouldMatch = 0;
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: @Override public org.apache.lucene.search.Query rewrite(org.apache.lucene.index.IndexReader reader) throws java.io.IOException
- public override Query rewrite(IndexReader reader)
- {
- if (this.terms.Count == 0)
- {
- return new BooleanQuery();
- }
- else if (this.terms.Count == 1)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.search.Query tq = newTermQuery(this.terms.get(0), null);
- Query tq = newTermQuery(this.terms[0], null);
- tq.Boost = Boost;
- return tq;
- }
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final java.util.List<org.apache.lucene.index.AtomicReaderContext> leaves = reader.leaves();
- IList<AtomicReaderContext> leaves = reader.leaves();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int maxDoc = reader.maxDoc();
- int maxDoc = reader.maxDoc();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.TermContext[] contextArray = new org.apache.lucene.index.TermContext[terms.size()];
- TermContext[] contextArray = new TermContext[terms.Count];
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.Term[] queryTerms = this.terms.toArray(new org.apache.lucene.index.Term[0]);
- Term[] queryTerms = this.terms.ToArray();
- collectTermContext(reader, leaves, contextArray, queryTerms);
- return buildQuery(maxDoc, contextArray, queryTerms);
- }
+ /// <summary>
+ /// Adds a term to the <seealso cref="CommonTermsQuery"/>
+ /// </summary>
+ /// <param name="term">
+ /// the term to add </param>
+ public virtual void Add(Term term)
+ {
+ if (term == null)
+ {
+ throw new ArgumentException("Term must not be null");
+ }
+ this.terms.Add(term);
+ }
- protected internal virtual int calcLowFreqMinimumNumberShouldMatch(int numOptional)
- {
- return minNrShouldMatch(lowFreqMinNrShouldMatch, numOptional);
- }
+ public override Query Rewrite(IndexReader reader)
+ {
+ if (this.terms.Count == 0)
+ {
+ return new BooleanQuery();
+ }
+ else if (this.terms.Count == 1)
+ {
+ Query tq = NewTermQuery(this.terms[0], null);
+ tq.Boost = Boost;
+ return tq;
+ }
+ var leaves = reader.Leaves;
+ int maxDoc = reader.MaxDoc;
+ var contextArray = new TermContext[terms.Count];
+ var queryTerms = this.terms.ToArray();
+ CollectTermContext(reader, leaves, contextArray, queryTerms);
+ return BuildQuery(maxDoc, contextArray, queryTerms);
+ }
- protected internal virtual int calcHighFreqMinimumNumberShouldMatch(int numOptional)
- {
- return minNrShouldMatch(highFreqMinNrShouldMatch, numOptional);
- }
+ protected internal virtual int CalcLowFreqMinimumNumberShouldMatch(int numOptional)
+ {
+ return MinNrShouldMatch(LowFreqMinimumNumberShouldMatch, numOptional);
+ }
- private int minNrShouldMatch(float minNrShouldMatch, int numOptional)
- {
- if (minNrShouldMatch >= 1.0f || minNrShouldMatch == 0.0f)
- {
- return (int) minNrShouldMatch;
- }
- return Math.Round(minNrShouldMatch * numOptional);
- }
+ protected internal virtual int CalcHighFreqMinimumNumberShouldMatch(int numOptional)
+ {
+ return MinNrShouldMatch(HighFreqMinimumNumberShouldMatch, numOptional);
+ }
-//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
-//ORIGINAL LINE: protected org.apache.lucene.search.Query buildQuery(final int maxDoc, final org.apache.lucene.index.TermContext[] contextArray, final org.apache.lucene.index.Term[] queryTerms)
- protected internal virtual Query buildQuery(int maxDoc, TermContext[] contextArray, Term[] queryTerms)
- {
- BooleanQuery lowFreq = new BooleanQuery(disableCoord);
- BooleanQuery highFreq = new BooleanQuery(disableCoord);
- highFreq.Boost = highFreqBoost;
- lowFreq.Boost = lowFreqBoost;
- BooleanQuery query = new BooleanQuery(true);
- for (int i = 0; i < queryTerms.Length; i++)
- {
- TermContext termContext = contextArray[i];
- if (termContext == null)
- {
- lowFreq.add(newTermQuery(queryTerms[i], null), lowFreqOccur);
- }
- else
- {
- if ((maxTermFrequency >= 1f && termContext.docFreq() > maxTermFrequency) || (termContext.docFreq() > (int) Math.Ceiling(maxTermFrequency * (float) maxDoc)))
- {
- highFreq.add(newTermQuery(queryTerms[i], termContext), highFreqOccur);
- }
- else
- {
- lowFreq.add(newTermQuery(queryTerms[i], termContext), lowFreqOccur);
- }
- }
+ private int MinNrShouldMatch(float minNrShouldMatch, int numOptional)
+ {
+ if (minNrShouldMatch >= 1.0f || minNrShouldMatch == 0.0f)
+ {
+ return (int)minNrShouldMatch;
+ }
+ return Math.Round(minNrShouldMatch * numOptional);
+ }
- }
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int numLowFreqClauses = lowFreq.clauses().size();
- int numLowFreqClauses = lowFreq.clauses().size();
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final int numHighFreqClauses = highFreq.clauses().size();
- int numHighFreqClauses = highFreq.clauses().size();
- if (lowFreqOccur == BooleanClause.Occur.SHOULD && numLowFreqClauses > 0)
- {
- int minMustMatch = calcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
- lowFreq.MinimumNumberShouldMatch = minMustMatch;
- }
- if (highFreqOccur == BooleanClause.Occur.SHOULD && numHighFreqClauses > 0)
- {
- int minMustMatch = calcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
- highFreq.MinimumNumberShouldMatch = minMustMatch;
- }
- if (lowFreq.clauses().Empty)
- {
- /*
- * if lowFreq is empty we rewrite the high freq terms in a conjunction to
- * prevent slow queries.
- */
- if (highFreq.MinimumNumberShouldMatch == 0 && highFreqOccur != BooleanClause.Occur.MUST)
- {
- foreach (BooleanClause booleanClause in highFreq)
- {
- booleanClause.Occur = BooleanClause.Occur.MUST;
- }
- }
- highFreq.Boost = Boost;
- return highFreq;
- }
- else if (highFreq.clauses().Empty)
- {
- // only do low freq terms - we don't have high freq terms
- lowFreq.Boost = Boost;
- return lowFreq;
- }
- else
- {
- query.add(highFreq, BooleanClause.Occur.SHOULD);
- query.add(lowFreq, BooleanClause.Occur.MUST);
- query.Boost = Boost;
- return query;
- }
- }
+ protected internal virtual Query BuildQuery(int maxDoc, TermContext[] contextArray, Term[] queryTerms)
+ {
+ BooleanQuery lowFreq = new BooleanQuery(disableCoord);
+ BooleanQuery highFreq = new BooleanQuery(disableCoord);
+ highFreq.Boost = highFreqBoost;
+ lowFreq.Boost = lowFreqBoost;
+ BooleanQuery query = new BooleanQuery(true);
+ for (int i = 0; i < queryTerms.Length; i++)
+ {
+ TermContext termContext = contextArray[i];
+ if (termContext == null)
+ {
+ lowFreq.Add(NewTermQuery(queryTerms[i], null), lowFreqOccur);
+ }
+ else
+ {
+ if ((maxTermFrequency >= 1f && termContext.DocFreq > maxTermFrequency) || (termContext.DocFreq > (int)Math.Ceiling(maxTermFrequency * (float)maxDoc)))
+ {
+ highFreq.Add(NewTermQuery(queryTerms[i], termContext), highFreqOccur);
+ }
+ else
+ {
+ lowFreq.Add(NewTermQuery(queryTerms[i], termContext), lowFreqOccur);
+ }
+ }
-//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
-//ORIGINAL LINE: public void collectTermContext(org.apache.lucene.index.IndexReader reader, java.util.List<org.apache.lucene.index.AtomicReaderContext> leaves, org.apache.lucene.index.TermContext[] contextArray, org.apache.lucene.index.Term[] queryTerms) throws java.io.IOException
- public virtual void collectTermContext(IndexReader reader, IList<AtomicReaderContext> leaves, TermContext[] contextArray, Term[] queryTerms)
- {
- TermsEnum termsEnum = null;
- foreach (AtomicReaderContext context in leaves)
- {
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.Fields fields = context.reader().fields();
- Fields fields = context.reader().fields();
- if (fields == null)
- {
- // reader has no fields
- continue;
- }
- for (int i = 0; i < queryTerms.Length; i++)
- {
- Term term = queryTerms[i];
- TermContext termContext = contextArray[i];
-//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
-//ORIGINAL LINE: final org.apache.lucene.index.Terms terms = fields.terms(term.field());
- Terms terms = fields.terms(term.field());
- if (terms == null)
- {
- // field does not exist
- continue;
- }
- termsEnum = terms.iterator(termsEnum);
- Debug.Assert(termsEnum != null);
+ }
+ //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+ //ORIGINAL LINE: final int numLowFreqClauses = lowFreq.clauses().size();
+ int numLowFreqClauses = lowFreq.Clauses.Length;
+ //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+ //ORIGINAL LINE: final int numHighFreqClauses = highFreq.clauses().size();
+ int numHighFreqClauses = highFreq.Clauses.Length;
+ if (lowFreqOccur == BooleanClause.Occur.SHOULD && numLowFreqClauses > 0)
+ {
+ int minMustMatch = CalcLowFreqMinimumNumberShouldMatch(numLowFreqClauses);
+ lowFreq.MinimumNumberShouldMatch = minMustMatch;
+ }
+ if (highFreqOccur == BooleanClause.Occur.SHOULD && numHighFreqClauses > 0)
+ {
+ int minMustMatch = CalcHighFreqMinimumNumberShouldMatch(numHighFreqClauses);
+ highFreq.MinimumNumberShouldMatch = minMustMatch;
+ }
+ if (lowFreq.Clauses.Length == 0)
+ {
+ /*
+ * if lowFreq is empty we rewrite the high freq terms in a conjunction to
+ * prevent slow queries.
+ */
+ if (highFreq.MinimumNumberShouldMatch == 0 && highFreqOccur != BooleanClause.Occur.MUST)
+ {
+ foreach (BooleanClause booleanClause in highFreq)
+ {
+ booleanClause.Occur = BooleanClause.Occur.MUST;
+ }
+ }
+ highFreq.Boost = Boost;
+ return highFreq;
+ }
+ else if (highFreq.Clauses.Length == 0)
+ {
+ // only do low freq terms - we don't have high freq terms
+ lowFreq.Boost = Boost;
+ return lowFreq;
+ }
+ else
+ {
+ query.Add(highFreq, BooleanClause.Occur.SHOULD);
+ query.Add(lowFreq, BooleanClause.Occur.MUST);
+ query.Boost = Boost;
+ return query;
+ }
+ }
- if (termsEnum == TermsEnum.EMPTY)
- {
- continue;
- }
- if (termsEnum.seekExact(term.bytes()))
- {
- if (termContext == null)
- {
- contextArray[i] = new TermContext(reader.Context, termsEnum.termState(), context.ord, termsEnum.docFreq(), termsEnum.totalTermFreq());
- }
- else
- {
- termContext.register(termsEnum.termState(), context.ord, termsEnum.docFreq(), termsEnum.totalTermFreq());
- }
+ public virtual void CollectTermContext(IndexReader reader, IList<AtomicReaderContext> leaves, TermContext[] contextArray, Term[] queryTerms)
+ {
+ TermsEnum termsEnum = null;
+ foreach (AtomicReaderContext context in leaves)
+ {
+ Fields fields = context.AtomicReader.Fields;
+ if (fields == null)
+ {
+ // reader has no fields
+ continue;
+ }
+ for (int i = 0; i < queryTerms.Length; i++)
+ {
+ Term term = queryTerms[i];
+ TermContext termContext = contextArray[i];
+ //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
+ //ORIGINAL LINE: final org.apache.lucene.index.Terms terms = fields.terms(term.field());
+ Terms terms = fields.Terms(term.Field());
+ if (terms == null)
+ {
+ // field does not exist
+ continue;
+ }
+ termsEnum = terms.Iterator(termsEnum);
+ Debug.Assert(termsEnum != null);
- }
+ if (termsEnum == TermsEnum.EMPTY)
+ {
+ continue;
+ }
+ if (termsEnum.SeekExact(term.Bytes()))
+ {
+ if (termContext == null)
+ {
+ contextArray[i] = new TermContext(reader.Context, termsEnum.TermState(), context.Ord, termsEnum.DocFreq(), termsEnum.TotalTermFreq());
+ }
+ else
+ {
+ termContext.Register(termsEnum.TermState(), context.Ord, termsEnum.DocFreq(), termsEnum.TotalTermFreq());
+ }
- }
- }
- }
+ }
- /// <summary>
- /// Returns true iff <seealso cref="Similarity#coord(int,int)"/> is disabled in scoring
- /// for the high and low frequency query instance. The top level query will
- /// always disable coords.
- /// </summary>
- public virtual bool CoordDisabled
- {
- get
- {
- return disableCoord;
- }
- }
+ }
+ }
+ }
- /// <summary>
- /// Specifies a minimum number of the low frequent optional BooleanClauses which must be
- /// satisfied in order to produce a match on the low frequency terms query
- /// part. This method accepts a float value in the range [0..1) as a fraction
- /// of the actual query terms in the low frequent clause or a number
- /// <tt>>=1</tt> as an absolut number of clauses that need to match.
- ///
- /// <para>
- /// By default no optional clauses are necessary for a match (unless there are
- /// no required clauses). If this method is used, then the specified number of
- /// clauses is required.
- /// </para>
- /// </summary>
- /// <param name="min">
- /// the number of optional clauses that must match </param>
- public virtual float LowFreqMinimumNumberShouldMatch
- {
- set
- {
- this.lowFreqMinNrShouldMatch = value;
- }
- get
- {
- return lowFreqMinNrShouldMatch;
- }
- }
+ /// <summary>
+ /// Returns true iff <seealso cref="Similarity#coord(int,int)"/> is disabled in scoring
+ /// for the high and low frequency query instance. The top level query will
+ /// always disable coords.
+ /// </summary>
+ public virtual bool CoordDisabled
+ {
+ get
+ {
+ return disableCoord;
+ }
+ }
+ /// <summary>
+ /// Specifies a minimum number of the low frequent optional BooleanClauses which must be
+ /// satisfied in order to produce a match on the low frequency terms query
+ /// part. This method accepts a float value in the range [0..1) as a fraction
+ /// of the actual query terms in the low frequent clause or a number
+ /// <tt>>=1</tt> as an absolut number of clauses that need to match.
+ ///
+ /// <para>
+ /// By default no optional clauses are necessary for a match (unless there are
+ /// no required clauses). If this method is used, then the specified number of
+ /// clauses is required.
+ /// </para>
+ /// </summary>
+ /// <param name="min">
+ /// the number of optional clauses that must match </param>
+ public float LowFreqMinimumNumberShouldMatch { get; set; }
- /// <summary>
- /// Specifies a minimum number of the high frequent optional BooleanClauses which must be
- /// satisfied in order to produce a match on the low frequency terms query
- /// part. This method accepts a float value in the range [0..1) as a fraction
- /// of the actual query terms in the low frequent clause or a number
- /// <tt>>=1</tt> as an absolut number of clauses that need to match.
- ///
- /// <para>
- /// By default no optional clauses are necessary for a match (unless there are
- /// no required clauses). If this method is used, then the specified number of
- /// clauses is required.
- /// </para>
- /// </summary>
- /// <param name="min">
- /// the number of optional clauses that must match </param>
- public virtual float HighFreqMinimumNumberShouldMatch
- {
- set
- {
- this.highFreqMinNrShouldMatch = value;
- }
- get
- {
- return highFreqMinNrShouldMatch;
- }
- }
+ /// <summary>
+ /// Specifies a minimum number of the high frequent optional BooleanClauses which must be
+ /// satisfied in order to produce a match on the low frequency terms query
+ /// part. This method accepts a float value in the range [0..1) as a fraction
+ /// of the actual query terms in the low frequent clause or a number
+ /// <tt>>=1</tt> as an absolut number of clauses that need to match.
+ ///
+ /// <para>
+ /// By default no optional clauses are necessary for a match (unless there are
+ /// no required clauses). If this method is used, then the specified number of
+ /// clauses is required.
+ /// </para>
+ /// </summary>
+ /// <param name="min">
+ /// the number of optional clauses that must match </param>
+ public float HighFreqMinimumNumberShouldMatch { get; set; }
- public override void extractTerms(HashSet<Term> terms)
- {
- terms.addAll(this.terms);
- }
- public override string ToString(string field)
- {
- StringBuilder buffer = new StringBuilder();
- bool needParens = (Boost != 1.0) || (LowFreqMinimumNumberShouldMatch > 0);
- if (needParens)
- {
- buffer.Append("(");
- }
- for (int i = 0; i < terms.Count; i++)
- {
- Term t = terms[i];
- buffer.Append(newTermQuery(t, null).ToString());
+ public override void ExtractTerms(HashSet<Term> terms)
+ {
+ terms.AddAll(this.terms);
+ }
- if (i != terms.Count - 1)
- {
- buffer.Append(", ");
- }
- }
- if (needParens)
- {
- buffer.Append(")");
- }
- if (LowFreqMinimumNumberShouldMatch > 0 || HighFreqMinimumNumberShouldMatch > 0)
- {
- buffer.Append('~');
- buffer.Append("(");
- buffer.Append(LowFreqMinimumNumberShouldMatch);
- buffer.Append(HighFreqMinimumNumberShouldMatch);
- buffer.Append(")");
- }
- if (Boost != 1.0f)
- {
- buffer.Append(ToStringUtils.boost(Boost));
- }
- return buffer.ToString();
- }
+ public override string ToString(string field)
+ {
+ StringBuilder buffer = new StringBuilder();
+ bool needParens = (Boost != 1.0) || (LowFreqMinimumNumberShouldMatch > 0);
+ if (needParens)
+ {
+ buffer.Append("(");
+ }
+ for (int i = 0; i < terms.Count; i++)
+ {
+ Term t = terms[i];
+ buffer.Append(NewTermQuery(t, null).ToString());
- public override int GetHashCode()
- {
- const int prime = 31;
- int result = base.GetHashCode();
- result = prime * result + (disableCoord ? 1231 : 1237);
- result = prime * result + float.floatToIntBits(highFreqBoost);
- result = prime * result + ((highFreqOccur == null) ? 0 : highFreqOccur.GetHashCode());
- result = prime * result + float.floatToIntBits(lowFreqBoost);
- result = prime * result + ((lowFreqOccur == null) ? 0 : lowFreqOccur.GetHashCode());
- result = prime * result + float.floatToIntBits(maxTermFrequency);
- result = prime * result + float.floatToIntBits(lowFreqMinNrShouldMatch);
- result = prime * result + float.floatToIntBits(highFreqMinNrShouldMatch);
- result = prime * result + ((terms == null) ? 0 : terms.GetHashCode());
- return result;
- }
+ if (i != terms.Count - 1)
+ {
+ buffer.Append(", ");
+ }
+ }
+ if (needParens)
+ {
+ buffer.Append(")");
+ }
+ if (LowFreqMinimumNumberShouldMatch > 0 || HighFreqMinimumNumberShouldMatch > 0)
+ {
+ buffer.Append('~');
+ buffer.Append("(");
+ buffer.Append(LowFreqMinimumNumberShouldMatch);
+ buffer.Append(HighFreqMinimumNumberShouldMatch);
+ buffer.Append(")");
+ }
+ if (Boost != 1.0f)
+ {
+ buffer.Append(ToStringUtils.Boost(Boost));
+ }
+ return buffer.ToString();
+ }
- public override bool Equals(object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (!base.Equals(obj))
- {
- return false;
- }
- if (this.GetType() != obj.GetType())
- {
- return false;
- }
- CommonTermsQuery other = (CommonTermsQuery) obj;
- if (disableCoord != other.disableCoord)
- {
- return false;
- }
- if (float.floatToIntBits(highFreqBoost) != float.floatToIntBits(other.highFreqBoost))
- {
- return false;
- }
- if (highFreqOccur != other.highFreqOccur)
- {
- return false;
- }
- if (float.floatToIntBits(lowFreqBoost) != float.floatToIntBits(other.lowFreqBoost))
- {
- return false;
- }
- if (lowFreqOccur != other.lowFreqOccur)
- {
- return false;
- }
- if (float.floatToIntBits(maxTermFrequency) != float.floatToIntBits(other.maxTermFrequency))
- {
- return false;
- }
- if (lowFreqMinNrShouldMatch != other.lowFreqMinNrShouldMatch)
- {
- return false;
- }
- if (highFreqMinNrShouldMatch != other.highFreqMinNrShouldMatch)
- {
- return false;
- }
- if (terms == null)
- {
- if (other.terms != null)
- {
- return false;
- }
- }
- else if (!terms.Equals(other.terms))
- {
- return false;
- }
- return true;
- }
+ public override int GetHashCode()
+ {
+ const int prime = 31;
+ int result = base.GetHashCode();
+ result = prime * result + (disableCoord ? 1231 : 1237);
+ result = prime * result + Number.FloatToIntBits(highFreqBoost);
+ result = prime * result + ((highFreqOccur == null) ? 0 : highFreqOccur.GetHashCode());
+ result = prime * result + Number.FloatToIntBits(lowFreqBoost);
+ result = prime * result + ((lowFreqOccur == null) ? 0 : lowFreqOccur.GetHashCode());
+ result = prime * result + Number.FloatToIntBits(maxTermFrequency);
+ result = prime * result + Number.FloatToIntBits(LowFreqMinimumNumberShouldMatch);
+ result = prime * result + Number.FloatToIntBits(HighFreqMinimumNumberShouldMatch);
+ result = prime * result + ((terms == null) ? 0 : terms.GetHashCode());
+ return result;
+ }
- /// <summary>
- /// Builds a new TermQuery instance.
- /// <para>This is intended for subclasses that wish to customize the generated queries.</para> </summary>
- /// <param name="term"> term </param>
- /// <param name="context"> the TermContext to be used to create the low level term query. Can be <code>null</code>. </param>
- /// <returns> new TermQuery instance </returns>
- protected internal virtual Query newTermQuery(Term term, TermContext context)
- {
- return context == null ? new TermQuery(term) : new TermQuery(term, context);
- }
- }
+ public override bool Equals(object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!base.Equals(obj))
+ {
+ return false;
+ }
+ if (this.GetType() != obj.GetType())
+ {
+ return false;
+ }
+ CommonTermsQuery other = (CommonTermsQuery)obj;
+ if (disableCoord != other.disableCoord)
+ {
+ return false;
+ }
+ if (Number.FloatToIntBits(highFreqBoost) != Number.FloatToIntBits(other.highFreqBoost))
+ {
+ return false;
+ }
+ if (highFreqOccur != other.highFreqOccur)
+ {
+ return false;
+ }
+ if (Number.FloatToIntBits(lowFreqBoost) != Number.FloatToIntBits(other.lowFreqBoost))
+ {
+ return false;
+ }
+ if (lowFreqOccur != other.lowFreqOccur)
+ {
+ return false;
+ }
+ if (Number.FloatToIntBits(maxTermFrequency) != Number.FloatToIntBits(other.maxTermFrequency))
+ {
+ return false;
+ }
+ if (LowFreqMinimumNumberShouldMatch != other.LowFreqMinimumNumberShouldMatch)
+ {
+ return false;
+ }
+ if (HighFreqMinimumNumberShouldMatch != other.HighFreqMinimumNumberShouldMatch)
+ {
+ return false;
+ }
+ if (terms == null)
+ {
+ if (other.terms != null)
+ {
+ return false;
+ }
+ }
+ else if (!terms.Equals(other.terms))
+ {
+ return false;
+ }
+ return true;
+ }
+ /// <summary>
+ /// Builds a new TermQuery instance.
+ /// <para>This is intended for subclasses that wish to customize the generated queries.</para> </summary>
+ /// <param name="term"> term </param>
+ /// <param name="context"> the TermContext to be used to create the low level term query. Can be <code>null</code>. </param>
+ /// <returns> new TermQuery instance </returns>
+ protected virtual Query NewTermQuery(Term term, TermContext context)
+ {
+ return context == null ? new TermQuery(term) : new TermQuery(term, context);
+ }
+ }
}
\ No newline at end of file