You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/09/22 05:55:24 UTC
[01/11] lucenenet git commit: BUG:
Lucene.Net.Support.StringExtensions.TrimEnd(): Fixed logic to correctly trim
all of the elements if they are empty
Repository: lucenenet
Updated Branches:
refs/heads/master caa61a37d -> 2368a020d
BUG: Lucene.Net.Support.StringExtensions.TrimEnd(): Fixed logic to correctly trim all of the elements if they are empty
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/713a645f
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/713a645f
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/713a645f
Branch: refs/heads/master
Commit: 713a645f8ff416e269ddaa4af3dc6697a0f0e0e1
Parents: a57d9f1
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Sep 19 20:15:44 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 03:06:02 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net/Support/StringExtensions.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/713a645f/src/Lucene.Net/Support/StringExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/StringExtensions.cs b/src/Lucene.Net/Support/StringExtensions.cs
index c051a60..8f99970 100644
--- a/src/Lucene.Net/Support/StringExtensions.cs
+++ b/src/Lucene.Net/Support/StringExtensions.cs
@@ -153,7 +153,7 @@ namespace Lucene.Net.Support
if (!string.IsNullOrEmpty(input[lastElement]))
break;
}
- if (lastElement > 0 && lastElement < input.Length)
+ if (lastElement >= -1 && lastElement < input.Length)
{
int end = lastElement + 1;
string[] result = new string[end];
[08/11] lucenenet git commit: Lucene.Net.Codecs.Sep: Did a fresh port
of SepSkipListReader and SepSkipListWriter
Posted by ni...@apache.org.
Lucene.Net.Codecs.Sep: Did a fresh port of SepSkipListReader and SepSkipListWriter
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ffaa021f
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ffaa021f
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ffaa021f
Branch: refs/heads/master
Commit: ffaa021f062c848b3faee69810c58514ac6059e9
Parents: 7ae81ef
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Sep 22 00:03:58 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 12:45:44 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs | 203 +++++++++++---------
src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs | 173 +++++++++--------
2 files changed, 196 insertions(+), 180 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ffaa021f/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs b/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
index 5cc9df4..9cb4574 100644
--- a/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
+++ b/src/Lucene.Net.Codecs/Sep/SepSkipListReader.cs
@@ -32,171 +32,184 @@ namespace Lucene.Net.Codecs.Sep
// TODO: rewrite this as recursive classes?
internal class SepSkipListReader : MultiLevelSkipListReader
{
- private bool _currentFieldStoresPayloads;
- private readonly Int32IndexInput.Index[] _freqIndex;
- private readonly Int32IndexInput.Index[] _docIndex;
- private readonly Int32IndexInput.Index[] _posIndex;
- private readonly long[] _payloadPointer;
- private readonly int[] _payloadLength;
-
- private readonly Int32IndexInput.Index _lastFreqIndex;
- private readonly Int32IndexInput.Index _lastDocIndex;
- private readonly Int32IndexInput.Index _lastPosIndex;
-
- private long _lastPayloadPointer;
- private int _lastPayloadLength;
-
- internal SepSkipListReader(IndexInput skipStream, Int32IndexInput freqIn, Int32IndexInput docIn, Int32IndexInput posIn,
- int maxSkipLevels, int skipInterval)
+ private bool currentFieldStoresPayloads;
+ private Int32IndexInput.Index[] freqIndex;
+ private Int32IndexInput.Index[] docIndex;
+ private Int32IndexInput.Index[] posIndex;
+ private long[] payloadPointer;
+ private int[] payloadLength;
+
+ private readonly Int32IndexInput.Index lastFreqIndex;
+ private readonly Int32IndexInput.Index lastDocIndex;
+ // TODO: -- make private again
+ internal readonly Int32IndexInput.Index lastPosIndex;
+
+ private long lastPayloadPointer;
+ private int lastPayloadLength;
+
+ /// <exception cref="System.IO.IOException"/>
+ internal SepSkipListReader(IndexInput skipStream,
+ Int32IndexInput freqIn,
+ Int32IndexInput docIn,
+ Int32IndexInput posIn,
+ int maxSkipLevels,
+ int skipInterval)
: base(skipStream, maxSkipLevels, skipInterval)
{
if (freqIn != null)
{
- _freqIndex = new Int32IndexInput.Index[maxSkipLevels];
+ freqIndex = new Int32IndexInput.Index[maxSkipLevels];
}
- _docIndex = new Int32IndexInput.Index[maxSkipLevels];
+ docIndex = new Int32IndexInput.Index[maxSkipLevels];
if (posIn != null)
{
- _posIndex = new Int32IndexInput.Index[m_maxNumberOfSkipLevels];
+ posIndex = new Int32IndexInput.Index[m_maxNumberOfSkipLevels];
}
-
- for (var i = 0; i < maxSkipLevels; i++)
+ for (int i = 0; i < maxSkipLevels; i++)
{
if (freqIn != null)
{
- _freqIndex[i] = freqIn.GetIndex();
+ freqIndex[i] = freqIn.GetIndex();
}
-
- _docIndex[i] = docIn.GetIndex();
-
+ docIndex[i] = docIn.GetIndex();
if (posIn != null)
{
- _posIndex[i] = posIn.GetIndex();
+ posIndex[i] = posIn.GetIndex();
}
}
+ payloadPointer = new long[maxSkipLevels];
+ payloadLength = new int[maxSkipLevels];
- _payloadPointer = new long[maxSkipLevels];
- _payloadLength = new int[maxSkipLevels];
-
- _lastFreqIndex = freqIn != null ? freqIn.GetIndex() : null;
- _lastDocIndex = docIn.GetIndex();
- _lastPosIndex = posIn != null ? posIn.GetIndex() : null;
+ if (freqIn != null)
+ {
+ lastFreqIndex = freqIn.GetIndex();
+ }
+ else
+ {
+ lastFreqIndex = null;
+ }
+ lastDocIndex = docIn.GetIndex();
+ if (posIn != null)
+ {
+ lastPosIndex = posIn.GetIndex();
+ }
+ else
+ {
+ lastPosIndex = null;
+ }
}
- private IndexOptions _indexOptions;
+ internal IndexOptions indexOptions;
- internal virtual void SetIndexOptions(IndexOptions v)
+ internal void SetIndexOptions(IndexOptions v)
{
- _indexOptions = v;
+ indexOptions = v;
}
- internal virtual void Init(long skipPointer,
- Int32IndexInput.Index docBaseIndex,
- Int32IndexInput.Index freqBaseIndex,
- Int32IndexInput.Index posBaseIndex,
- long payloadBasePointer,
- int df,
- bool storesPayloads)
+ internal void Init(long skipPointer,
+ Int32IndexInput.Index docBaseIndex,
+ Int32IndexInput.Index freqBaseIndex,
+ Int32IndexInput.Index posBaseIndex,
+ long payloadBasePointer,
+ int df,
+ bool storesPayloads)
{
+
base.Init(skipPointer, df);
- this._currentFieldStoresPayloads = storesPayloads;
+ this.currentFieldStoresPayloads = storesPayloads;
- _lastPayloadPointer = payloadBasePointer;
+ lastPayloadPointer = payloadBasePointer;
- for (var i = 0; i < m_maxNumberOfSkipLevels; i++)
+ for (int i = 0; i < m_maxNumberOfSkipLevels; i++)
{
- _docIndex[i].CopyFrom(docBaseIndex);
- if (_freqIndex != null)
+ docIndex[i].CopyFrom(docBaseIndex);
+ if (freqIndex != null)
{
- _freqIndex[i].CopyFrom(freqBaseIndex);
+ freqIndex[i].CopyFrom(freqBaseIndex);
}
if (posBaseIndex != null)
{
- _posIndex[i].CopyFrom(posBaseIndex);
+ posIndex[i].CopyFrom(posBaseIndex);
}
}
- Arrays.Fill(_payloadPointer, payloadBasePointer);
- Arrays.Fill(_payloadLength, 0);
+ Arrays.Fill(payloadPointer, payloadBasePointer);
+ Arrays.Fill(payloadLength, 0);
}
- internal virtual long PayloadPointer
+ internal long PayloadPointer
{
- get { return _lastPayloadPointer; }
+ get { return lastPayloadPointer; }
}
/// <summary>
/// Returns the payload length of the payload stored just before
/// the doc to which the last call of <see cref="MultiLevelSkipListReader.SkipTo(int)"/>
- /// has skipped.
+ /// has skipped.
/// </summary>
- internal virtual int PayloadLength
+ internal int PayloadLength
{
- get { return _lastPayloadLength; }
+ get { return lastPayloadLength; }
}
+ /// <exception cref="System.IO.IOException"/>
protected override void SeekChild(int level)
{
base.SeekChild(level);
- _payloadPointer[level] = _lastPayloadPointer;
- _payloadLength[level] = _lastPayloadLength;
+ payloadPointer[level] = lastPayloadPointer;
+ payloadLength[level] = lastPayloadLength;
}
protected override void SetLastSkipData(int level)
{
base.SetLastSkipData(level);
- _lastPayloadPointer = _payloadPointer[level];
- _lastPayloadLength = _payloadLength[level];
-
- if (_freqIndex != null)
+ lastPayloadPointer = payloadPointer[level];
+ lastPayloadLength = payloadLength[level];
+ if (freqIndex != null)
{
- _lastFreqIndex.CopyFrom(_freqIndex[level]);
+ lastFreqIndex.CopyFrom(freqIndex[level]);
}
-
- _lastDocIndex.CopyFrom(_docIndex[level]);
-
- if (_lastPosIndex != null)
+ lastDocIndex.CopyFrom(docIndex[level]);
+ if (lastPosIndex != null)
{
- _lastPosIndex.CopyFrom(_posIndex[level]);
+ lastPosIndex.CopyFrom(posIndex[level]);
}
if (level > 0)
{
- if (_freqIndex != null)
+ if (freqIndex != null)
{
- _freqIndex[level - 1].CopyFrom(_freqIndex[level]);
+ freqIndex[level - 1].CopyFrom(freqIndex[level]);
}
-
- _docIndex[level - 1].CopyFrom(_docIndex[level]);
-
- if (_posIndex != null)
+ docIndex[level - 1].CopyFrom(docIndex[level]);
+ if (posIndex != null)
{
- _posIndex[level - 1].CopyFrom(_posIndex[level]);
+ posIndex[level - 1].CopyFrom(posIndex[level]);
}
}
}
- internal virtual Int32IndexInput.Index FreqIndex
+ internal Int32IndexInput.Index FreqIndex
{
- get { return _lastFreqIndex; }
+ get { return lastFreqIndex; }
}
- internal virtual Int32IndexInput.Index PosIndex
+ internal Int32IndexInput.Index PosIndex
{
- get { return _lastPosIndex; }
+ get { return lastPosIndex; }
}
- internal virtual Int32IndexInput.Index DocIndex
+ internal Int32IndexInput.Index DocIndex
{
- get { return _lastDocIndex; }
+ get { return lastDocIndex; }
}
+ /// <exception cref="System.IO.IOException"/>
protected override int ReadSkipData(int level, IndexInput skipStream)
{
int delta;
- Debug.Assert(_indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS ||
- !_currentFieldStoresPayloads);
- if (_currentFieldStoresPayloads)
+ Debug.Assert(indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !currentFieldStoresPayloads);
+ if (currentFieldStoresPayloads)
{
// the current field stores payloads.
// if the doc delta is odd then we have
@@ -206,28 +219,26 @@ namespace Lucene.Net.Codecs.Sep
delta = skipStream.ReadVInt32();
if ((delta & 1) != 0)
{
- _payloadLength[level] = skipStream.ReadVInt32();
+ payloadLength[level] = skipStream.ReadVInt32();
}
- delta = (int) ((uint) delta >> 1);
+ //delta >>>= 1;
+ delta = (int)((uint)delta >> 1);
}
else
{
delta = skipStream.ReadVInt32();
}
-
- if (_indexOptions != IndexOptions.DOCS_ONLY)
+ if (indexOptions != IndexOptions.DOCS_ONLY)
{
- _freqIndex[level].Read(skipStream, false);
+ freqIndex[level].Read(skipStream, false);
}
-
- _docIndex[level].Read(skipStream, false);
- if (_indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
+ docIndex[level].Read(skipStream, false);
+ if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
{
- _posIndex[level].Read(skipStream, false);
-
- if (_currentFieldStoresPayloads)
+ posIndex[level].Read(skipStream, false);
+ if (currentFieldStoresPayloads)
{
- _payloadPointer[level] += skipStream.ReadVInt32();
+ payloadPointer[level] += skipStream.ReadVInt32();
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ffaa021f/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs b/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
index 5d3acb5..703b98d 100644
--- a/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
+++ b/src/Lucene.Net.Codecs/Sep/SepSkipListWriter.cs
@@ -33,121 +33,126 @@ namespace Lucene.Net.Codecs.Sep
/// </summary>
internal class SepSkipListWriter : MultiLevelSkipListWriter
{
- private readonly int[] _lastSkipDoc;
- private readonly int[] _lastSkipPayloadLength;
- private readonly long[] _lastSkipPayloadPointer;
-
- private readonly Int32IndexOutput.Index[] _docIndex;
- private readonly Int32IndexOutput.Index[] _freqIndex;
- private readonly Int32IndexOutput.Index[] _posIndex;
-
- private readonly Int32IndexOutput _freqOutput;
- private Int32IndexOutput _posOutput;
- private IndexOutput _payloadOutput;
-
- private int _curDoc;
- private bool _curStorePayloads;
- private int _curPayloadLength;
- private long _curPayloadPointer;
-
- internal SepSkipListWriter(int skipInterval, int numberOfSkipLevels, int docCount,
- Int32IndexOutput freqOutput,
- Int32IndexOutput docOutput,
- Int32IndexOutput posOutput,
- IndexOutput payloadOutput)
+ private int[] lastSkipDoc;
+ private int[] lastSkipPayloadLength;
+ private long[] lastSkipPayloadPointer;
+
+ private Int32IndexOutput.Index[] docIndex;
+ private Int32IndexOutput.Index[] freqIndex;
+ private Int32IndexOutput.Index[] posIndex;
+
+ private Int32IndexOutput freqOutput;
+ // TODO: -- private again
+ internal Int32IndexOutput posOutput;
+ // TODO: -- private again
+ internal IndexOutput payloadOutput;
+
+ private int curDoc;
+ private bool curStorePayloads;
+ private int curPayloadLength;
+ private long curPayloadPointer;
+
+ /// <exception cref="System.IO.IOException"/>
+ internal SepSkipListWriter(int skipInterval, int numberOfSkipLevels, int docCount,
+ Int32IndexOutput freqOutput,
+ Int32IndexOutput docOutput,
+ Int32IndexOutput posOutput,
+ IndexOutput payloadOutput)
: base(skipInterval, numberOfSkipLevels, docCount)
{
- this._freqOutput = freqOutput;
- this._posOutput = posOutput;
- this._payloadOutput = payloadOutput;
- _lastSkipDoc = new int[numberOfSkipLevels];
- _lastSkipPayloadLength = new int[numberOfSkipLevels];
+ this.freqOutput = freqOutput;
+ this.posOutput = posOutput;
+ this.payloadOutput = payloadOutput;
+
+ lastSkipDoc = new int[numberOfSkipLevels];
+ lastSkipPayloadLength = new int[numberOfSkipLevels];
// TODO: -- also cutover normal IndexOutput to use getIndex()?
- _lastSkipPayloadPointer = new long[numberOfSkipLevels];
+ lastSkipPayloadPointer = new long[numberOfSkipLevels];
- _freqIndex = new Int32IndexOutput.Index[numberOfSkipLevels];
- _docIndex = new Int32IndexOutput.Index[numberOfSkipLevels];
- _posIndex = new Int32IndexOutput.Index[numberOfSkipLevels];
+ freqIndex = new Int32IndexOutput.Index[numberOfSkipLevels];
+ docIndex = new Int32IndexOutput.Index[numberOfSkipLevels];
+ posIndex = new Int32IndexOutput.Index[numberOfSkipLevels];
- for (var i = 0; i < numberOfSkipLevels; i++)
+ for (int i = 0; i < numberOfSkipLevels; i++)
{
if (freqOutput != null)
{
- _freqIndex[i] = freqOutput.GetIndex();
+ freqIndex[i] = freqOutput.GetIndex();
}
- _docIndex[i] = docOutput.GetIndex();
+ docIndex[i] = docOutput.GetIndex();
if (posOutput != null)
{
- _posIndex[i] = posOutput.GetIndex();
+ posIndex[i] = posOutput.GetIndex();
}
}
}
- private IndexOptions _indexOptions;
+ IndexOptions indexOptions;
- internal virtual void SetIndexOptions(IndexOptions v)
+ internal void SetIndexOptions(IndexOptions v)
{
- _indexOptions = v;
+ indexOptions = v;
}
- internal virtual void SetPosOutput(Int32IndexOutput posOutput)
+ /// <exception cref="System.IO.IOException"/>
+ internal void SetPosOutput(Int32IndexOutput posOutput)
{
- _posOutput = posOutput;
- for (var i = 0; i < m_numberOfSkipLevels; i++)
+ this.posOutput = posOutput;
+ for (int i = 0; i < m_numberOfSkipLevels; i++)
{
- _posIndex[i] = posOutput.GetIndex();
+ posIndex[i] = posOutput.GetIndex();
}
}
- internal virtual void SetPayloadOutput(IndexOutput payloadOutput)
+ internal void SetPayloadOutput(IndexOutput payloadOutput)
{
- _payloadOutput = payloadOutput;
+ this.payloadOutput = payloadOutput;
}
/// <summary>
/// Sets the values for the current skip data.
- /// Called @ every index interval (every 128th (by default) doc).
/// </summary>
- internal virtual void SetSkipData(int doc, bool storePayloads, int payloadLength)
+ // Called @ every index interval (every 128th (by default)
+ // doc)
+ internal void SetSkipData(int doc, bool storePayloads, int payloadLength)
{
- this._curDoc = doc;
- this._curStorePayloads = storePayloads;
- this._curPayloadLength = payloadLength;
- if (_payloadOutput != null)
+ this.curDoc = doc;
+ this.curStorePayloads = storePayloads;
+ this.curPayloadLength = payloadLength;
+ if (payloadOutput != null)
{
- _curPayloadPointer = _payloadOutput.GetFilePointer();
+ this.curPayloadPointer = payloadOutput.GetFilePointer();
}
}
- /// <summary>
- /// Called @ start of new term.
- /// </summary>
- protected internal virtual void ResetSkip(Int32IndexOutput.Index topDocIndex, Int32IndexOutput.Index topFreqIndex,
- Int32IndexOutput.Index topPosIndex)
+ // Called @ start of new term
+ /// <exception cref="System.IO.IOException"/>
+ protected internal void ResetSkip(Int32IndexOutput.Index topDocIndex, Int32IndexOutput.Index topFreqIndex, Int32IndexOutput.Index topPosIndex)
{
base.ResetSkip();
- Arrays.Fill(_lastSkipDoc, 0);
- Arrays.Fill(_lastSkipPayloadLength, -1); // we don't have to write the first length in the skip list
+ Arrays.Fill(lastSkipDoc, 0);
+ Arrays.Fill(lastSkipPayloadLength, -1); // we don't have to write the first length in the skip list
for (int i = 0; i < m_numberOfSkipLevels; i++)
{
- _docIndex[i].CopyFrom(topDocIndex, true);
- if (_freqOutput != null)
+ docIndex[i].CopyFrom(topDocIndex, true);
+ if (freqOutput != null)
{
- _freqIndex[i].CopyFrom(topFreqIndex, true);
+ freqIndex[i].CopyFrom(topFreqIndex, true);
}
- if (_posOutput != null)
+ if (posOutput != null)
{
- _posIndex[i].CopyFrom(topPosIndex, true);
+ posIndex[i].CopyFrom(topPosIndex, true);
}
}
- if (_payloadOutput != null)
+ if (payloadOutput != null)
{
- Arrays.Fill(_lastSkipPayloadPointer, _payloadOutput.GetFilePointer());
+ Arrays.Fill(lastSkipPayloadPointer, payloadOutput.GetFilePointer());
}
}
+ /// <exception cref="System.IO.IOException"/>
protected override void WriteSkipData(int level, IndexOutput skipBuffer)
{
// To efficiently store payloads in the posting lists we do not store the length of
@@ -171,12 +176,12 @@ namespace Lucene.Net.Codecs.Sep
// current payload length equals the length at the previous
// skip point
- Debug.Assert(_indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !_curStorePayloads);
+ Debug.Assert(indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS || !curStorePayloads);
- if (_curStorePayloads)
+ if (curStorePayloads)
{
- int delta = _curDoc - _lastSkipDoc[level];
- if (_curPayloadLength == _lastSkipPayloadLength[level])
+ int delta = curDoc - lastSkipDoc[level];
+ if (curPayloadLength == lastSkipPayloadLength[level])
{
// the current payload length equals the length at the previous skip point,
// so we don't store the length again
@@ -187,35 +192,35 @@ namespace Lucene.Net.Codecs.Sep
// the payload length is different from the previous one. We shift the DocSkip,
// set the lowest bit and store the current payload length as VInt.
skipBuffer.WriteVInt32(delta << 1 | 1);
- skipBuffer.WriteVInt32(_curPayloadLength);
- _lastSkipPayloadLength[level] = _curPayloadLength;
+ skipBuffer.WriteVInt32(curPayloadLength);
+ lastSkipPayloadLength[level] = curPayloadLength;
}
}
else
{
// current field does not store payloads
- skipBuffer.WriteVInt32(_curDoc - _lastSkipDoc[level]);
+ skipBuffer.WriteVInt32(curDoc - lastSkipDoc[level]);
}
- if (_indexOptions != IndexOptions.DOCS_ONLY)
+ if (indexOptions != IndexOptions.DOCS_ONLY)
{
- _freqIndex[level].Mark();
- _freqIndex[level].Write(skipBuffer, false);
+ freqIndex[level].Mark();
+ freqIndex[level].Write(skipBuffer, false);
}
- _docIndex[level].Mark();
- _docIndex[level].Write(skipBuffer, false);
- if (_indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
+ docIndex[level].Mark();
+ docIndex[level].Write(skipBuffer, false);
+ if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
{
- _posIndex[level].Mark();
- _posIndex[level].Write(skipBuffer, false);
- if (_curStorePayloads)
+ posIndex[level].Mark();
+ posIndex[level].Write(skipBuffer, false);
+ if (curStorePayloads)
{
- skipBuffer.WriteVInt32((int)(_curPayloadPointer - _lastSkipPayloadPointer[level]));
+ skipBuffer.WriteVInt32((int)(curPayloadPointer - lastSkipPayloadPointer[level]));
}
}
- _lastSkipDoc[level] = _curDoc;
- _lastSkipPayloadPointer[level] = _curPayloadPointer;
+ lastSkipDoc[level] = curDoc;
+ lastSkipPayloadPointer[level] = curPayloadPointer;
}
}
}
\ No newline at end of file
[03/11] lucenenet git commit: SWEEP: Added TimeZoneInfo.ConvertTime()
to corresponding locations where time zone had been set in Lucene.
Posted by ni...@apache.org.
SWEEP: Added TimeZoneInfo.ConvertTime() to corresponding locations where time zone had been set in Lucene.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/9c66bd18
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/9c66bd18
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/9c66bd18
Branch: refs/heads/master
Commit: 9c66bd185bda096c4b3ee0c15daedfe946049672
Parents: fe8add7
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Sep 19 21:55:00 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 03:06:03 2017 +0700
----------------------------------------------------------------------
.../Util/TestRuleSetupAndRestoreClassEnv.cs | 2 --
src/Lucene.Net.Tests.Queries/ChainedFilterTest.cs | 3 ++-
.../Flexible/Standard/TestQPHelper.cs | 5 +++--
3 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9c66bd18/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
index 4f6d36e..08e9fc8 100644
--- a/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
+++ b/src/Lucene.Net.TestFramework/Util/TestRuleSetupAndRestoreClassEnv.cs
@@ -269,8 +269,6 @@ namespace Lucene.Net.Util
timeZone = testTimeZone.Equals("random", StringComparison.Ordinal) ? randomTimeZone : TimeZoneInfo.FindSystemTimeZoneById(testTimeZone);
//TimeZone.Default = TimeZone; // LUCENENET NOTE: There doesn't seem to be an equivalent to this, but I don't think we need it.
- //TimeZoneInfo.ConvertTime() // LUCENENET TODO: Everywhere TimeZoneInfo is supposed to be used, use this method to convert a dateTime object to the time zone
-
similarity = random.NextBoolean() ? (Similarity)new DefaultSimilarity() : new RandomSimilarityProvider(random);
// Check codec restrictions once at class level.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9c66bd18/src/Lucene.Net.Tests.Queries/ChainedFilterTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Queries/ChainedFilterTest.cs b/src/Lucene.Net.Tests.Queries/ChainedFilterTest.cs
index 914b3e0..7cb1a89 100644
--- a/src/Lucene.Net.Tests.Queries/ChainedFilterTest.cs
+++ b/src/Lucene.Net.Tests.Queries/ChainedFilterTest.cs
@@ -51,7 +51,8 @@ namespace Lucene.Net.Tests.Queries
directory = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, Similarity, TimeZone);
// we use the default Locale/TZ since LuceneTestCase randomizes it
- var cal = new GregorianCalendar().ToDateTime(1970, 1, 1, 0, 0, 0, (int)TestUtil.NextLong(Random(), 0, long.MaxValue));
+ var cal = new GregorianCalendar().ToDateTime(2003, 1, 1, 0, 0, 0, 0); // 2003 January 01
+ cal = TimeZoneInfo.ConvertTime(cal, TimeZoneInfo.Local);
for (int i = 0; i < Max; i++)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/9c66bd18/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestQPHelper.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestQPHelper.cs b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestQPHelper.cs
index 8f48fc5..3fb4953 100644
--- a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestQPHelper.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestQPHelper.cs
@@ -764,8 +764,9 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard
private String GetLocalizedDate(int year, int month, int day)
{
- DateTime d = new DateTime(year, month, day, 23, 59, 59, 999);
- return d.ToString("d"); //.ToShortDateString();
+ DateTime date = new GregorianCalendar().ToDateTime(year, month, day, 23, 59, 59, 999);
+ date = TimeZoneInfo.ConvertTime(date, TimeZoneInfo.Local);
+ return date.ToString("d"); //.ToShortDateString();
//// we use the default Locale/TZ since LuceneTestCase randomizes it
//DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
[11/11] lucenenet git commit: Lucene.Net.Tests.Support: Added
TestStringExtensions class and TestTrimEnd() test
Posted by ni...@apache.org.
Lucene.Net.Tests.Support: Added TestStringExtensions class and TestTrimEnd() test
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/2368a020
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/2368a020
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/2368a020
Branch: refs/heads/master
Commit: 2368a020d1f140ff8be983a08d8b5f9504d67322
Parents: 302a51e
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Sep 22 01:20:13 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 12:45:45 2017 +0700
----------------------------------------------------------------------
.../Support/TestStringExtensions.cs | 59 ++++++++++++++++++++
1 file changed, 59 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2368a020/src/Lucene.Net.Tests/Support/TestStringExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/TestStringExtensions.cs b/src/Lucene.Net.Tests/Support/TestStringExtensions.cs
new file mode 100644
index 0000000..5ea5801
--- /dev/null
+++ b/src/Lucene.Net.Tests/Support/TestStringExtensions.cs
@@ -0,0 +1,59 @@
+using NUnit.Framework;
+
+namespace Lucene.Net.Support
+{
+ /*
+ * 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.
+ */
+
+ public class TestStringExtensions
+ {
+ [Test]
+ public void TestTrimEnd()
+ {
+ // Zero length
+ CollectionAssert.AreEqual(new string[0], new string[0].TrimEnd());
+ CollectionAssert.AreEqual(new string[0], new string[] { "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[0], new string[] { "", "" }.TrimEnd());
+
+ CollectionAssert.AreEqual(new string[0], new string[] { "", "", null }.TrimEnd());
+ CollectionAssert.AreEqual(new string[0], new string[] { null }.TrimEnd());
+ CollectionAssert.AreEqual(new string[0], new string[] { null, null }.TrimEnd());
+
+ // End trimming
+ CollectionAssert.AreEqual(new string[] { "foo" }, new string[] { "foo", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo" }, new string[] { "foo", "", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo" }, new string[] { "foo", "", "", "" }.TrimEnd());
+
+ CollectionAssert.AreEqual(new string[] { "foo", "bar" }, new string[] { "foo", "bar", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo", "bar" }, new string[] { "foo", "bar", "", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo", "bar" }, new string[] { "foo", "bar", "", "", "" }.TrimEnd());
+
+ // End trimming without trimming beginning or middle entries
+ CollectionAssert.AreEqual(new string[] { "", "foo" }, new string[] { "", "foo" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "", "foo", "bar" }, new string[] { "", "foo", "bar" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo", "", "bar" }, new string[] { "foo", "", "bar" }.TrimEnd());
+
+ CollectionAssert.AreEqual(new string[] { "", "foo" }, new string[] { "", "foo", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "", "foo", "bar" }, new string[] { "", "foo", "bar", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo", "", "bar" }, new string[] { "foo", "", "bar", "" }.TrimEnd());
+
+ CollectionAssert.AreEqual(new string[] { "", "foo" }, new string[] { "", "foo", "", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "", "foo", "bar" }, new string[] { "", "foo", "bar", "", "" }.TrimEnd());
+ CollectionAssert.AreEqual(new string[] { "foo", "", "bar" }, new string[] { "foo", "", "bar", "", "" }.TrimEnd());
+ }
+ }
+}
[06/11] lucenenet git commit: BUG: Lucene.Net.Store.MMapDirectory:
Fixed issue with FileStream not being disposed when the file length is 0.
Posted by ni...@apache.org.
BUG: Lucene.Net.Store.MMapDirectory: Fixed issue with FileStream not being disposed when the file length is 0.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/8ab834f3
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/8ab834f3
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/8ab834f3
Branch: refs/heads/master
Commit: 8ab834f3525aa55af334c10b9a5dfa1a759ec44a
Parents: 9c66bd1
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Thu Sep 21 23:24:12 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 12:45:18 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Tests/Store/TestMultiMMap.cs | 21 ++++++++++++
src/Lucene.Net/Store/MMapDirectory.cs | 42 ++++++++++++++++--------
2 files changed, 49 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8ab834f3/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Store/TestMultiMMap.cs b/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
index 81aa60b..00c18d0 100644
--- a/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
+++ b/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
@@ -3,6 +3,7 @@ using Lucene.Net.Support;
using NUnit.Framework;
using System;
using System.IO;
+using System.Text;
namespace Lucene.Net.Store
{
@@ -435,5 +436,25 @@ namespace Lucene.Net.Store
reader.Dispose();
dir.Dispose();
}
+
+
+ [Test, LuceneNetSpecific]
+ public void TestDisposeIndexInput()
+ {
+ string name = "foobar";
+ var dir = CreateTempDir("testDisposeIndexInput");
+ string fileName = Path.Combine(dir.FullName, name);
+
+ // Create a zero byte file, and close it immediately
+ File.WriteAllText(fileName, string.Empty, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false) /* No BOM */);
+
+ MMapDirectory mmapDir = new MMapDirectory(dir);
+ using (var indexInput = mmapDir.OpenInput(name, NewIOContext(Random())))
+ {
+ } // Dispose
+
+ // Now it should be possible to delete the file. This is the condition we are testing for.
+ File.Delete(fileName);
+ }
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/8ab834f3/src/Lucene.Net/Store/MMapDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/MMapDirectory.cs b/src/Lucene.Net/Store/MMapDirectory.cs
index b116b90..cb2dc0b 100644
--- a/src/Lucene.Net/Store/MMapDirectory.cs
+++ b/src/Lucene.Net/Store/MMapDirectory.cs
@@ -220,16 +220,13 @@ namespace Lucene.Net.Store
{
EnsureOpen();
var file = new FileInfo(Path.Combine(Directory.FullName, name));
-
- var c = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
-
- return new MMapIndexInput(this, "MMapIndexInput(path=\"" + file + "\")", c);
+ var fc = new FileStream(file.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ return new MMapIndexInput(this, "MMapIndexInput(path=\"" + file + "\")", fc);
}
public override IndexInputSlicer CreateSlicer(string name, IOContext context)
{
var full = (MMapIndexInput)OpenInput(name, context);
-
return new IndexInputSlicerAnonymousInnerClassHelper(this, full);
}
@@ -269,30 +266,47 @@ namespace Lucene.Net.Store
public sealed class MMapIndexInput : ByteBufferIndexInput
{
- private readonly bool useUnmapHack;
+ //private readonly bool useUnmapHack;
//private string mapName; // LUCENENET NOTE: Not used
internal MemoryMappedFile memoryMappedFile; // .NET port: this is equivalent to FileChannel.map
+ private readonly FileStream fc;
private readonly MMapDirectory outerInstance;
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc)
: base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, outerInstance.UseUnmap)
{
this.outerInstance = outerInstance;
- this.useUnmapHack = outerInstance.UseUnmap;
+ this.fc = fc ?? throw new ArgumentNullException("fc");
+ //this.useUnmapHack = outerInstance.UseUnmap;
this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length));
}
- protected override /*sealed*/ void Dispose(bool disposing) // LUCENENET specific - not marked sealed in case subclass needs to dispose
+ protected override sealed void Dispose(bool disposing)
{
- if (disposing)
+ try
{
- if (null != this.memoryMappedFile)
+ if (disposing)
{
- this.memoryMappedFile.Dispose();
- this.memoryMappedFile = null;
+ try
+ {
+ if (this.memoryMappedFile != null)
+ {
+ this.memoryMappedFile.Dispose();
+ this.memoryMappedFile = null;
+ }
+ }
+ finally
+ {
+ // LUCENENET: If the file is 0 length we will not create a memoryMappedFile above
+ // so we must always ensure the FileStream is explicitly disposed.
+ this.fc.Dispose();
+ }
}
}
- base.Dispose(disposing);
+ finally
+ {
+ base.Dispose(disposing);
+ }
}
/// <summary>
@@ -344,7 +358,7 @@ namespace Lucene.Net.Store
memoryMappedFileSecurity: null,
#endif
inheritability: HandleInheritability.Inheritable,
- leaveOpen: false);
+ leaveOpen: true); // LUCENENET: We explicitly dispose the FileStream separately.
}
long bufferStart = 0L;
[05/11] lucenenet git commit: BREAKING: Lucene.Net.MMapDirectory:
Removed UnmapHack/UNMAP_SUPPORTED features since these are not needed in
.NET.
Posted by ni...@apache.org.
BREAKING: Lucene.Net.MMapDirectory: Removed UnmapHack/UNMAP_SUPPORTED features since these are not needed in .NET.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/7ae81efe
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/7ae81efe
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/7ae81efe
Branch: refs/heads/master
Commit: 7ae81efe2ab898932cabda9820011b76b4259760
Parents: 8ab834f
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Sep 22 12:02:51 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 12:45:18 2017 +0700
----------------------------------------------------------------------
src/Lucene.Net.Tests/Store/TestDirectory.cs | 11 +++---
src/Lucene.Net.Tests/Store/TestMultiMMap.cs | 11 +++---
src/Lucene.Net/Store/FSDirectory.cs | 4 +--
src/Lucene.Net/Store/MMapDirectory.cs | 44 +++---------------------
4 files changed, 18 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net.Tests/Store/TestDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Store/TestDirectory.cs b/src/Lucene.Net.Tests/Store/TestDirectory.cs
index 407e38c..9d514c1 100644
--- a/src/Lucene.Net.Tests/Store/TestDirectory.cs
+++ b/src/Lucene.Net.Tests/Store/TestDirectory.cs
@@ -213,11 +213,12 @@ namespace Lucene.Net.Store
Assert.IsTrue(SlowFileExists(d2, fname));
Assert.AreEqual(1 + largeBuffer.Length, d2.FileLength(fname));
- // don't do read tests if unmapping is not supported!
- if (d2 is MMapDirectory && !((MMapDirectory)d2).UseUnmap)
- {
- continue;
- }
+ // LUCENENET specific - unmap hack not needed
+ //// don't do read tests if unmapping is not supported!
+ //if (d2 is MMapDirectory && !((MMapDirectory)d2).UseUnmap)
+ //{
+ // continue;
+ //}
IndexInput input = d2.OpenInput(fname, NewIOContext(Random()));
Assert.AreEqual((byte)i, input.ReadByte());
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Store/TestMultiMMap.cs b/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
index 00c18d0..3dcb59d 100644
--- a/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
+++ b/src/Lucene.Net.Tests/Store/TestMultiMMap.cs
@@ -404,11 +404,12 @@ namespace Lucene.Net.Store
{
DirectoryInfo path = CreateTempDir("mmap" + chunkSize);
MMapDirectory mmapDir = new MMapDirectory(path, null, chunkSize);
- // we will map a lot, try to turn on the unmap hack
- if (MMapDirectory.UNMAP_SUPPORTED)
- {
- mmapDir.UseUnmap = true;
- }
+ // LUCENENET specific - unmap hack not needed
+ //// we will map a lot, try to turn on the unmap hack
+ //if (MMapDirectory.UNMAP_SUPPORTED)
+ //{
+ // mmapDir.UseUnmap = true;
+ //}
MockDirectoryWrapper dir = new MockDirectoryWrapper(random, mmapDir);
RandomIndexWriter writer = new RandomIndexWriter(random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).SetMergePolicy(NewLogMergePolicy()));
Document doc = new Document();
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net/Store/FSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/FSDirectory.cs b/src/Lucene.Net/Store/FSDirectory.cs
index 8c65d9c..4c408ae 100644
--- a/src/Lucene.Net/Store/FSDirectory.cs
+++ b/src/Lucene.Net/Store/FSDirectory.cs
@@ -172,8 +172,8 @@ namespace Lucene.Net.Store
/// </summary>
public static FSDirectory Open(DirectoryInfo path, LockFactory lockFactory)
{
- if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.RUNTIME_IS_64BIT &&
- MMapDirectory.UNMAP_SUPPORTED)
+ if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX) && Constants.RUNTIME_IS_64BIT /*&&
+ MMapDirectory.UNMAP_SUPPORTED*/) // LUCENENET specific - unmap hack not needed
{
return new MMapDirectory(path, lockFactory);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/7ae81efe/src/Lucene.Net/Store/MMapDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/MMapDirectory.cs b/src/Lucene.Net/Store/MMapDirectory.cs
index cb2dc0b..68cbaee 100644
--- a/src/Lucene.Net/Store/MMapDirectory.cs
+++ b/src/Lucene.Net/Store/MMapDirectory.cs
@@ -51,7 +51,7 @@ namespace Lucene.Net.Store
/// </summary>
public class MMapDirectory : FSDirectory
{
- private bool useUnmapHack = UNMAP_SUPPORTED;
+ // LUCENENET specific - unmap hack not needed
/// <summary>
/// Default max chunk size. </summary>
@@ -166,42 +166,9 @@ namespace Lucene.Net.Store
{
}
- /// <summary>
- /// <c>true</c>, if this platform supports unmapping mmapped files.
- /// </summary>
- // LUCENENET NOTE: Some JREs had a bug that didn't allow them to unmap.
+ // LUCENENET specific - Some JREs had a bug that didn't allow them to unmap.
// But according to MSDN, the MemoryMappedFile.Dispose() method will
- // indeed "release all resources".
- public static readonly bool UNMAP_SUPPORTED = true;
-
- // LUCENENET specific: No need for static constructor, since unmap is always supported
-
- /// <summary>
- /// This property enables the workaround for unmapping the buffers
- /// from address space after closing <see cref="IndexInput"/>, that is
- /// mentioned in the bug report. This hack may fail on non-Sun JVMs.
- /// It forcefully unmaps the buffer on close by using
- /// an undocumented internal cleanup functionality.
- /// <para/><b>NOTE:</b> Enabling this is completely unsupported
- /// by Java and may lead to JVM crashes if <see cref="IndexInput"/>
- /// is closed while another thread is still accessing it (SIGSEGV). </summary>
- /// <exception cref="ArgumentException"> if <see cref="UNMAP_SUPPORTED"/>
- /// is <c>false</c> and the workaround cannot be enabled. </exception>
- public virtual bool UseUnmap
- {
- set
- {
- if (value && !UNMAP_SUPPORTED)
- {
- throw new System.ArgumentException("Unmap hack not supported on this platform!");
- }
- this.useUnmapHack = value;
- }
- get
- {
- return useUnmapHack;
- }
- }
+ // indeed "release all resources". Therefore unmap hack is not needed in .NET.
/// <summary>
/// Returns the current mmap chunk size. </summary>
@@ -266,18 +233,15 @@ namespace Lucene.Net.Store
public sealed class MMapIndexInput : ByteBufferIndexInput
{
- //private readonly bool useUnmapHack;
- //private string mapName; // LUCENENET NOTE: Not used
internal MemoryMappedFile memoryMappedFile; // .NET port: this is equivalent to FileChannel.map
private readonly FileStream fc;
private readonly MMapDirectory outerInstance;
internal MMapIndexInput(MMapDirectory outerInstance, string resourceDescription, FileStream fc)
- : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, outerInstance.UseUnmap)
+ : base(resourceDescription, null, fc.Length, outerInstance.chunkSizePower, true)
{
this.outerInstance = outerInstance;
this.fc = fc ?? throw new ArgumentNullException("fc");
- //this.useUnmapHack = outerInstance.UseUnmap;
this.SetBuffers(outerInstance.Map(this, fc, 0, fc.Length));
}
[02/11] lucenenet git commit: BUG: Patched behavior of all
implementations of String.Split() and Regex.Split() using the .TrimEnd()
extension method. In Java,
only the empty entries at the end of the array are removed,
not all empty entries.
Posted by ni...@apache.org.
BUG: Patched behavior of all implementations of String.Split() and Regex.Split() using the .TrimEnd() extension method. In Java, only the empty entries at the end of the array are removed, not all empty entries.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/a57d9f11
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/a57d9f11
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/a57d9f11
Branch: refs/heads/master
Commit: a57d9f1154b7393556493e73e4a9649d28df1f0a
Parents: caa61a3
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Sep 19 19:40:00 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 03:06:02 2017 +0700
----------------------------------------------------------------------
.../Analysis/Hunspell/Dictionary.cs | 18 +++++++++---------
.../Hunspell/HunspellStemFilterFactory.cs | 3 ++-
.../Analysis/Miscellaneous/PatternAnalyzer.cs | 4 ++--
.../Analysis/Pt/RSLPStemmerBase.cs | 2 +-
.../Analysis/Util/WordlistLoader.cs | 11 ++++++++---
.../Dict/UserDictionary.cs | 6 +++---
.../Tools/CharacterDefinitionWriter.cs | 6 +++---
.../Tools/ConnectionCostsBuilder.cs | 7 ++++---
.../Tools/UnknownDictionaryBuilder.cs | 5 +++--
.../Language/Bm/Lang.cs | 4 ++--
.../Language/Bm/PhoneticEngine.cs | 4 ++--
.../Language/Bm/Rule.cs | 6 +++---
.../Language/DaitchMokotoffSoundex.cs | 14 +++++++++-----
.../ByTask/Feeds/LineDocSource.cs | 2 +-
.../ByTask/Tasks/OpenReaderTask.cs | 2 +-
.../SimpleText/SimpleTextDocValuesReader.cs | 5 +++--
.../JS/JavascriptCompiler.cs | 2 +-
src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs | 2 +-
.../Xml/Builders/LikeThisQueryBuilder.cs | 3 ++-
.../Http/ReplicationService.cs | 3 ++-
.../IndexAndTaxonomyRevision.cs | 3 ++-
.../Analysis/VocabularyAssert.cs | 4 ++--
.../Randomized/SeedUtils.cs | 3 ++-
.../TestRemoveDuplicatesTokenFilter.cs | 2 +-
.../TestRemoveDuplicatesTokenFilterFactory.cs | 3 ++-
.../Snowball/TestSnowballPorterFilterFactory.cs | 3 ++-
.../Analysis/Synonym/TestSlowSynonymFilter.cs | 8 ++++----
.../Analysis/Synonym/TestSynonymMapFilter.cs | 12 ++++++------
.../Analysis/Util/TestCharTokenizers.cs | 2 +-
.../TestJapaneseTokenizer.cs | 3 ++-
.../TestSearchMode.cs | 7 ++++---
.../Language/Bm/BeiderMorseEncoderTest.cs | 5 +++--
.../Language/Bm/PhoneticEngineRegressionTest.cs | 2 +-
.../Language/Bm/PhoneticEngineTest.cs | 9 +++++----
.../WriterCache/TestCompactLabelToOrdinal.cs | 11 ++++++-----
.../ComplexPhrase/TestComplexPhraseQuery.cs | 3 ++-
.../Queries/TestSlowFuzzyQuery2.cs | 4 ++--
src/Lucene.Net.Tests.Spatial/SpatialTestData.cs | 5 +++--
.../Analyzing/AnalyzingInfixSuggesterTest.cs | 4 ++--
.../Suggest/Analyzing/AnalyzingSuggesterTest.cs | 2 +-
.../Suggest/Analyzing/FuzzySuggesterTest.cs | 2 +-
.../Analysis/TestGraphTokenizers.cs | 4 ++--
src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs | 2 +-
src/Lucene.Net.Tests/Index/TestIndexWriter.cs | 2 +-
.../Search/Payloads/TestPayloadNearQuery.cs | 4 ++--
.../Search/TestSloppyPhraseQuery.cs | 12 +++++++++---
.../Search/TestTimeLimitingCollector.cs | 4 +++-
src/Lucene.Net/Support/StringExtensions.cs | 4 ----
48 files changed, 134 insertions(+), 104 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
index 0c7c8c1..55037ff 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
@@ -309,7 +309,7 @@ namespace Lucene.Net.Analysis.Hunspell
}
else if (line.StartsWith(CIRCUMFIX_KEY, StringComparison.Ordinal))
{
- string[] parts = whitespacePattern.Split(line);
+ string[] parts = whitespacePattern.Split(line).TrimEnd();
if (parts.Length != 2)
{
throw new Exception(string.Format("Illegal CIRCUMFIX declaration, line {0}", lineNumber));
@@ -318,7 +318,7 @@ namespace Lucene.Net.Analysis.Hunspell
}
else if (line.StartsWith(IGNORE_KEY, StringComparison.Ordinal))
{
- string[] parts = whitespacePattern.Split(line);
+ string[] parts = whitespacePattern.Split(line).TrimEnd();
if (parts.Length != 2)
{
throw new Exception(string.Format("Illegal IGNORE declaration, line {0}", lineNumber));
@@ -329,7 +329,7 @@ namespace Lucene.Net.Analysis.Hunspell
}
else if (line.StartsWith(ICONV_KEY, StringComparison.Ordinal) || line.StartsWith(OCONV_KEY, StringComparison.Ordinal))
{
- string[] parts = whitespacePattern.Split(line);
+ string[] parts = whitespacePattern.Split(line).TrimEnd();
string type = parts[0];
if (parts.Length != 2)
{
@@ -407,7 +407,7 @@ namespace Lucene.Net.Analysis.Hunspell
{
BytesRef scratch = new BytesRef();
StringBuilder sb = new StringBuilder();
- string[] args = whitespacePattern.Split(header);
+ string[] args = whitespacePattern.Split(header).TrimEnd();
bool crossProduct = args[2].Equals("Y");
@@ -419,7 +419,7 @@ namespace Lucene.Net.Analysis.Hunspell
{
Debug.Assert(affixWriter.Position == currentAffix << 3);
string line = reader.ReadLine();
- string[] ruleArgs = whitespacePattern.Split(line);
+ string[] ruleArgs = whitespacePattern.Split(line).TrimEnd();
// from the manpage: PFX flag stripping prefix [condition [morphological_fields...]]
// condition is optional
@@ -554,7 +554,7 @@ namespace Lucene.Net.Analysis.Hunspell
for (int i = 0; i < num; i++)
{
string line = reader.ReadLine();
- string[] parts = whitespacePattern.Split(line);
+ string[] parts = whitespacePattern.Split(line).TrimEnd();
if (parts.Length != 3)
{
throw new Exception("invalid syntax: " + line /*, reader.LineNumber */); // LUCENENET TODO: LineNumberReader
@@ -683,7 +683,7 @@ namespace Lucene.Net.Analysis.Hunspell
/// <returns> <see cref="FlagParsingStrategy"/> that handles parsing flags in the way specified in the FLAG definition </returns>
internal static FlagParsingStrategy GetFlagParsingStrategy(string flagLine)
{
- string[] parts = whitespacePattern.Split(flagLine);
+ string[] parts = whitespacePattern.Split(flagLine).TrimEnd();
if (parts.Length != 2)
{
throw new System.ArgumentException("Illegal FLAG specification: " + flagLine);
@@ -982,7 +982,7 @@ namespace Lucene.Net.Analysis.Hunspell
private void ParseAlias(string line)
{
- string[] ruleArgs = whitespacePattern.Split(line);
+ string[] ruleArgs = whitespacePattern.Split(line).TrimEnd();
if (aliases == null)
{
//first line should be the aliases count
@@ -1057,7 +1057,7 @@ namespace Lucene.Net.Analysis.Hunspell
{
internal override char[] ParseFlags(string rawFlags)
{
- string[] rawFlagParts = rawFlags.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] rawFlagParts = rawFlags.Trim().Split(',').TrimEnd();
char[] flags = new char[rawFlagParts.Length];
int upto = 0;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/HunspellStemFilterFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/HunspellStemFilterFactory.cs b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/HunspellStemFilterFactory.cs
index d27fa3b..eef53a4 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/HunspellStemFilterFactory.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Hunspell/HunspellStemFilterFactory.cs
@@ -1,4 +1,5 @@
using Lucene.Net.Analysis.Util;
+using Lucene.Net.Support;
using Lucene.Net.Util;
using System;
using System.Collections.Generic;
@@ -76,7 +77,7 @@ namespace Lucene.Net.Analysis.Hunspell
public virtual void Inform(IResourceLoader loader)
{
- string[] dicts = dictionaryFiles.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] dicts = dictionaryFiles.Split(',').TrimEnd();
Stream affix = null;
IList<Stream> dictionaries = new List<Stream>();
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
index 69fa5fb..bc596e2 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/PatternAnalyzer.cs
@@ -29,7 +29,7 @@ namespace Lucene.Net.Analysis.Miscellaneous
/// <summary>
/// Efficient Lucene analyzer/tokenizer that preferably operates on a <see cref="string"/> rather than a
/// <see cref="TextReader"/>, that can flexibly separate text into terms via a regular expression <see cref="Regex"/>
- /// (with behaviour similar to <see cref="string.Split(string[], StringSplitOptions)"/>),
+ /// (with behaviour similar to <see cref="Regex.Split(string)"/>),
/// and that combines the functionality of
/// <see cref="LetterTokenizer"/>,
/// <see cref="LowerCaseTokenizer"/>,
@@ -39,7 +39,7 @@ namespace Lucene.Net.Analysis.Miscellaneous
/// <para>
/// If you are unsure how exactly a regular expression should look like, consider
/// prototyping by simply trying various expressions on some test texts via
- /// <see cref="string.Split(string[], StringSplitOptions)"/>. Once you are satisfied, give that regex to
+ /// <see cref="Regex.Split(string)"/>. Once you are satisfied, give that regex to
/// <see cref="PatternAnalyzer"/>. Also see <a target="_blank"
/// href="http://www.regular-expressions.info/">Regular Expression Tutorial</a>.
/// </para>
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Common/Analysis/Pt/RSLPStemmerBase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Pt/RSLPStemmerBase.cs b/src/Lucene.Net.Analysis.Common/Analysis/Pt/RSLPStemmerBase.cs
index e36aee8..26f3c59 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Pt/RSLPStemmerBase.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Pt/RSLPStemmerBase.cs
@@ -364,7 +364,7 @@ namespace Lucene.Net.Analysis.Pt
{
return null;
}
- string[] list = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] list = s.Split(',').TrimEnd();
for (int i = 0; i < list.Length; i++)
{
list[i] = ParseString(list[i].Trim());
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Common/Analysis/Util/WordlistLoader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Common/Analysis/Util/WordlistLoader.cs b/src/Lucene.Net.Analysis.Common/Analysis/Util/WordlistLoader.cs
index 23fa016..5281f5f 100644
--- a/src/Lucene.Net.Analysis.Common/Analysis/Util/WordlistLoader.cs
+++ b/src/Lucene.Net.Analysis.Common/Analysis/Util/WordlistLoader.cs
@@ -1,9 +1,11 @@
-using Lucene.Net.Util;
+using Lucene.Net.Support;
+using Lucene.Net.Util;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
+using System.Text.RegularExpressions;
namespace Lucene.Net.Analysis.Util
{
@@ -34,6 +36,9 @@ namespace Lucene.Net.Analysis.Util
{
private const int INITIAL_CAPACITY = 16;
+ // LUCENENET specific
+ private readonly static Regex WHITESPACE = new Regex("\\s+", RegexOptions.Compiled);
+
/// <summary>
/// no instance </summary>
private WordlistLoader()
@@ -155,7 +160,7 @@ namespace Lucene.Net.Analysis.Util
{
line = line.Substring(0, comment);
}
- string[] words = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim()).ToArray();
+ string[] words = WHITESPACE.Split(line).TrimEnd();
foreach (var word in words)
{
if (word.Length > 0)
@@ -206,7 +211,7 @@ namespace Lucene.Net.Analysis.Util
string line;
while ((line = reader.ReadLine()) != null)
{
- string[] wordstem = line.Split(new char[] { '\t' }, 2, StringSplitOptions.RemoveEmptyEntries);
+ string[] wordstem = line.Split(new char[] { '\t' }, 2);
result.Put(wordstem[0], wordstem[1]);
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Kuromoji/Dict/UserDictionary.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Kuromoji/Dict/UserDictionary.cs b/src/Lucene.Net.Analysis.Kuromoji/Dict/UserDictionary.cs
index 3fb2b09..d5853c0 100644
--- a/src/Lucene.Net.Analysis.Kuromoji/Dict/UserDictionary.cs
+++ b/src/Lucene.Net.Analysis.Kuromoji/Dict/UserDictionary.cs
@@ -88,8 +88,8 @@ namespace Lucene.Net.Analysis.Ja.Dict
foreach (string[] values in featureEntries)
{
- string[] segmentation = commentLine.Replace(values[1], " ").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string[] readings = commentLine.Replace(values[2], " ").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] segmentation = commentLine.Replace(values[1], " ").Split(' ').TrimEnd();
+ string[] readings = commentLine.Replace(values[2], " ").Split(' ').TrimEnd();
string pos = values[3];
if (segmentation.Length != readings.Length)
@@ -265,7 +265,7 @@ namespace Lucene.Net.Analysis.Ja.Dict
return null;
}
- return allFeatures.Split(new string[] { Dictionary.INTERNAL_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
+ return allFeatures.Split(new string[] { Dictionary.INTERNAL_SEPARATOR }, StringSplitOptions.None).TrimEnd();
}
private string GetFeature(int wordId, params int[] fields)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Kuromoji/Tools/CharacterDefinitionWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Kuromoji/Tools/CharacterDefinitionWriter.cs b/src/Lucene.Net.Analysis.Kuromoji/Tools/CharacterDefinitionWriter.cs
index 39ed4f8..9f019fb 100644
--- a/src/Lucene.Net.Analysis.Kuromoji/Tools/CharacterDefinitionWriter.cs
+++ b/src/Lucene.Net.Analysis.Kuromoji/Tools/CharacterDefinitionWriter.cs
@@ -46,9 +46,9 @@ namespace Lucene.Net.Analysis.Ja.Util
/// <param name="characterClassName">Character class name.</param>
public void PutCharacterCategory(int codePoint, string characterClassName)
{
- characterClassName = characterClassName.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[0]; // use first
- // category
- // class
+ characterClassName = characterClassName.Split(' ')[0]; // use first
+ // category
+ // class
// Override Nakaguro
if (codePoint == 0x30FB)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Kuromoji/Tools/ConnectionCostsBuilder.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Kuromoji/Tools/ConnectionCostsBuilder.cs b/src/Lucene.Net.Analysis.Kuromoji/Tools/ConnectionCostsBuilder.cs
index 235c523..49aa559 100644
--- a/src/Lucene.Net.Analysis.Kuromoji/Tools/ConnectionCostsBuilder.cs
+++ b/src/Lucene.Net.Analysis.Kuromoji/Tools/ConnectionCostsBuilder.cs
@@ -1,4 +1,5 @@
-using System.Diagnostics;
+using Lucene.Net.Support;
+using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
@@ -38,7 +39,7 @@ namespace Lucene.Net.Analysis.Ja.Util
StreamReader streamReader = new StreamReader(inputStream, Encoding.ASCII);
string line = streamReader.ReadLine();
- string[] dimensions = whiteSpaceRegex.Split(line);
+ string[] dimensions = whiteSpaceRegex.Split(line).TrimEnd();
Debug.Assert(dimensions.Length == 2);
@@ -51,7 +52,7 @@ namespace Lucene.Net.Analysis.Ja.Util
while ((line = streamReader.ReadLine()) != null)
{
- string[] fields = whiteSpaceRegex.Split(line);
+ string[] fields = whiteSpaceRegex.Split(line).TrimEnd();
Debug.Assert(fields.Length == 3);
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Kuromoji/Tools/UnknownDictionaryBuilder.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Kuromoji/Tools/UnknownDictionaryBuilder.cs b/src/Lucene.Net.Analysis.Kuromoji/Tools/UnknownDictionaryBuilder.cs
index 7f10b9b..e57570a 100644
--- a/src/Lucene.Net.Analysis.Kuromoji/Tools/UnknownDictionaryBuilder.cs
+++ b/src/Lucene.Net.Analysis.Kuromoji/Tools/UnknownDictionaryBuilder.cs
@@ -1,4 +1,5 @@
using Lucene.Net.Analysis.Ja.Dict;
+using Lucene.Net.Support;
using System;
using System.Collections.Generic;
using System.Globalization;
@@ -120,7 +121,7 @@ namespace Lucene.Net.Analysis.Ja.Util
}
else
{
- string[] codePoints = Regex.Split(values[0], "\\.\\.");
+ string[] codePoints = Regex.Split(values[0], "\\.\\.").TrimEnd();
int cpFrom = Convert.ToInt32(codePoints[0], 16);
int cpTo = Convert.ToInt32(codePoints[1], 16);
@@ -132,7 +133,7 @@ namespace Lucene.Net.Analysis.Ja.Util
}
else
{ // Invoke definition
- string[] values = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // Consecutive space is merged above
+ string[] values = line.Split(' ').TrimEnd(); // Consecutive space is merged above
string characterClassName = values[0];
int invoke = int.Parse(values[1], CultureInfo.InvariantCulture);
int group = int.Parse(values[2], CultureInfo.InvariantCulture);
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs
index 98119f8..63faf7c 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Lang.cs
@@ -190,7 +190,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
}
// split it up
- string[] parts = WHITESPACE.Split(line);
+ string[] parts = WHITESPACE.Split(line).TrimEnd();
if (parts.Length != 3)
{
@@ -199,7 +199,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
}
Regex pattern = new Regex(parts[0], RegexOptions.Compiled);
- string[] langs = TOKEN.Split(parts[1]);
+ string[] langs = TOKEN.Split(parts[1]).TrimEnd();
bool accept = parts[2].Equals("true");
rules.Add(new LangRule(pattern, new HashSet<string>(langs), accept));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
index 3cf5c7a..1288f6b 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/PhoneticEngine.cs
@@ -464,7 +464,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
}
}
- IList<string> words = WHITESPACE.Split(input).ToList();
+ IList<string> words = WHITESPACE.Split(input).TrimEnd().ToList();
IList<string> words2 = new List<string>();
// special-case handling of word prefixes based upon the name type
@@ -473,7 +473,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
case NameType.SEPHARDIC:
foreach (string aWord in words)
{
- string[] parts = aWord.Split(new char[] { '\'' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] parts = aWord.Split('\'').TrimEnd();
string lastPart = parts[parts.Length - 1];
words2.Add(lastPart);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Rule.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Rule.cs b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Rule.cs
index 52f3d9a..55e2d17 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Rule.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/Bm/Rule.cs
@@ -355,7 +355,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
}
string before = ph.Substring(0, open - 0);
string input = ph.Substring(open + 1, (ph.Length - 1) - (open + 1));
- ISet<string> langs = new HashSet<string>(PLUS.Split(input));
+ ISet<string> langs = new HashSet<string>(PLUS.Split(input).TrimEnd());
return new Phoneme(before, LanguageSet.From(langs));
}
@@ -376,7 +376,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
IList<Phoneme> phs = new List<Phoneme>();
string body = ph.Substring(1, (ph.Length - 1) - 1);
- foreach (string part in PIPE.Split(body))
+ foreach (string part in PIPE.Split(body).TrimEnd())
{
phs.Add(ParsePhoneme(part));
}
@@ -477,7 +477,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
else
{
// rule
- string[] parts = WHITESPACE.Split(line);
+ string[] parts = WHITESPACE.Split(line).TrimEnd();
if (parts.Length != 4)
{
throw new ArgumentException("Malformed rule statement split into " + parts.Length +
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Analysis.Phonetic/Language/DaitchMokotoffSoundex.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Analysis.Phonetic/Language/DaitchMokotoffSoundex.cs b/src/Lucene.Net.Analysis.Phonetic/Language/DaitchMokotoffSoundex.cs
index e72bc38..d6bdfcb 100644
--- a/src/Lucene.Net.Analysis.Phonetic/Language/DaitchMokotoffSoundex.cs
+++ b/src/Lucene.Net.Analysis.Phonetic/Language/DaitchMokotoffSoundex.cs
@@ -160,6 +160,8 @@ namespace Lucene.Net.Analysis.Phonetic.Language
/// </summary>
private sealed class Rule
{
+ private readonly static Regex PIPE = new Regex(@"\|", RegexOptions.Compiled);
+
private readonly string pattern;
private readonly string[] replacementAtStart;
private readonly string[] replacementBeforeVowel;
@@ -169,9 +171,9 @@ namespace Lucene.Net.Analysis.Phonetic.Language
string replacementDefault)
{
this.pattern = pattern;
- this.replacementAtStart = Regex.Split(replacementAtStart, "\\|");
- this.replacementBeforeVowel = Regex.Split(replacementBeforeVowel, "\\|");
- this.replacementDefault = Regex.Split(replacementDefault, "\\|");
+ this.replacementAtStart = PIPE.Split(replacementAtStart);
+ this.replacementBeforeVowel = PIPE.Split(replacementBeforeVowel);
+ this.replacementDefault = PIPE.Split(replacementDefault);
}
// LUCENENET specific - need read access to pattern
@@ -238,6 +240,8 @@ namespace Lucene.Net.Analysis.Phonetic.Language
/// <summary>Folding rules.</summary>
private static readonly IDictionary<char, char> FOLDINGS = new Dictionary<char, char>();
+ private static readonly Regex WHITESPACE = new Regex(@"\s+", RegexOptions.Compiled);
+
private class DaitchMokotoffRuleComparer : IComparer<Rule>
{
public int Compare(Rule rule1, Rule rule2)
@@ -312,7 +316,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language
if (line.Contains("="))
{
// folding
- string[] parts = line.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
+ string[] parts = line.Split('=').TrimEnd();
if (parts.Length != 2)
{
throw new ArgumentException("Malformed folding statement split into " + parts.Length +
@@ -335,7 +339,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language
else
{
// rule
- string[] parts = Regex.Split(line, "\\s+");
+ string[] parts = WHITESPACE.Split(line).TrimEnd();
if (parts.Length != 4)
{
throw new ArgumentException("Malformed rule statement split into " + parts.Length +
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs b/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs
index 1a45cc6..8829b75 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Feeds/LineDocSource.cs
@@ -123,7 +123,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
if (line.StartsWith(headIndicator, StringComparison.Ordinal))
{
- header = line.Substring(headIndicator.Length).Split(new char[] { WriteLineDocTask.SEP }).TrimEnd();
+ header = line.Substring(headIndicator.Length).Split(WriteLineDocTask.SEP).TrimEnd();
skipHeaderLine = true; // mark to skip the header line when input file is reopened
}
else
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Benchmark/ByTask/Tasks/OpenReaderTask.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Benchmark/ByTask/Tasks/OpenReaderTask.cs b/src/Lucene.Net.Benchmark/ByTask/Tasks/OpenReaderTask.cs
index 81adf4c..7ef8705 100644
--- a/src/Lucene.Net.Benchmark/ByTask/Tasks/OpenReaderTask.cs
+++ b/src/Lucene.Net.Benchmark/ByTask/Tasks/OpenReaderTask.cs
@@ -63,7 +63,7 @@ namespace Lucene.Net.Benchmarks.ByTask.Tasks
base.SetParams(@params);
if (@params != null)
{
- string[] split = @params.Split(new char[] { ',' }).TrimEnd();
+ string[] split = @params.Split(',').TrimEnd();
if (split.Length > 0)
{
commitUserData = split[0];
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
index a928290..fe493c6 100644
--- a/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
+++ b/src/Lucene.Net.Codecs/SimpleText/SimpleTextDocValuesReader.cs
@@ -1,4 +1,5 @@
-using System;
+using Lucene.Net.Support;
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -535,7 +536,7 @@ namespace Lucene.Net.Codecs.SimpleText
docID * (1 + _field.OrdPattern.Length));
SimpleTextUtil.ReadLine(_input, _scratch);
var ordList = _scratch.Utf8ToString().Trim();
- _currentOrds = ordList.Length == 0 ? new string[0] : ordList.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ _currentOrds = ordList.Length == 0 ? new string[0] : ordList.Split(',').TrimEnd();
_currentIndex = 0;
}
catch (System.IO.IOException ioe)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
index c95c056..4c881c8 100644
--- a/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
+++ b/src/Lucene.Net.Expressions/JS/JavascriptCompiler.cs
@@ -608,7 +608,7 @@ namespace Lucene.Net.Expressions.JS
{
foreach (var property in GetDefaultSettings())
{
- string[] vals = property.Value.Split(',');
+ string[] vals = property.Value.Split(',').TrimEnd();
if (vals.Length != 3)
{
throw new Exception("Error reading Javascript functions from settings");
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs
index 870771f..6d811db 100644
--- a/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/CategoryPath.cs
@@ -90,7 +90,7 @@ namespace Lucene.Net.Facet.Taxonomy
/// </summary>
public CategoryPath(string pathString, char delimiter)
{
- string[] comps = pathString.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries);
+ string[] comps = pathString.Split(delimiter).TrimEnd();
if (comps.Length == 1 && comps[0].Length == 0)
{
Components = null;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs b/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs
index 0af6739..88015da 100644
--- a/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs
+++ b/src/Lucene.Net.QueryParser/Xml/Builders/LikeThisQueryBuilder.cs
@@ -2,6 +2,7 @@
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Queries.Mlt;
using Lucene.Net.Search;
+using Lucene.Net.Support;
using Lucene.Net.Util;
using System;
using System.Collections.Generic;
@@ -55,7 +56,7 @@ namespace Lucene.Net.QueryParsers.Xml.Builders
string[] fields = defaultFieldNames;
if ((fieldsList != null) && (fieldsList.Trim().Length > 0))
{
- fields = fieldsList.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ fields = fieldsList.Trim().Split(',').TrimEnd();
//trim the fieldnames
for (int i = 0; i < fields.Length; i++)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Replicator/Http/ReplicationService.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/Http/ReplicationService.cs b/src/Lucene.Net.Replicator/Http/ReplicationService.cs
index 6ef6155..38692f9 100644
--- a/src/Lucene.Net.Replicator/Http/ReplicationService.cs
+++ b/src/Lucene.Net.Replicator/Http/ReplicationService.cs
@@ -1,5 +1,6 @@
using Lucene.Net.Replicator.Http.Abstractions;
using Lucene.Net.Support.IO;
+using Lucene.Net.Support;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -111,7 +112,7 @@ namespace Lucene.Net.Replicator.Http
if (path.Length > actionLength && path[actionLength] == '/')
++startIndex;
- return path.Substring(startIndex).Split('/');
+ return path.Substring(startIndex).Split('/').TrimEnd();
}
private static string ExtractRequestParam(IReplicationRequest request, string paramName)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs b/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
index b2b90a6..de1ed16 100644
--- a/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
+++ b/src/Lucene.Net.Replicator/IndexAndTaxonomyRevision.cs
@@ -2,6 +2,7 @@
using Lucene.Net.Facet.Taxonomy.WriterCache;
using Lucene.Net.Index;
using Lucene.Net.Store;
+using Lucene.Net.Support;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -150,7 +151,7 @@ namespace Lucene.Net.Replicator
/// </summary>
public virtual int CompareTo(string version)
{
- string[] parts = version.Split(':');
+ string[] parts = version.Split(':').TrimEnd();
long indexGen = long.Parse(parts[0], NumberStyles.HexNumber);
long taxonomyGen = long.Parse(parts[1], NumberStyles.HexNumber);
long indexCommitGen = indexCommit.Generation;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.TestFramework/Analysis/VocabularyAssert.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Analysis/VocabularyAssert.cs b/src/Lucene.Net.TestFramework/Analysis/VocabularyAssert.cs
index 7ce652b..749260f 100644
--- a/src/Lucene.Net.TestFramework/Analysis/VocabularyAssert.cs
+++ b/src/Lucene.Net.TestFramework/Analysis/VocabularyAssert.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Util;
+using Lucene.Net.Support;
using NUnit.Framework;
using System.IO;
using System.IO.Compression;
@@ -54,7 +54,7 @@ namespace Lucene.Net.Analysis
{
continue; // comment
}
- string[] words = inputLine.Split('\t');
+ string[] words = inputLine.Split('\t').TrimEnd();
BaseTokenStreamTestCase.CheckOneTerm(a, words[0], words[1]);
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.TestFramework/Randomized/SeedUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Randomized/SeedUtils.cs b/src/Lucene.Net.TestFramework/Randomized/SeedUtils.cs
index 68b5ef4..284323d 100644
--- a/src/Lucene.Net.TestFramework/Randomized/SeedUtils.cs
+++ b/src/Lucene.Net.TestFramework/Randomized/SeedUtils.cs
@@ -19,6 +19,7 @@
*
*/
+using Lucene.Net.Support;
using System;
using System.Linq;
using System.Text;
@@ -70,7 +71,7 @@ namespace Lucene.Net.Randomized
if (matches.Count == 0)
throw new ArgumentException("Not a valid seed chain: " + chain, "chain");
- var parts = chain.Split(":".ToCharArray());
+ var parts = chain.Split(':').TrimEnd();
int[] result = new int[parts.Length];
for (int i = 0; i < parts.Length; i++)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilter.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilter.cs
index 7634702..290441d 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilter.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilter.cs
@@ -51,7 +51,7 @@ namespace Lucene.Net.Analysis.Miscellaneous
IEnumerator<Token> toks = Arrays.AsList(tokens).GetEnumerator();
TokenStream ts = new RemoveDuplicatesTokenFilter((new TokenStreamAnonymousInnerClassHelper(this, toks)));
- AssertTokenStreamContents(ts, Regex.Split(expected, "\\s"));
+ AssertTokenStreamContents(ts, Regex.Split(expected, "\\s").TrimEnd());
}
private class TokenStreamAnonymousInnerClassHelper : TokenStream
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilterFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilterFactory.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilterFactory.cs
index 0113e09..c75be08 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilterFactory.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Miscellaneous/TestRemoveDuplicatesTokenFilterFactory.cs
@@ -1,4 +1,5 @@
using Lucene.Net.Analysis.Util;
+using Lucene.Net.Support;
using NUnit.Framework;
using System.Text.RegularExpressions;
@@ -37,7 +38,7 @@ namespace Lucene.Net.Analysis.Miscellaneous
{
TokenStream stream = new CannedTokenStream(tokens);
stream = TokenFilterFactory("RemoveDuplicates").Create(stream);
- AssertTokenStreamContents(stream, Regex.Split(expected, "\\s"));
+ AssertTokenStreamContents(stream, Regex.Split(expected, "\\s").TrimEnd());
}
[Test]
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Common/Analysis/Snowball/TestSnowballPorterFilterFactory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Snowball/TestSnowballPorterFilterFactory.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Snowball/TestSnowballPorterFilterFactory.cs
index 4f112b2..1de2510 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Snowball/TestSnowballPorterFilterFactory.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Snowball/TestSnowballPorterFilterFactory.cs
@@ -1,4 +1,5 @@
using Lucene.Net.Analysis.Util;
+using Lucene.Net.Support;
using Lucene.Net.Tartarus.Snowball.Ext;
using NUnit.Framework;
using System.IO;
@@ -32,7 +33,7 @@ namespace Lucene.Net.Analysis.Snowball
{
string text = "The fledgling banks were counting on a big boom in banking";
EnglishStemmer stemmer = new EnglishStemmer();
- string[] test = Regex.Split(text, "\\s");
+ string[] test = Regex.Split(text, "\\s").TrimEnd();
string[] gold = new string[test.Length];
for (int i = 0; i < test.Length; i++)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSlowSynonymFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSlowSynonymFilter.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSlowSynonymFilter.cs
index 7d33bd9..c2cf39b 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSlowSynonymFilter.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSlowSynonymFilter.cs
@@ -37,7 +37,7 @@ namespace Lucene.Net.Analysis.Synonym
internal static IList<string> Strings(string str)
{
- string[] arr = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+ string[] arr = str.Split(' ').TrimEnd();
return Arrays.AsList(arr);
}
@@ -277,12 +277,12 @@ namespace Lucene.Net.Analysis.Synonym
[Obsolete("(3.0) does not support attributes api")]
private IList<Token> Tokens(string str)
{
- string[] arr = str.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+ string[] arr = str.Split(' ').TrimEnd();
IList<Token> result = new List<Token>();
for (int i = 0; i < arr.Length; i++)
{
- string[] toks = arr[i].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
- string[] @params = toks[0].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
+ string[] toks = arr[i].Split('/').TrimEnd();
+ string[] @params = toks[0].Split(',').TrimEnd();
int posInc;
int start;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSynonymMapFilter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSynonymMapFilter.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSynonymMapFilter.cs
index 30af766..ef09a42 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSynonymMapFilter.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Synonym/TestSynonymMapFilter.cs
@@ -51,10 +51,10 @@ namespace Lucene.Net.Analysis.Synonym
}
CharsRef inputCharsRef = new CharsRef();
- SynonymMap.Builder.Join(space.Split(input), inputCharsRef);
+ SynonymMap.Builder.Join(space.Split(input).TrimEnd(), inputCharsRef);
CharsRef outputCharsRef = new CharsRef();
- SynonymMap.Builder.Join(space.Split(output), outputCharsRef);
+ SynonymMap.Builder.Join(space.Split(output).TrimEnd(), outputCharsRef);
b.Add(inputCharsRef, outputCharsRef, keepOrig);
}
@@ -85,7 +85,7 @@ namespace Lucene.Net.Analysis.Synonym
tokensIn.SetReader(new StringReader(input));
tokensOut.Reset();
- string[] expected = output.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+ string[] expected = output.Split(' ').TrimEnd();
int expectedUpto = 0;
while (tokensOut.IncrementToken())
{
@@ -99,7 +99,7 @@ namespace Lucene.Net.Analysis.Synonym
int startOffset = offsetAtt.StartOffset;
int endOffset = offsetAtt.EndOffset;
- string[] expectedAtPos = expected[expectedUpto++].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
+ string[] expectedAtPos = expected[expectedUpto++].Split('/').TrimEnd();
for (int atPos = 0; atPos < expectedAtPos.Length; atPos++)
{
if (atPos > 0)
@@ -380,7 +380,7 @@ namespace Lucene.Net.Analysis.Synonym
}
foreach (string synOut in syn.@out)
{
- string[] synOutputs = synOut.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+ string[] synOutputs = synOut.Split(' ').TrimEnd();
assertEquals(synOutputs.Length, (1 + synOut.Length) / 2);
int matchEnd = inputIDX + synOutputs.Length;
int synUpto = 0;
@@ -417,7 +417,7 @@ namespace Lucene.Net.Analysis.Synonym
}
StringBuilder sb = new StringBuilder();
- string[] inputTokens = doc.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
+ string[] inputTokens = doc.Split(' ').TrimEnd();
int limit = inputTokens.Length + maxOutputLength;
for (int inputIDX = 0; inputIDX < limit; inputIDX++)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharTokenizers.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharTokenizers.cs b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharTokenizers.cs
index 87b8c22..37c7a04 100644
--- a/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharTokenizers.cs
+++ b/src/Lucene.Net.Tests.Analysis.Common/Analysis/Util/TestCharTokenizers.cs
@@ -57,7 +57,7 @@ namespace Lucene.Net.Analysis.Util
// internal buffer size is 1024 make sure we have a surrogate pair right at the border
builder.Insert(1023, "\ud801\udc1c");
var tokenizer = new LowerCaseTokenizer(TEST_VERSION_CURRENT, new StringReader(builder.ToString()));
- AssertTokenStreamContents(tokenizer, builder.ToString().ToLowerInvariant().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
+ AssertTokenStreamContents(tokenizer, builder.ToString().ToLowerInvariant().Split(' ').TrimEnd());
}
/*
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs b/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs
index 4331ce9..8e9bbfc 100644
--- a/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs
+++ b/src/Lucene.Net.Tests.Analysis.Kuromoji/TestJapaneseTokenizer.cs
@@ -2,6 +2,7 @@
using Lucene.Net.Analysis.Ja.TokenAttributes;
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Attributes;
+using Lucene.Net.Support;
using Lucene.Net.Util;
using NUnit.Framework;
using System;
@@ -797,7 +798,7 @@ namespace Lucene.Net.Analysis.Ja
IOUtils.DisposeWhileHandlingException(ts);
}
}
- String[] sentences = Regex.Split(line, "、|。");
+ String[] sentences = Regex.Split(line, "、|。").TrimEnd();
if (VERBOSE)
{
Console.WriteLine("Total time : " + (Environment.TickCount - totalStart));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Kuromoji/TestSearchMode.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Kuromoji/TestSearchMode.cs b/src/Lucene.Net.Tests.Analysis.Kuromoji/TestSearchMode.cs
index f44feb0..f12b173 100644
--- a/src/Lucene.Net.Tests.Analysis.Kuromoji/TestSearchMode.cs
+++ b/src/Lucene.Net.Tests.Analysis.Kuromoji/TestSearchMode.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using Lucene.Net.Support;
+using NUnit.Framework;
using System;
using System.IO;
using System.Text;
@@ -63,9 +64,9 @@ namespace Lucene.Net.Analysis.Ja
{
Console.WriteLine("Line no. " + lineNumber + ": " + line);
}
- String[] fields = new Regex("\t").Split(line, 2); // Regex.Split(line, "\t", 2);
+ String[] fields = new Regex("\t").Split(line, 2);
String sourceText = fields[0];
- String[] expectedTokens = Regex.Split(fields[1], "\\s+");
+ String[] expectedTokens = Regex.Split(fields[1], "\\s+").TrimEnd();
int[] expectedPosIncrs = new int[expectedTokens.Length];
int[] expectedPosLengths = new int[expectedTokens.Length];
for (int tokIDX = 0; tokIDX < expectedTokens.Length; tokIDX++)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/BeiderMorseEncoderTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/BeiderMorseEncoderTest.cs b/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/BeiderMorseEncoderTest.cs
index 1d7fe8a..f85c95c 100644
--- a/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/BeiderMorseEncoderTest.cs
+++ b/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/BeiderMorseEncoderTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using Lucene.Net.Support;
+using NUnit.Framework;
using System;
using System.Globalization;
using System.Text;
@@ -168,7 +169,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
String phonemes = encoder.Encode(phrase);
Assert.True(phonemes.Length > 0);
- String[] phonemeArr = new Regex("\\|").Split(phonemes);
+ String[] phonemeArr = new Regex("\\|").Split(phonemes).TrimEnd();
Assert.True(phonemeArr.Length <= 10);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineRegressionTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineRegressionTest.cs b/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineRegressionTest.cs
index cb9a40d..3f89405 100644
--- a/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineRegressionTest.cs
+++ b/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineRegressionTest.cs
@@ -209,7 +209,7 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
}
else
{
- languageSet = LanguageSet.From(new HashSet<String>(Arrays.AsList(languageSetArg.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))));
+ languageSet = LanguageSet.From(new HashSet<String>(Arrays.AsList(languageSetArg.Split(',').TrimEnd())));
}
/*
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineTest.cs b/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineTest.cs
index 281fc45..25728b1 100644
--- a/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineTest.cs
+++ b/src/Lucene.Net.Tests.Analysis.Phonetic/Language/Bm/PhoneticEngineTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using Lucene.Net.Support;
+using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
@@ -72,15 +73,15 @@ namespace Lucene.Net.Analysis.Phonetic.Language.Bm
if (concat)
{
- String[] split = new Regex("\\|").Split(phoneticActual);
+ String[] split = new Regex("\\|").Split(phoneticActual).TrimEnd();
Assert.True(split.Length <= maxPhonemes);
}
else
{
- String[] words = phoneticActual.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
+ String[] words = phoneticActual.Split('-').TrimEnd();
foreach (String word in words)
{
- String[] split = new Regex("\\|").Split(word);
+ String[] split = new Regex("\\|").Split(word).TrimEnd();
Assert.True(split.Length <= maxPhonemes);
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
index 7066c5f..852638b 100644
--- a/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
+++ b/src/Lucene.Net.Tests.Facet/Taxonomy/WriterCache/TestCompactLabelToOrdinal.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using Lucene.Net.Support;
+using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
@@ -94,7 +95,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache
}
else
{
- label = new FacetLabel(s.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
+ label = new FacetLabel(s.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
}
int ord1 = map.GetOrdinal(label);
@@ -125,7 +126,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache
}
else
{
- label = new FacetLabel(s.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
+ label = new FacetLabel(s.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
}
int ord1 = map.GetOrdinal(label);
int ord2 = compact.GetOrdinal(label);
@@ -210,7 +211,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache
}
else
{
- label = new FacetLabel(s.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
+ label = new FacetLabel(s.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
}
int ord1 = map.GetOrdinal(label);
@@ -242,7 +243,7 @@ namespace Lucene.Net.Facet.Taxonomy.WriterCache
}
else
{
- label = new FacetLabel(s.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
+ label = new FacetLabel(s.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
}
int ord1 = map.GetOrdinal(label);
int ord2 = compact.GetOrdinal(label);
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs b/src/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
index fcdb4dd..fcb137e 100644
--- a/src/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
+++ b/src/Lucene.Net.Tests.QueryParser/ComplexPhrase/TestComplexPhraseQuery.cs
@@ -3,6 +3,7 @@ using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
+using Lucene.Net.Support;
using Lucene.Net.Util;
using NUnit.Framework;
using System;
@@ -106,7 +107,7 @@ namespace Lucene.Net.QueryParsers.ComplexPhrase
Query q = qp.Parse(qString);
HashSet<string> expecteds = new HashSet<string>();
- string[] vals = expectedVals.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
+ string[] vals = expectedVals.Split(',').TrimEnd();
for (int i = 0; i < vals.Length; i++)
{
if (vals[i].Length > 0)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Sandbox/Queries/TestSlowFuzzyQuery2.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Sandbox/Queries/TestSlowFuzzyQuery2.cs b/src/Lucene.Net.Tests.Sandbox/Queries/TestSlowFuzzyQuery2.cs
index 525bf50..77173d3 100644
--- a/src/Lucene.Net.Tests.Sandbox/Queries/TestSlowFuzzyQuery2.cs
+++ b/src/Lucene.Net.Tests.Sandbox/Queries/TestSlowFuzzyQuery2.cs
@@ -121,7 +121,7 @@ namespace Lucene.Net.Sandbox.Queries
while ((line = reader.ReadLine()) != null)
{
lineNum++;
- String[] @params = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ String[] @params = line.Split(',').TrimEnd();
String query = MapInt(codePointTable, int.Parse(@params[0], CultureInfo.InvariantCulture));
int prefix = int.Parse(@params[1], CultureInfo.InvariantCulture);
int pqSize = int.Parse(@params[2], CultureInfo.InvariantCulture);
@@ -135,7 +135,7 @@ namespace Lucene.Net.Sandbox.Queries
assertEquals(expectedResults, docs.TotalHits);
for (int i = 0; i < expectedResults; i++)
{
- String[] scoreDoc = reader.ReadLine().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
+ String[] scoreDoc = reader.ReadLine().Split(',').TrimEnd();
assertEquals(int.Parse(scoreDoc[0], CultureInfo.InvariantCulture), docs.ScoreDocs[i].Doc);
assertEquals(float.Parse(scoreDoc[1], CultureInfo.InvariantCulture), docs.ScoreDocs[i].Score, epsilon);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Spatial/SpatialTestData.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Spatial/SpatialTestData.cs b/src/Lucene.Net.Tests.Spatial/SpatialTestData.cs
index d2be777..02461d6 100644
--- a/src/Lucene.Net.Tests.Spatial/SpatialTestData.cs
+++ b/src/Lucene.Net.Tests.Spatial/SpatialTestData.cs
@@ -1,4 +1,5 @@
-using Spatial4n.Core.Context;
+using Lucene.Net.Support;
+using Spatial4n.Core.Context;
using Spatial4n.Core.Exceptions;
using Spatial4n.Core.Shapes;
using System;
@@ -52,7 +53,7 @@ namespace Lucene.Net.Spatial
continue;
SpatialTestData data = new SpatialTestData();
- String[] vals = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
+ String[] vals = line.Split('\t').TrimEnd();
if (vals.Length != 3)
throw new Exception("bad format; expecting 3 tab-separated values for line: " + line);
data.id = vals[0];
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
index 5a9b35d..aeaf685 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
@@ -751,7 +751,7 @@ namespace Lucene.Net.Search.Suggest.Analyzing
query += " ";
}
- string[] queryTerms = Regex.Split(query, "\\s", RegexOptions.Compiled);
+ string[] queryTerms = Regex.Split(query, "\\s", RegexOptions.Compiled).TrimEnd();
bool allTermsRequired = Random().nextInt(10) == 7;
bool doHilite = Random().nextBoolean();
@@ -765,7 +765,7 @@ namespace Lucene.Net.Search.Suggest.Analyzing
for (int i = 0; i < visibleUpto; i++)
{
Input input = inputs.ElementAt(i);
- string[] inputTerms = Regex.Split(input.term.Utf8ToString(), "\\s", RegexOptions.Compiled);
+ string[] inputTerms = Regex.Split(input.term.Utf8ToString(), "\\s", RegexOptions.Compiled).TrimEnd();
bool match = false;
for (int j = 0; j < queryTerms.Length; j++)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs
index 5c5906f..3d75293 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingSuggesterTest.cs
@@ -928,7 +928,7 @@ namespace Lucene.Net.Search.Suggest.Analyzing
List<TermFreq2> matches = new List<TermFreq2>();
// "Analyze" the key:
- string[] tokens = prefix.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] tokens = prefix.Split(' ').TrimEnd();
StringBuilder builder = new StringBuilder();
bool lastRemoved = false;
for (int i = 0; i < tokens.Length; i++)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs
index cea67cb..29e73ca 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/FuzzySuggesterTest.cs
@@ -841,7 +841,7 @@ namespace Lucene.Net.Search.Suggest.Analyzing
List<Lookup.LookupResult> matches = new List<Lookup.LookupResult>();
// "Analyze" the key:
- string[] tokens = prefix.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ string[] tokens = prefix.Split(' ').TrimEnd();
StringBuilder builder = new StringBuilder();
bool lastRemoved = false;
for (int i = 0; i < tokens.Length; i++)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests/Analysis/TestGraphTokenizers.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Analysis/TestGraphTokenizers.cs b/src/Lucene.Net.Tests/Analysis/TestGraphTokenizers.cs
index b7f8adb..53bcbeb 100644
--- a/src/Lucene.Net.Tests/Analysis/TestGraphTokenizers.cs
+++ b/src/Lucene.Net.Tests/Analysis/TestGraphTokenizers.cs
@@ -136,7 +136,7 @@ namespace Lucene.Net.Analysis
InputLength = sb.Length;
- string[] parts = sb.ToString().Split(' ');
+ string[] parts = sb.ToString().Split(' ').TrimEnd();
Tokens = new List<Token>();
int pos = 0;
@@ -145,7 +145,7 @@ namespace Lucene.Net.Analysis
//System.out.println("again");
foreach (string part in parts)
{
- string[] overlapped = part.Split('/');
+ string[] overlapped = part.Split('/').TrimEnd();
bool firstAtPos = true;
int minPosLength = int.MaxValue;
foreach (string part2 in overlapped)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs b/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
index 6c2810b..06023cd 100644
--- a/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
+++ b/src/Lucene.Net.Tests/Index/TestDuelingCodecs.cs
@@ -151,7 +151,7 @@ namespace Lucene.Net.Index
Document document = lineFileDocs.NextDoc();
// grab the title and add some SortedSet instances for fun
string title = document.Get("titleTokenized");
- string[] split = whiteSpace.Split(title);
+ string[] split = whiteSpace.Split(title).TrimEnd();
foreach (string trash in split)
{
document.Add(new SortedSetDocValuesField("sortedset", new BytesRef(trash)));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
index 21fafd1..8010e70 100644
--- a/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
+++ b/src/Lucene.Net.Tests/Index/TestIndexWriter.cs
@@ -1998,7 +1998,7 @@ namespace Lucene.Net.Index
{
b.Append(buffer, 0, n);
}
- this.Tokens = b.ToString().Split(' ');
+ this.Tokens = b.ToString().Split(' ').TrimEnd();
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests/Search/Payloads/TestPayloadNearQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Search/Payloads/TestPayloadNearQuery.cs b/src/Lucene.Net.Tests/Search/Payloads/TestPayloadNearQuery.cs
index c608df2..261ac15 100644
--- a/src/Lucene.Net.Tests/Search/Payloads/TestPayloadNearQuery.cs
+++ b/src/Lucene.Net.Tests/Search/Payloads/TestPayloadNearQuery.cs
@@ -103,7 +103,7 @@ namespace Lucene.Net.Search.Payloads
private PayloadNearQuery NewPhraseQuery(string fieldName, string phrase, bool inOrder, PayloadFunction function)
{
- var words = _whiteSpaceRegex.Split(phrase);
+ var words = _whiteSpaceRegex.Split(phrase).TrimEnd();
var clauses = new SpanQuery[words.Length];
for (var i = 0; i < clauses.Length; i++)
{
@@ -301,7 +301,7 @@ namespace Lucene.Net.Search.Payloads
private SpanNearQuery SpanNearQuery(string fieldName, string words)
{
- var wordList = _whiteSpaceRegex.Split(words);
+ var wordList = _whiteSpaceRegex.Split(words).TrimEnd();
var clauses = new SpanQuery[wordList.Length];
for (var i = 0; i < clauses.Length; i++)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs b/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
index 5c010ac..2c59335 100644
--- a/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
+++ b/src/Lucene.Net.Tests/Search/TestSloppyPhraseQuery.cs
@@ -1,9 +1,11 @@
-using System;
using Lucene.Net.Documents;
+using Lucene.Net.Support;
+using NUnit.Framework;
+using System;
+using System.Text.RegularExpressions;
namespace Lucene.Net.Search
{
- using NUnit.Framework;
using AtomicReaderContext = Lucene.Net.Index.AtomicReaderContext;
using Directory = Lucene.Net.Store.Directory;
using Document = Documents.Document;
@@ -38,6 +40,8 @@ namespace Lucene.Net.Search
[TestFixture]
public class TestSloppyPhraseQuery : LuceneTestCase
{
+ private static Regex SPACES = new Regex(" +", RegexOptions.Compiled);
+
private const string S_1 = "A A A";
private const string S_2 = "A 1 2 3 A 4 5 6 A";
@@ -194,10 +198,12 @@ namespace Lucene.Net.Search
return doc;
}
+
+
private static PhraseQuery MakePhraseQuery(string terms)
{
PhraseQuery query = new PhraseQuery();
- string[] t = terms.Split(" +".ToCharArray());
+ string[] t = SPACES.Split(terms).TrimEnd();
for (int i = 0; i < t.Length; i++)
{
query.Add(new Term("f", t[i]));
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs b/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
index 4e258d2..c3ad145 100644
--- a/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
+++ b/src/Lucene.Net.Tests/Search/TestTimeLimitingCollector.cs
@@ -58,6 +58,8 @@ namespace Lucene.Net.Search
private Counter counter;
private TimeLimitingCollector.TimerThread counterThread;
+ private readonly static Regex WHITESPACE = new Regex("\\s+", RegexOptions.Compiled);
+
/**
* initializes searcher with a document set
*/
@@ -93,7 +95,7 @@ namespace Lucene.Net.Search
// start from 1, so that the 0th doc never matches
for (int i = 1; i < docText.Length; i++)
{
- string[] docTextParts = Regex.Split(docText[i], "\\s+");
+ string[] docTextParts = WHITESPACE.Split(docText[i]).TrimEnd();
foreach (string docTextPart in docTextParts)
{
// large query so that search will be longer
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a57d9f11/src/Lucene.Net/Support/StringExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/StringExtensions.cs b/src/Lucene.Net/Support/StringExtensions.cs
index 0bb596b..c051a60 100644
--- a/src/Lucene.Net/Support/StringExtensions.cs
+++ b/src/Lucene.Net/Support/StringExtensions.cs
@@ -138,10 +138,6 @@ namespace Lucene.Net.Support
return -1;
}
- // LUCENENET TODO: BUG Replace all calls to .Split("", StringSplitOptions.RemoveEmptyEntries)
- // and Regex.Split("") with .Split("").TrimEnd() and Regex.Split("").TrimEnd() to match the
- // behavior of Java's Split() method.
-
/// <summary>
/// Removes null or empty elements from the end of a string array.
/// </summary>
[04/11] lucenenet git commit: BUG:
Lucene.Net.Tests.QueryParser.Flexible.Precedence.TestPrecedenceQueryParser:
Fixed test to always use GregorianCalendar and local time zone.
Posted by ni...@apache.org.
BUG: Lucene.Net.Tests.QueryParser.Flexible.Precedence.TestPrecedenceQueryParser: Fixed test to always use GregorianCalendar and local time zone.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/fe8add7a
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/fe8add7a
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/fe8add7a
Branch: refs/heads/master
Commit: fe8add7a54948f5ee168ce840b9277003b39246b
Parents: 713a645
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Tue Sep 19 21:50:40 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 03:06:03 2017 +0700
----------------------------------------------------------------------
.../Flexible/Precedence/TestPrecedenceQueryParser.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/fe8add7a/src/Lucene.Net.Tests.QueryParser/Flexible/Precedence/TestPrecedenceQueryParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/Flexible/Precedence/TestPrecedenceQueryParser.cs b/src/Lucene.Net.Tests.QueryParser/Flexible/Precedence/TestPrecedenceQueryParser.cs
index 8a7e3eb..d2a936e 100644
--- a/src/Lucene.Net.Tests.QueryParser/Flexible/Precedence/TestPrecedenceQueryParser.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Flexible/Precedence/TestPrecedenceQueryParser.cs
@@ -450,9 +450,9 @@ namespace Lucene.Net.QueryParsers.Flexible.Precedence
//}
//return df.format(calendar.getTime());
-
- var calendar = CultureInfo.CurrentCulture.Calendar;
+ var calendar = new GregorianCalendar(GregorianCalendarTypes.Localized);
DateTime lastDate = calendar.ToDateTime(year, month, day, 0, 0, 0, 0);
+ lastDate = TimeZoneInfo.ConvertTime(lastDate, TimeZoneInfo.Local);
if (extendLastDate)
{
[10/11] lucenenet git commit:
Lucene.Net.TestFramework.Index.BasePostingsFormatTestCase +
Lucene.Net.Suggest.Analyzing (AnalyzingInfixSuggesterTest +
TestFreeTextSuggester) + Lucene.Net.Tests.Index.TestCodecs: Added using
blocks to make the tests run mor
Posted by ni...@apache.org.
Lucene.Net.TestFramework.Index.BasePostingsFormatTestCase + Lucene.Net.Suggest.Analyzing (AnalyzingInfixSuggesterTest + TestFreeTextSuggester) + Lucene.Net.Tests.Index.TestCodecs: Added using blocks to make the tests run more reliably.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/302a51e6
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/302a51e6
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/302a51e6
Branch: refs/heads/master
Commit: 302a51e66ee3ebafd977fa2277bed790ef33756b
Parents: 063f384
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Sep 22 01:17:01 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 12:45:44 2017 +0700
----------------------------------------------------------------------
.../Index/BasePostingsFormatTestCase.cs | 125 +-
.../Analyzing/AnalyzingInfixSuggesterTest.cs | 1095 +++++++++---------
.../Suggest/Analyzing/TestFreeTextSuggester.cs | 16 +-
src/Lucene.Net.Tests/Index/TestCodecs.cs | 250 ++--
4 files changed, 769 insertions(+), 717 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/302a51e6/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
index c8b9c16..12d4f1e 100644
--- a/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Index/BasePostingsFormatTestCase.cs
@@ -555,94 +555,97 @@ namespace Lucene.Net.Index
long bytes = TotalPostings * 8 + TotalPayloadBytes;
SegmentWriteState writeState = new SegmentWriteState(null, dir, segmentInfo, newFieldInfos, 32, null, new IOContext(new FlushInfo(MaxDoc, bytes)));
- FieldsConsumer fieldsConsumer = codec.PostingsFormat.FieldsConsumer(writeState);
- foreach (KeyValuePair<string, SortedDictionary<BytesRef, long>> fieldEnt in Fields)
+ // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
+ using (FieldsConsumer fieldsConsumer = codec.PostingsFormat.FieldsConsumer(writeState))
{
- string field = fieldEnt.Key;
- IDictionary<BytesRef, long> terms = fieldEnt.Value;
-
- FieldInfo fieldInfo = newFieldInfos.FieldInfo(field);
-
- IndexOptions indexOptions = fieldInfo.IndexOptions;
- if (VERBOSE)
+ foreach (KeyValuePair<string, SortedDictionary<BytesRef, long>> fieldEnt in Fields)
{
- Console.WriteLine("field=" + field + " indexOtions=" + indexOptions);
- }
+ string field = fieldEnt.Key;
+ IDictionary<BytesRef, long> terms = fieldEnt.Value;
- bool doFreq = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
- bool doPos = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
- bool doPayloads = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && allowPayloads;
- bool doOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
+ FieldInfo fieldInfo = newFieldInfos.FieldInfo(field);
+
+ IndexOptions indexOptions = fieldInfo.IndexOptions;
- TermsConsumer termsConsumer = fieldsConsumer.AddField(fieldInfo);
- long sumTotalTF = 0;
- long sumDF = 0;
- FixedBitSet seenDocs = new FixedBitSet(MaxDoc);
- foreach (KeyValuePair<BytesRef, long> termEnt in terms)
- {
- BytesRef term = termEnt.Key;
- SeedPostings postings = GetSeedPostings(term.Utf8ToString(), termEnt.Value, false, maxAllowed);
if (VERBOSE)
{
- Console.WriteLine(" term=" + field + ":" + term.Utf8ToString() + " docFreq=" + postings.DocFreq + " seed=" + termEnt.Value);
+ Console.WriteLine("field=" + field + " indexOtions=" + indexOptions);
}
- PostingsConsumer postingsConsumer = termsConsumer.StartTerm(term);
- long totalTF = 0;
- int docID = 0;
- while ((docID = postings.NextDoc()) != DocsEnum.NO_MORE_DOCS)
+ bool doFreq = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0;
+ bool doPos = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0;
+ bool doPayloads = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 && allowPayloads;
+ bool doOffsets = indexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
+
+ TermsConsumer termsConsumer = fieldsConsumer.AddField(fieldInfo);
+ long sumTotalTF = 0;
+ long sumDF = 0;
+ FixedBitSet seenDocs = new FixedBitSet(MaxDoc);
+ foreach (KeyValuePair<BytesRef, long> termEnt in terms)
{
- int freq = postings.Freq;
+ BytesRef term = termEnt.Key;
+ SeedPostings postings = GetSeedPostings(term.Utf8ToString(), termEnt.Value, false, maxAllowed);
if (VERBOSE)
{
- Console.WriteLine(" " + postings.Upto + ": docID=" + docID + " freq=" + postings.Freq_Renamed);
+ Console.WriteLine(" term=" + field + ":" + term.Utf8ToString() + " docFreq=" + postings.DocFreq + " seed=" + termEnt.Value);
}
- postingsConsumer.StartDoc(docID, doFreq ? postings.Freq_Renamed : -1);
- seenDocs.Set(docID);
- if (doPos)
+
+ PostingsConsumer postingsConsumer = termsConsumer.StartTerm(term);
+ long totalTF = 0;
+ int docID = 0;
+ while ((docID = postings.NextDoc()) != DocsEnum.NO_MORE_DOCS)
{
- totalTF += postings.Freq_Renamed;
- for (int posUpto = 0; posUpto < freq; posUpto++)
+ int freq = postings.Freq;
+ if (VERBOSE)
{
- int pos = postings.NextPosition();
- BytesRef payload = postings.GetPayload();
-
- if (VERBOSE)
+ Console.WriteLine(" " + postings.Upto + ": docID=" + docID + " freq=" + postings.Freq_Renamed);
+ }
+ postingsConsumer.StartDoc(docID, doFreq ? postings.Freq_Renamed : -1);
+ seenDocs.Set(docID);
+ if (doPos)
+ {
+ totalTF += postings.Freq_Renamed;
+ for (int posUpto = 0; posUpto < freq; posUpto++)
{
- if (doPayloads)
- {
- Console.WriteLine(" pos=" + pos + " payload=" + (payload == null ? "null" : payload.Length + " bytes"));
- }
- else
+ int pos = postings.NextPosition();
+ BytesRef payload = postings.GetPayload();
+
+ if (VERBOSE)
{
- Console.WriteLine(" pos=" + pos);
+ if (doPayloads)
+ {
+ Console.WriteLine(" pos=" + pos + " payload=" + (payload == null ? "null" : payload.Length + " bytes"));
+ }
+ else
+ {
+ Console.WriteLine(" pos=" + pos);
+ }
}
+ postingsConsumer.AddPosition(pos, doPayloads ? payload : null, doOffsets ? postings.StartOffset : -1, doOffsets ? postings.EndOffset : -1);
}
- postingsConsumer.AddPosition(pos, doPayloads ? payload : null, doOffsets ? postings.StartOffset : -1, doOffsets ? postings.EndOffset : -1);
}
+ else if (doFreq)
+ {
+ totalTF += freq;
+ }
+ else
+ {
+ totalTF++;
+ }
+ postingsConsumer.FinishDoc();
}
- else if (doFreq)
- {
- totalTF += freq;
- }
- else
- {
- totalTF++;
- }
- postingsConsumer.FinishDoc();
+ termsConsumer.FinishTerm(term, new TermStats(postings.DocFreq, doFreq ? totalTF : -1));
+ sumTotalTF += totalTF;
+ sumDF += postings.DocFreq;
}
- termsConsumer.FinishTerm(term, new TermStats(postings.DocFreq, doFreq ? totalTF : -1));
- sumTotalTF += totalTF;
- sumDF += postings.DocFreq;
+
+ termsConsumer.Finish(doFreq ? sumTotalTF : -1, sumDF, seenDocs.Cardinality());
}
- termsConsumer.Finish(doFreq ? sumTotalTF : -1, sumDF, seenDocs.Cardinality());
}
- fieldsConsumer.Dispose();
-
if (VERBOSE)
{
Console.WriteLine("TEST: after indexing: files=");
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/302a51e6/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
index aeaf685..d60fbf2 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/AnalyzingInfixSuggesterTest.cs
@@ -49,38 +49,39 @@ namespace Lucene.Net.Search.Suggest.Analyzing
};
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
-
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(2, results.size());
- assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
-
- assertEquals("lend me your <b>ear</b>", results[1].Key);
- assertEquals(8, results[1].Value);
- assertEquals(new BytesRef("foobar"), results[1].Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("lend me your <b>ear</b>", results[0].Key);
- assertEquals(8, results[0].Value);
- assertEquals(new BytesRef("foobar"), results[0].Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
-
- suggester.Dispose();
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(keys));
+
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(2, results.size());
+ assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ assertEquals("lend me your <b>ear</b>", results[1].Key);
+ assertEquals(8, results[1].Value);
+ assertEquals(new BytesRef("foobar"), results[1].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("lend me your <b>ear</b>", results[0].Key);
+ assertEquals(8, results[0].Value);
+ assertEquals(new BytesRef("foobar"), results[0].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ }
}
[Test]
@@ -95,18 +96,24 @@ namespace Lucene.Net.Search.Suggest.Analyzing
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
- assertEquals(2, suggester.Count);
- suggester.Dispose();
-
- suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(2, results.size());
- assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
- assertEquals(2, suggester.Count);
- suggester.Dispose();
+ try
+ {
+ suggester.Build(new InputArrayIterator(keys));
+ assertEquals(2, suggester.Count);
+ suggester.Dispose();
+
+ suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(2, results.size());
+ assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+ assertEquals(2, suggester.Count);
+ }
+ finally
+ {
+ suggester.Dispose();
+ }
}
/// <summary>
@@ -207,16 +214,17 @@ namespace Lucene.Net.Search.Suggest.Analyzing
};
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new TestHighlightAnalyzingInfixSuggester(this, a);
+ using (AnalyzingInfixSuggester suggester = new TestHighlightAnalyzingInfixSuggester(this, a))
+ {
- suggester.Build(new InputArrayIterator(keys));
+ suggester.Build(new InputArrayIterator(keys));
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a penny saved is a penny <b>ear</b>ned", ToString((List<LookupHighlightFragment>)results[0].HighlightKey));
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
- suggester.Dispose();
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a penny saved is a penny <b>ear</b>ned", ToString((List<LookupHighlightFragment>)results[0].HighlightKey));
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+ }
}
private string ToString(IEnumerable<LookupHighlightFragment> fragments)
@@ -250,82 +258,89 @@ namespace Lucene.Net.Search.Suggest.Analyzing
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
int minPrefixLength = Random().nextInt(10);
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, minPrefixLength);
- suggester.Build(new InputArrayIterator(keys));
-
- for (int i = 0; i < 2; i++)
+ try
{
- for (int j = 0; j < 2; j++)
- {
- bool doHighlight = j == 0;
+ suggester.Build(new InputArrayIterator(keys));
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, doHighlight);
- assertEquals(2, results.size());
- if (doHighlight)
- {
- assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
- }
- else
- {
- assertEquals("a penny saved is a penny earned", results[0].Key);
- }
- assertEquals(10, results[0].Value);
- if (doHighlight)
- {
- assertEquals("lend me your <b>ear</b>", results[1].Key);
- }
- else
+ for (int i = 0; i < 2; i++)
+ {
+ for (int j = 0; j < 2; j++)
{
- assertEquals("lend me your ear", results[1].Key);
- }
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
- assertEquals(8, results[1].Value);
- assertEquals(new BytesRef("foobar"), results[1].Payload);
+ bool doHighlight = j == 0;
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, doHighlight);
- assertEquals(1, results.size());
- if (doHighlight)
- {
- assertEquals("lend me your <b>ear</b>", results[0].Key);
- }
- else
- {
- assertEquals("lend me your ear", results[0].Key);
- }
- assertEquals(8, results[0].Value);
- assertEquals(new BytesRef("foobar"), results[0].Payload);
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, doHighlight);
+ assertEquals(2, results.size());
+ if (doHighlight)
+ {
+ assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
+ }
+ else
+ {
+ assertEquals("a penny saved is a penny earned", results[0].Key);
+ }
+ assertEquals(10, results[0].Value);
+ if (doHighlight)
+ {
+ assertEquals("lend me your <b>ear</b>", results[1].Key);
+ }
+ else
+ {
+ assertEquals("lend me your ear", results[1].Key);
+ }
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+ assertEquals(8, results[1].Value);
+ assertEquals(new BytesRef("foobar"), results[1].Payload);
- results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, doHighlight);
- assertEquals(1, results.size());
- if (doHighlight)
- {
- assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results[0].Key);
- }
- else
- {
- assertEquals("a penny saved is a penny earned", results[0].Key);
- }
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, doHighlight);
+ assertEquals(1, results.size());
+ if (doHighlight)
+ {
+ assertEquals("lend me your <b>ear</b>", results[0].Key);
+ }
+ else
+ {
+ assertEquals("lend me your ear", results[0].Key);
+ }
+ assertEquals(8, results[0].Value);
+ assertEquals(new BytesRef("foobar"), results[0].Payload);
- results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, doHighlight);
- assertEquals(1, results.size());
- if (doHighlight)
- {
- assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results[0].Key);
- }
- else
- {
- assertEquals("a penny saved is a penny earned", results[0].Key);
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, doHighlight);
+ assertEquals(1, results.size());
+ if (doHighlight)
+ {
+ assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results[0].Key);
+ }
+ else
+ {
+ assertEquals("a penny saved is a penny earned", results[0].Key);
+ }
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, doHighlight);
+ assertEquals(1, results.size());
+ if (doHighlight)
+ {
+ assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results[0].Key);
+ }
+ else
+ {
+ assertEquals("a penny saved is a penny earned", results[0].Key);
+ }
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
}
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
- }
- // Make sure things still work after close and reopen:
+ // Make sure things still work after close and reopen:
+ suggester.Dispose();
+ suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, minPrefixLength);
+ }
+ }
+ finally
+ {
suggester.Dispose();
- suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, minPrefixLength);
}
- suggester.Dispose();
+
}
[Test]
@@ -336,12 +351,13 @@ namespace Lucene.Net.Search.Suggest.Analyzing
};
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("penn", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>penn</b>y saved is a <b>penn</b>y earned", results[0].Key);
- suggester.Dispose();
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(keys));
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("penn", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>penn</b>y saved is a <b>penn</b>y earned", results[0].Key);
+ }
}
internal class TestHighlightChangeCaseAnalyzingInfixSuggester : AnalyzingInfixSuggester
@@ -369,22 +385,24 @@ namespace Lucene.Net.Search.Suggest.Analyzing
};
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, true);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("penn", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>Penn</b>y saved is a <b>penn</b>y earned", results[0].Key);
- suggester.Dispose();
+ IList<Lookup.LookupResult> results;
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(keys));
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("penn", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>Penn</b>y saved is a <b>penn</b>y earned", results[0].Key);
+ }
// Try again, but overriding addPrefixMatch to highlight
// the entire hit:
- suggester = new TestHighlightChangeCaseAnalyzingInfixSuggester(this, a);
-
- suggester.Build(new InputArrayIterator(keys));
- results = suggester.DoLookup(TestUtil.StringToCharSequence("penn", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>Penny</b> saved is a <b>penny</b> earned", results[0].Key);
- suggester.Dispose();
+ using (var suggester = new TestHighlightChangeCaseAnalyzingInfixSuggester(this, a))
+ {
+ suggester.Build(new InputArrayIterator(keys));
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("penn", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>Penny</b> saved is a <b>penny</b> earned", results[0].Key);
+ }
}
[Test]
@@ -395,10 +413,11 @@ namespace Lucene.Net.Search.Suggest.Analyzing
};
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
- suggester.Dispose();
- suggester.Dispose();
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(keys));
+ suggester.Dispose();
+ }
}
internal class TestSuggestStopFilterAnalyzer1 : Analyzer
@@ -444,74 +463,77 @@ namespace Lucene.Net.Search.Suggest.Analyzing
Analyzer indexAnalyzer = new TestSuggestStopFilterAnalyzer1(this, stopWords);
Analyzer queryAnalyzer = new TestSuggestStopFilterAnalyzer2(this, stopWords);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), indexAnalyzer, queryAnalyzer, 3);
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), indexAnalyzer, queryAnalyzer, 3))
+ {
- Input[] keys = new Input[] {
- new Input("a bob for apples", 10, new BytesRef("foobaz")),
- };
+ Input[] keys = new Input[] {
+ new Input("a bob for apples", 10, new BytesRef("foobaz")),
+ };
- suggester.Build(new InputArrayIterator(keys));
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("a", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a bob for <b>a</b>pples", results[0].Key);
- suggester.Dispose();
+ suggester.Build(new InputArrayIterator(keys));
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("a", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a bob for <b>a</b>pples", results[0].Key);
+ }
}
[Test]
public void TestEmptyAtStart()
{
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(new Input[0]));
- suggester.Add(new BytesRef("a penny saved is a penny earned"), null, 10, new BytesRef("foobaz"));
- suggester.Add(new BytesRef("lend me your ear"), null, 8, new BytesRef("foobar"));
- suggester.Refresh();
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(2, results.size());
- assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
-
- assertEquals("lend me your <b>ear</b>", results[1].Key);
- assertEquals(8, results[1].Value);
- assertEquals(new BytesRef("foobar"), results[1].Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("lend me your <b>ear</b>", results[0].Key);
- assertEquals(8, results[0].Value);
- assertEquals(new BytesRef("foobar"), results[0].Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
-
- suggester.Dispose();
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(new Input[0]));
+ suggester.Add(new BytesRef("a penny saved is a penny earned"), null, 10, new BytesRef("foobaz"));
+ suggester.Add(new BytesRef("lend me your ear"), null, 8, new BytesRef("foobar"));
+ suggester.Refresh();
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(2, results.size());
+ assertEquals("a penny saved is a penny <b>ear</b>ned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ assertEquals("lend me your <b>ear</b>", results[1].Key);
+ assertEquals(8, results[1].Value);
+ assertEquals(new BytesRef("foobar"), results[1].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("lend me your <b>ear</b>", results[0].Key);
+ assertEquals(8, results[0].Value);
+ assertEquals(new BytesRef("foobar"), results[0].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+
+ }
}
[Test]
public void TestBothExactAndPrefix()
{
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(new Input[0]));
- suggester.Add(new BytesRef("the pen is pretty"), null, 10, new BytesRef("foobaz"));
- suggester.Refresh();
-
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("pen p", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("the <b>pen</b> is <b>p</b>retty", results[0].Key);
- assertEquals(10, results[0].Value);
- assertEquals(new BytesRef("foobaz"), results[0].Payload);
- suggester.Dispose();
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(new Input[0]));
+ suggester.Add(new BytesRef("the pen is pretty"), null, 10, new BytesRef("foobaz"));
+ suggester.Refresh();
+
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("pen p", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("the <b>pen</b> is <b>p</b>retty", results[0].Key);
+ assertEquals(10, results[0].Value);
+ assertEquals(new BytesRef("foobaz"), results[0].Payload);
+ }
}
private static string RandomText()
@@ -628,249 +650,255 @@ namespace Lucene.Net.Search.Suggest.Analyzing
}
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, minPrefixChars);
+ try
+ {
- // Initial suggester built with nothing:
- suggester.Build(new InputArrayIterator(new Input[0]));
+ // Initial suggester built with nothing:
+ suggester.Build(new InputArrayIterator(new Input[0]));
- var stop = new AtomicBoolean(false);
- Exception[] error = new Exception[] { null };
+ var stop = new AtomicBoolean(false);
+ Exception[] error = new Exception[] { null };
- LookupThread lookupThread = new LookupThread(this, suggester, stop, error);
- lookupThread.Start();
+ LookupThread lookupThread = new LookupThread(this, suggester, stop, error);
+ lookupThread.Start();
- int iters = AtLeast(1000);
- int visibleUpto = 0;
+ int iters = AtLeast(1000);
+ int visibleUpto = 0;
- ISet<long> usedWeights = new HashSet<long>();
- ISet<string> usedKeys = new HashSet<string>();
+ ISet<long> usedWeights = new HashSet<long>();
+ ISet<string> usedKeys = new HashSet<string>();
- List<Input> inputs = new List<Input>();
- List<Update> pendingUpdates = new List<Update>();
+ List<Input> inputs = new List<Input>();
+ List<Update> pendingUpdates = new List<Update>();
- for (int iter = 0; iter < iters; iter++)
- {
- string text;
- while (true)
+ for (int iter = 0; iter < iters; iter++)
{
- text = RandomText();
- if (usedKeys.contains(text) == false)
+ string text;
+ while (true)
{
- usedKeys.add(text);
- break;
- }
- }
-
- // Carefully pick a weight we never used, to sidestep
- // tie-break problems:
- long weight;
- while (true)
- {
- weight = Random().nextInt(10 * iters);
- if (usedWeights.contains(weight) == false)
- {
- usedWeights.add(weight);
- break;
+ text = RandomText();
+ if (usedKeys.contains(text) == false)
+ {
+ usedKeys.add(text);
+ break;
+ }
}
- }
- if (inputs.size() > 0 && Random().nextInt(4) == 1)
- {
- // Update an existing suggestion
- Update update = new Update();
- update.index = Random().nextInt(inputs.size());
- update.weight = weight;
- Input input = inputs.ElementAt(update.index);
- pendingUpdates.Add(update);
- if (VERBOSE)
+ // Carefully pick a weight we never used, to sidestep
+ // tie-break problems:
+ long weight;
+ while (true)
{
- Console.WriteLine("TEST: iter=" + iter + " update input=" + input.term.Utf8ToString() + "/" + weight);
+ weight = Random().nextInt(10 * iters);
+ if (usedWeights.contains(weight) == false)
+ {
+ usedWeights.add(weight);
+ break;
+ }
}
- suggester.Update(input.term, null, weight, input.term);
- }
- else
- {
- // Add a new suggestion
- inputs.Add(new Input(text, weight, new BytesRef(text)));
- if (VERBOSE)
+ if (inputs.size() > 0 && Random().nextInt(4) == 1)
{
- Console.WriteLine("TEST: iter=" + iter + " add input=" + text + "/" + weight);
- }
- BytesRef br = new BytesRef(text);
- suggester.Add(br, null, weight, br);
- }
+ // Update an existing suggestion
+ Update update = new Update();
+ update.index = Random().nextInt(inputs.size());
+ update.weight = weight;
+ Input input = inputs.ElementAt(update.index);
+ pendingUpdates.Add(update);
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: iter=" + iter + " update input=" + input.term.Utf8ToString() + "/" + weight);
+ }
+ suggester.Update(input.term, null, weight, input.term);
- if (Random().nextInt(15) == 7)
- {
- if (VERBOSE)
- {
- Console.WriteLine("TEST: now refresh suggester");
}
- suggester.Refresh();
- visibleUpto = inputs.size();
- foreach (Update update in pendingUpdates)
+ else
{
- Input oldInput = inputs.ElementAt(update.index);
- Input newInput = new Input(oldInput.term, update.weight, oldInput.payload);
- inputs[update.index] = newInput;
+ // Add a new suggestion
+ inputs.Add(new Input(text, weight, new BytesRef(text)));
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: iter=" + iter + " add input=" + text + "/" + weight);
+ }
+ BytesRef br = new BytesRef(text);
+ suggester.Add(br, null, weight, br);
}
- pendingUpdates.Clear();
- }
- if (Random().nextInt(50) == 7)
- {
- if (VERBOSE)
+ if (Random().nextInt(15) == 7)
{
- Console.WriteLine("TEST: now close/reopen suggester");
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: now refresh suggester");
+ }
+ suggester.Refresh();
+ visibleUpto = inputs.size();
+ foreach (Update update in pendingUpdates)
+ {
+ Input oldInput = inputs.ElementAt(update.index);
+ Input newInput = new Input(oldInput.term, update.weight, oldInput.payload);
+ inputs[update.index] = newInput;
+ }
+ pendingUpdates.Clear();
}
- //lookupThread.Finish();
- stop.Set(true);
- lookupThread.Join();
- Assert.Null(error[0], "Unexpcted exception at retry : \n" + stackTraceStr(error[0]));
- suggester.Dispose();
- suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, minPrefixChars);
- lookupThread = new LookupThread(this, suggester, stop, error);
- lookupThread.Start();
- visibleUpto = inputs.size();
- foreach (Update update in pendingUpdates)
+ if (Random().nextInt(50) == 7)
{
- Input oldInput = inputs.ElementAt(update.index);
- Input newInput = new Input(oldInput.term, update.weight, oldInput.payload);
- inputs[update.index] = newInput;
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: now close/reopen suggester");
+ }
+ //lookupThread.Finish();
+ stop.Set(true);
+ lookupThread.Join();
+ Assert.Null(error[0], "Unexpcted exception at retry : \n" + stackTraceStr(error[0]));
+ suggester.Dispose();
+ suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, minPrefixChars);
+ lookupThread = new LookupThread(this, suggester, stop, error);
+ lookupThread.Start();
+
+ visibleUpto = inputs.size();
+ foreach (Update update in pendingUpdates)
+ {
+ Input oldInput = inputs.ElementAt(update.index);
+ Input newInput = new Input(oldInput.term, update.weight, oldInput.payload);
+ inputs[update.index] = newInput;
+ }
+ pendingUpdates.Clear();
}
- pendingUpdates.Clear();
- }
- if (visibleUpto > 0)
- {
- string query = RandomText();
- bool lastPrefix = Random().nextInt(5) != 1;
- if (lastPrefix == false)
+ if (visibleUpto > 0)
{
- query += " ";
- }
+ string query = RandomText();
+ bool lastPrefix = Random().nextInt(5) != 1;
+ if (lastPrefix == false)
+ {
+ query += " ";
+ }
- string[] queryTerms = Regex.Split(query, "\\s", RegexOptions.Compiled).TrimEnd();
- bool allTermsRequired = Random().nextInt(10) == 7;
- bool doHilite = Random().nextBoolean();
+ string[] queryTerms = Regex.Split(query, "\\s", RegexOptions.Compiled).TrimEnd();
+ bool allTermsRequired = Random().nextInt(10) == 7;
+ bool doHilite = Random().nextBoolean();
- if (VERBOSE)
- {
- Console.WriteLine("TEST: lookup \"" + query + "\" allTermsRequired=" + allTermsRequired + " doHilite=" + doHilite);
- }
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: lookup \"" + query + "\" allTermsRequired=" + allTermsRequired + " doHilite=" + doHilite);
+ }
- // Stupid slow but hopefully correct matching:
- List<Input> expected = new List<Input>();
- for (int i = 0; i < visibleUpto; i++)
- {
- Input input = inputs.ElementAt(i);
- string[] inputTerms = Regex.Split(input.term.Utf8ToString(), "\\s", RegexOptions.Compiled).TrimEnd();
- bool match = false;
- for (int j = 0; j < queryTerms.Length; j++)
+ // Stupid slow but hopefully correct matching:
+ List<Input> expected = new List<Input>();
+ for (int i = 0; i < visibleUpto; i++)
{
- if (j < queryTerms.Length - 1 || lastPrefix == false)
+ Input input = inputs.ElementAt(i);
+ string[] inputTerms = Regex.Split(input.term.Utf8ToString(), "\\s", RegexOptions.Compiled).TrimEnd();
+ bool match = false;
+ for (int j = 0; j < queryTerms.Length; j++)
{
- // Exact match
- for (int k = 0; k < inputTerms.Length; k++)
+ if (j < queryTerms.Length - 1 || lastPrefix == false)
{
- if (inputTerms[k].Equals(queryTerms[j], StringComparison.Ordinal))
+ // Exact match
+ for (int k = 0; k < inputTerms.Length; k++)
{
- match = true;
- break;
+ if (inputTerms[k].Equals(queryTerms[j], StringComparison.Ordinal))
+ {
+ match = true;
+ break;
+ }
}
}
- }
- else
- {
- // Prefix match
- for (int k = 0; k < inputTerms.Length; k++)
+ else
{
- if (inputTerms[k].StartsWith(queryTerms[j], StringComparison.Ordinal))
+ // Prefix match
+ for (int k = 0; k < inputTerms.Length; k++)
{
- match = true;
+ if (inputTerms[k].StartsWith(queryTerms[j], StringComparison.Ordinal))
+ {
+ match = true;
+ break;
+ }
+ }
+ }
+ if (match)
+ {
+ if (allTermsRequired == false)
+ {
+ // At least one query term does match:
break;
}
+ match = false;
}
- }
- if (match)
- {
- if (allTermsRequired == false)
+ else if (allTermsRequired)
{
- // At least one query term does match:
+ // At least one query term does not match:
break;
}
- match = false;
}
- else if (allTermsRequired)
- {
- // At least one query term does not match:
- break;
- }
- }
- if (match)
- {
- if (doHilite)
- {
- expected.Add(new Input(Hilite(lastPrefix, inputTerms, queryTerms), input.v, input.term));
- }
- else
+ if (match)
{
- expected.Add(input);
+ if (doHilite)
+ {
+ expected.Add(new Input(Hilite(lastPrefix, inputTerms, queryTerms), input.v, input.term));
+ }
+ else
+ {
+ expected.Add(input);
+ }
}
}
- }
- expected.Sort(new TestRandomNRTComparer());
+ expected.Sort(new TestRandomNRTComparer());
- if (expected.Any())
- {
+ if (expected.Any())
+ {
- int topN = TestUtil.NextInt(Random(), 1, expected.size());
+ int topN = TestUtil.NextInt(Random(), 1, expected.size());
- IList<Lookup.LookupResult> actual = suggester.DoLookup(TestUtil.StringToCharSequence(query, Random()).ToString(), topN, allTermsRequired, doHilite);
+ IList<Lookup.LookupResult> actual = suggester.DoLookup(TestUtil.StringToCharSequence(query, Random()).ToString(), topN, allTermsRequired, doHilite);
- int expectedCount = Math.Min(topN, expected.size());
+ int expectedCount = Math.Min(topN, expected.size());
- if (VERBOSE)
- {
- Console.WriteLine(" expected:");
- for (int i = 0; i < expectedCount; i++)
+ if (VERBOSE)
{
- Input x = expected.ElementAt(i);
- Console.WriteLine(" " + x.term.Utf8ToString() + "/" + x.v);
+ Console.WriteLine(" expected:");
+ for (int i = 0; i < expectedCount; i++)
+ {
+ Input x = expected.ElementAt(i);
+ Console.WriteLine(" " + x.term.Utf8ToString() + "/" + x.v);
+ }
+ Console.WriteLine(" actual:");
+ foreach (Lookup.LookupResult result in actual)
+ {
+ Console.WriteLine(" " + result);
+ }
}
- Console.WriteLine(" actual:");
- foreach (Lookup.LookupResult result in actual)
+
+ assertEquals(expectedCount, actual.size());
+ for (int i = 0; i < expectedCount; i++)
{
- Console.WriteLine(" " + result);
+ assertEquals(expected.ElementAt(i).term.Utf8ToString(), actual.ElementAt(i).Key.toString());
+ assertEquals(expected.ElementAt(i).v, actual.ElementAt(i).Value);
+ assertEquals(expected.ElementAt(i).payload, actual.ElementAt(i).Payload);
}
}
-
- assertEquals(expectedCount, actual.size());
- for (int i = 0; i < expectedCount; i++)
+ else
{
- assertEquals(expected.ElementAt(i).term.Utf8ToString(), actual.ElementAt(i).Key.toString());
- assertEquals(expected.ElementAt(i).v, actual.ElementAt(i).Value);
- assertEquals(expected.ElementAt(i).payload, actual.ElementAt(i).Payload);
- }
- }
- else
- {
- if (VERBOSE)
- {
- Console.WriteLine(" no expected matches");
+ if (VERBOSE)
+ {
+ Console.WriteLine(" no expected matches");
+ }
}
}
}
- }
- //lookupThread.finish();
- stop.Set(true);
- lookupThread.Join();
- Assert.Null(error[0], "Unexpcted exception at retry : \n" + stackTraceStr(error[0]));
- suggester.Dispose();
+ //lookupThread.finish();
+ stop.Set(true);
+ lookupThread.Join();
+ Assert.Null(error[0], "Unexpcted exception at retry : \n" + stackTraceStr(error[0]));
+ }
+ finally
+ {
+ suggester.Dispose();
+ }
}
private static string Hilite(bool lastPrefix, string[] inputTerms, string[] queryTerms)
@@ -931,64 +959,65 @@ namespace Lucene.Net.Search.Suggest.Analyzing
};
Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
-
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("lend me your <b>ear</b>", results.ElementAt(0).Key);
- assertEquals(8, results.ElementAt(0).Value);
- assertEquals(new BytesRef("foobar"), results.ElementAt(0).Payload);
-
- // Add a new suggestion:
- suggester.Add(new BytesRef("a penny saved is a penny earned"), null, 10, new BytesRef("foobaz"));
-
- // Must refresh to see any newly added suggestions:
- suggester.Refresh();
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(2, results.size());
- assertEquals("a penny saved is a penny <b>ear</b>ned", results.ElementAt(0).Key);
- assertEquals(10, results.ElementAt(0).Value);
- assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload);
-
- assertEquals("lend me your <b>ear</b>", results.ElementAt(1).Key);
- assertEquals(8, results.ElementAt(1).Value);
- assertEquals(new BytesRef("foobar"), results.ElementAt(1).Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("lend me your <b>ear</b>", results.ElementAt(0).Key);
- assertEquals(8, results.ElementAt(0).Value);
- assertEquals(new BytesRef("foobar"), results.ElementAt(0).Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results.ElementAt(0).Key);
- assertEquals(10, results.ElementAt(0).Value);
- assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload);
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, true);
- assertEquals(1, results.size());
- assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results.ElementAt(0).Key);
- assertEquals(10, results.ElementAt(0).Value);
- assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload);
-
- // Change the weight:
- suggester.Update(new BytesRef("lend me your ear"), null, 12, new BytesRef("foobox"));
-
- // Must refresh to see any newly added suggestions:
- suggester.Refresh();
-
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(2, results.size());
- assertEquals("lend me your <b>ear</b>", results.ElementAt(0).Key);
- assertEquals(12, results.ElementAt(0).Value);
- assertEquals(new BytesRef("foobox"), results.ElementAt(0).Payload);
- assertEquals("a penny saved is a penny <b>ear</b>ned", results.ElementAt(1).Key);
- assertEquals(10, results.ElementAt(1).Value);
- assertEquals(new BytesRef("foobaz"), results.ElementAt(1).Payload);
- suggester.Dispose();
+ using (AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewDirectory(), a, a, 3))
+ {
+ suggester.Build(new InputArrayIterator(keys));
+
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("lend me your <b>ear</b>", results.ElementAt(0).Key);
+ assertEquals(8, results.ElementAt(0).Value);
+ assertEquals(new BytesRef("foobar"), results.ElementAt(0).Payload);
+
+ // Add a new suggestion:
+ suggester.Add(new BytesRef("a penny saved is a penny earned"), null, 10, new BytesRef("foobaz"));
+
+ // Must refresh to see any newly added suggestions:
+ suggester.Refresh();
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(2, results.size());
+ assertEquals("a penny saved is a penny <b>ear</b>ned", results.ElementAt(0).Key);
+ assertEquals(10, results.ElementAt(0).Value);
+ assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload);
+
+ assertEquals("lend me your <b>ear</b>", results.ElementAt(1).Key);
+ assertEquals(8, results.ElementAt(1).Value);
+ assertEquals(new BytesRef("foobar"), results.ElementAt(1).Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear ", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("lend me your <b>ear</b>", results.ElementAt(0).Key);
+ assertEquals(8, results.ElementAt(0).Value);
+ assertEquals(new BytesRef("foobar"), results.ElementAt(0).Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("pen", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>pen</b>ny saved is a <b>pen</b>ny earned", results.ElementAt(0).Key);
+ assertEquals(10, results.ElementAt(0).Value);
+ assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload);
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("p", Random()).ToString(), 10, true, true);
+ assertEquals(1, results.size());
+ assertEquals("a <b>p</b>enny saved is a <b>p</b>enny earned", results.ElementAt(0).Key);
+ assertEquals(10, results.ElementAt(0).Value);
+ assertEquals(new BytesRef("foobaz"), results.ElementAt(0).Payload);
+
+ // Change the weight:
+ suggester.Update(new BytesRef("lend me your ear"), null, 12, new BytesRef("foobox"));
+
+ // Must refresh to see any newly added suggestions:
+ suggester.Refresh();
+
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(2, results.size());
+ assertEquals("lend me your <b>ear</b>", results.ElementAt(0).Key);
+ assertEquals(12, results.ElementAt(0).Value);
+ assertEquals(new BytesRef("foobox"), results.ElementAt(0).Payload);
+ assertEquals("a penny saved is a penny <b>ear</b>ned", results.ElementAt(1).Key);
+ assertEquals(10, results.ElementAt(1).Value);
+ assertEquals(new BytesRef("foobaz"), results.ElementAt(1).Payload);
+ }
}
private IEnumerable<BytesRef> AsSet(params string[] values)
@@ -1015,111 +1044,117 @@ namespace Lucene.Net.Search.Suggest.Analyzing
for (int iter = 0; iter < 2; iter++)
{
- AnalyzingInfixSuggester suggester;
- Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
- if (iter == 0)
- {
- suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
- suggester.Build(new InputArrayIterator(keys));
- }
- else
+ AnalyzingInfixSuggester suggester = null;
+ try
{
- // Test again, after close/reopen:
- suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
- }
-
- // No context provided, all results returned
- IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
- assertEquals(2, results.size());
- Lookup.LookupResult result = results.ElementAt(0);
- assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
- assertEquals(10, result.Value);
- assertEquals(new BytesRef("foobaz"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("baz")));
-
- result = results.ElementAt(1);
- assertEquals("lend me your <b>ear</b>", result.Key);
- assertEquals(8, result.Value);
- assertEquals(new BytesRef("foobar"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("bar")));
-
- // Both suggestions have "foo" context:
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("foo"), 10, true, true);
- assertEquals(2, results.size());
+ Analyzer a = new MockAnalyzer(Random(), MockTokenizer.WHITESPACE, false);
+ if (iter == 0)
+ {
+ suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
+ suggester.Build(new InputArrayIterator(keys));
+ }
+ else
+ {
+ // Test again, after close/reopen:
+ suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, NewFSDirectory(tempDir), a, a, 3);
+ }
- result = results.ElementAt(0);
- assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
- assertEquals(10, result.Value);
- assertEquals(new BytesRef("foobaz"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("baz")));
-
- result = results.ElementAt(1);
- assertEquals("lend me your <b>ear</b>", result.Key);
- assertEquals(8, result.Value);
- assertEquals(new BytesRef("foobar"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("bar")));
-
- // Only one has "bar" context:
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("bar"), 10, true, true);
- assertEquals(1, results.size());
+ // No context provided, all results returned
+ IList<Lookup.LookupResult> results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), 10, true, true);
+ assertEquals(2, results.size());
+ Lookup.LookupResult result = results.ElementAt(0);
+ assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
+ assertEquals(10, result.Value);
+ assertEquals(new BytesRef("foobaz"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("baz")));
+
+ result = results.ElementAt(1);
+ assertEquals("lend me your <b>ear</b>", result.Key);
+ assertEquals(8, result.Value);
+ assertEquals(new BytesRef("foobar"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("bar")));
+
+ // Both suggestions have "foo" context:
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("foo"), 10, true, true);
+ assertEquals(2, results.size());
- result = results.ElementAt(0);
- assertEquals("lend me your <b>ear</b>", result.Key);
- assertEquals(8, result.Value);
- assertEquals(new BytesRef("foobar"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("bar")));
-
- // Only one has "baz" context:
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("baz"), 10, true, true);
- assertEquals(1, results.size());
+ result = results.ElementAt(0);
+ assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
+ assertEquals(10, result.Value);
+ assertEquals(new BytesRef("foobaz"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("baz")));
+
+ result = results.ElementAt(1);
+ assertEquals("lend me your <b>ear</b>", result.Key);
+ assertEquals(8, result.Value);
+ assertEquals(new BytesRef("foobar"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("bar")));
+
+ // Only one has "bar" context:
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("bar"), 10, true, true);
+ assertEquals(1, results.size());
- result = results.ElementAt(0);
- assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
- assertEquals(10, result.Value);
- assertEquals(new BytesRef("foobaz"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("baz")));
-
- // Both have foo or bar:
- results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("foo", "bar"), 10, true, true);
- assertEquals(2, results.size());
+ result = results.ElementAt(0);
+ assertEquals("lend me your <b>ear</b>", result.Key);
+ assertEquals(8, result.Value);
+ assertEquals(new BytesRef("foobar"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("bar")));
+
+ // Only one has "baz" context:
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("baz"), 10, true, true);
+ assertEquals(1, results.size());
- result = results.ElementAt(0);
- assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
- assertEquals(10, result.Value);
- assertEquals(new BytesRef("foobaz"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("baz")));
-
- result = results.ElementAt(1);
- assertEquals("lend me your <b>ear</b>", result.Key);
- assertEquals(8, result.Value);
- assertEquals(new BytesRef("foobar"), result.Payload);
- assertNotNull(result.Contexts);
- assertEquals(2, result.Contexts.Count());
- assertTrue(result.Contexts.Contains(new BytesRef("foo")));
- assertTrue(result.Contexts.Contains(new BytesRef("bar")));
+ result = results.ElementAt(0);
+ assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
+ assertEquals(10, result.Value);
+ assertEquals(new BytesRef("foobaz"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("baz")));
+
+ // Both have foo or bar:
+ results = suggester.DoLookup(TestUtil.StringToCharSequence("ear", Random()).ToString(), AsSet("foo", "bar"), 10, true, true);
+ assertEquals(2, results.size());
- suggester.Dispose();
+ result = results.ElementAt(0);
+ assertEquals("a penny saved is a penny <b>ear</b>ned", result.Key);
+ assertEquals(10, result.Value);
+ assertEquals(new BytesRef("foobaz"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("baz")));
+
+ result = results.ElementAt(1);
+ assertEquals("lend me your <b>ear</b>", result.Key);
+ assertEquals(8, result.Value);
+ assertEquals(new BytesRef("foobar"), result.Payload);
+ assertNotNull(result.Contexts);
+ assertEquals(2, result.Contexts.Count());
+ assertTrue(result.Contexts.Contains(new BytesRef("foo")));
+ assertTrue(result.Contexts.Contains(new BytesRef("bar")));
+ }
+ finally
+ {
+ if (suggester != null)
+ suggester.Dispose();
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/302a51e6/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
index e578824..03bd5be 100644
--- a/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
+++ b/src/Lucene.Net.Tests.Suggest/Suggest/Analyzing/TestFreeTextSuggester.cs
@@ -69,18 +69,18 @@ namespace Lucene.Net.Search.Suggest.Analyzing
// Try again after save/load:
DirectoryInfo tmpDir = CreateTempDir("FreeTextSuggesterTest");
- tmpDir.Create();
+ //tmpDir.Create();
FileInfo path = new FileInfo(Path.Combine(tmpDir.FullName, "suggester"));
- Stream os = new FileStream(path.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- sug.Store(os);
- os.Dispose();
+ using (Stream os = new FileStream(path.FullName, FileMode.Create, FileAccess.Write))
+ sug.Store(os);
- Stream @is = new FileStream(path.FullName, FileMode.Open);
- sug = new FreeTextSuggester(a, a, 2, (byte)0x20);
- sug.Load(@is);
- @is.Dispose();
+ using (Stream @is = new FileStream(path.FullName, FileMode.Open, FileAccess.Read))
+ {
+ sug = new FreeTextSuggester(a, a, 2, (byte)0x20);
+ sug.Load(@is);
+ }
assertEquals(2, sug.Count);
}
}
[07/11] lucenenet git commit:
Lucene.Net.Suggest.Analyzing.FreeTextSuggester: Changed to use
Path.GetRandomFileName() instead of using random integers to make the file
name. Changed to delete the folder using System.IO.Directory.Delete and
rearranged try
Posted by ni...@apache.org.
Lucene.Net.Suggest.Analyzing.FreeTextSuggester: Changed to use Path.GetRandomFileName() instead of using random integers to make the file name. Changed to delete the folder using System.IO.Directory.Delete and rearranged try catch statements so the Lucene Directory disposes before deleting the OS directory.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/063f384a
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/063f384a
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/063f384a
Branch: refs/heads/master
Commit: 063f384a26fe094f57580e727d2c7a7dc87d7931
Parents: ffaa021
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Fri Sep 22 00:24:57 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Fri Sep 22 12:45:44 2017 +0700
----------------------------------------------------------------------
.../Suggest/Analyzing/FreeTextSuggester.cs | 66 +++++++++-----------
1 file changed, 30 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/063f384a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
index 31b7839..bd7e038 100644
--- a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
+++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
@@ -308,13 +308,12 @@ namespace Lucene.Net.Search.Suggest.Analyzing
string prefix = this.GetType().Name;
var directory = OfflineSorter.DefaultTempDir();
- // TODO: messy ... java7 has Files.createTempDirectory
- // ... but 4.x is java6:
+
+ // LUCENENET specific - using GetRandomFileName() instead of picking a random int
DirectoryInfo tempIndexPath = null;
- Random random = new Random();
while (true)
{
- tempIndexPath = new DirectoryInfo(Path.Combine(directory.FullName, prefix + ".index." + random.Next(int.MaxValue)));
+ tempIndexPath = new DirectoryInfo(Path.Combine(directory.FullName, prefix + ".index." + Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));
tempIndexPath.Create();
if (System.IO.Directory.Exists(tempIndexPath.FullName))
{
@@ -322,7 +321,8 @@ namespace Lucene.Net.Search.Suggest.Analyzing
}
}
- using (Directory dir = FSDirectory.Open(tempIndexPath))
+ Directory dir = FSDirectory.Open(tempIndexPath);
+ try
{
#pragma warning disable 612, 618
IndexWriterConfig iwc = new IndexWriterConfig(LuceneVersion.LUCENE_CURRENT, indexAnalyzer);
@@ -411,41 +411,35 @@ namespace Lucene.Net.Search.Suggest.Analyzing
}
finally
{
+ if (success)
+ {
+ IOUtils.Dispose(writer, reader);
+ }
+ else
+ {
+ IOUtils.DisposeWhileHandlingException(writer, reader);
+ }
+ }
+ }
+ finally
+ {
+ try
+ {
+ IOUtils.Dispose(dir);
+ }
+ finally
+ {
+ // LUCENENET specific - since we are removing the entire directory anyway,
+ // it doesn't make sense to first do a loop in order remove the files.
+ // Let the System.IO.Directory.Delete() method handle that.
+ // We also need to dispose the Directory instance first before deleting from disk.
try
{
- if (success)
- {
- IOUtils.Dispose(writer, reader);
- }
- else
- {
- IOUtils.DisposeWhileHandlingException(writer, reader);
- }
+ System.IO.Directory.Delete(tempIndexPath.FullName, true);
}
- finally
+ catch (Exception e)
{
- foreach (string file in dir.ListAll())
- {
- FileInfo path = new FileInfo(Path.Combine(tempIndexPath.FullName, file));
- try
- {
- path.Delete();
- }
- catch (Exception e)
- {
- throw new InvalidOperationException("failed to remove " + path, e);
- }
- }
-
- try
- {
- tempIndexPath.Delete();
- }
- catch (Exception e)
- {
- throw new InvalidOperationException("failed to remove " + tempIndexPath, e);
- }
-
+ throw new InvalidOperationException("failed to remove " + tempIndexPath, e);
}
}
}
[09/11] lucenenet git commit:
Lucene.Net.TestFramework.Index.BasePostingsFormatTestCase +
Lucene.Net.Suggest.Analyzing (AnalyzingInfixSuggesterTest +
TestFreeTextSuggester) + Lucene.Net.Tests.Index.TestCodecs: Added using
blocks to make the tests run mor
Posted by ni...@apache.org.
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/302a51e6/src/Lucene.Net.Tests/Index/TestCodecs.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestCodecs.cs b/src/Lucene.Net.Tests/Index/TestCodecs.cs
index c222008..c3a294d 100644
--- a/src/Lucene.Net.Tests/Index/TestCodecs.cs
+++ b/src/Lucene.Net.Tests/Index/TestCodecs.cs
@@ -380,49 +380,52 @@ namespace Lucene.Net.Index
FieldData field = new FieldData(this, "field", builder, terms, true, false);
FieldData[] fields = new FieldData[] { field };
FieldInfos fieldInfos = builder.Finish();
- Directory dir = NewDirectory();
- this.Write(fieldInfos, dir, fields, true);
- Codec codec = Codec.Default;
- SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
+ // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
+ using (Directory dir = NewDirectory())
+ {
+ this.Write(fieldInfos, dir, fields, true);
+ Codec codec = Codec.Default;
+ SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
- FieldsProducer reader = codec.PostingsFormat.FieldsProducer(new SegmentReadState(dir, si, fieldInfos, NewIOContext(Random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR));
+ // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
+ using (FieldsProducer reader = codec.PostingsFormat.FieldsProducer(new SegmentReadState(dir, si, fieldInfos, NewIOContext(Random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR)))
+ {
+ IEnumerator<string> fieldsEnum = reader.GetEnumerator();
+ fieldsEnum.MoveNext();
+ string fieldName = fieldsEnum.Current;
+ Assert.IsNotNull(fieldName);
+ Terms terms2 = reader.GetTerms(fieldName);
+ Assert.IsNotNull(terms2);
- IEnumerator<string> fieldsEnum = reader.GetEnumerator();
- fieldsEnum.MoveNext();
- string fieldName = fieldsEnum.Current;
- Assert.IsNotNull(fieldName);
- Terms terms2 = reader.GetTerms(fieldName);
- Assert.IsNotNull(terms2);
+ TermsEnum termsEnum = terms2.GetIterator(null);
- TermsEnum termsEnum = terms2.GetIterator(null);
+ DocsEnum docsEnum = null;
+ for (int i = 0; i < NUM_TERMS; i++)
+ {
+ BytesRef term = termsEnum.Next();
+ Assert.IsNotNull(term);
+ Assert.AreEqual(terms[i].Text2, term.Utf8ToString());
- DocsEnum docsEnum = null;
- for (int i = 0; i < NUM_TERMS; i++)
- {
- BytesRef term = termsEnum.Next();
- Assert.IsNotNull(term);
- Assert.AreEqual(terms[i].Text2, term.Utf8ToString());
+ // do this twice to stress test the codec's reuse, ie,
+ // make sure it properly fully resets (rewinds) its
+ // internal state:
+ for (int iter = 0; iter < 2; iter++)
+ {
+ docsEnum = TestUtil.Docs(Random(), termsEnum, null, docsEnum, DocsFlags.NONE);
+ Assert.AreEqual(terms[i].Docs[0], docsEnum.NextDoc());
+ Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, docsEnum.NextDoc());
+ }
+ }
+ Assert.IsNull(termsEnum.Next());
- // do this twice to stress test the codec's reuse, ie,
- // make sure it properly fully resets (rewinds) its
- // internal state:
- for (int iter = 0; iter < 2; iter++)
- {
- docsEnum = TestUtil.Docs(Random(), termsEnum, null, docsEnum, DocsFlags.NONE);
- Assert.AreEqual(terms[i].Docs[0], docsEnum.NextDoc());
- Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, docsEnum.NextDoc());
- }
- }
- Assert.IsNull(termsEnum.Next());
+ for (int i = 0; i < NUM_TERMS; i++)
+ {
+ Assert.AreEqual(termsEnum.SeekCeil(new BytesRef(terms[i].Text2)), TermsEnum.SeekStatus.FOUND);
+ }
- for (int i = 0; i < NUM_TERMS; i++)
- {
- Assert.AreEqual(termsEnum.SeekCeil(new BytesRef(terms[i].Text2)), TermsEnum.SeekStatus.FOUND);
+ Assert.IsFalse(fieldsEnum.MoveNext());
+ }
}
-
- Assert.IsFalse(fieldsEnum.MoveNext());
- reader.Dispose();
- dir.Dispose();
}
[Test]
@@ -438,42 +441,47 @@ namespace Lucene.Net.Index
fields[i] = new FieldData(this, FieldNames[i], builder, this.MakeRandomTerms(omitTF, storePayloads), omitTF, storePayloads);
}
- Directory dir = NewDirectory();
- FieldInfos fieldInfos = builder.Finish();
-
- if (VERBOSE)
+ // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
+ using (Directory dir = NewDirectory())
{
- Console.WriteLine("TEST: now write postings");
- }
+ FieldInfos fieldInfos = builder.Finish();
- this.Write(fieldInfos, dir, fields, false);
- Codec codec = Codec.Default;
- SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: now write postings");
+ }
- if (VERBOSE)
- {
- Console.WriteLine("TEST: now read postings");
- }
- FieldsProducer terms = codec.PostingsFormat.FieldsProducer(new SegmentReadState(dir, si, fieldInfos, NewIOContext(Random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR));
+ this.Write(fieldInfos, dir, fields, false);
+ Codec codec = Codec.Default;
+ SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
- Verify[] threads = new Verify[NUM_TEST_THREADS - 1];
- for (int i = 0; i < NUM_TEST_THREADS - 1; i++)
- {
- threads[i] = new Verify(this, si, fields, terms);
- threads[i].SetDaemon(true);
- threads[i].Start();
- }
+ if (VERBOSE)
+ {
+ Console.WriteLine("TEST: now read postings");
+ }
- (new Verify(this, si, fields, terms)).Run();
+ // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
+ using (FieldsProducer terms = codec.PostingsFormat.FieldsProducer(new SegmentReadState(dir, si, fieldInfos, NewIOContext(Random()), DirectoryReader.DEFAULT_TERMS_INDEX_DIVISOR)))
+ {
- for (int i = 0; i < NUM_TEST_THREADS - 1; i++)
- {
- threads[i].Join();
- Debug.Assert(!threads[i].Failed);
- }
+ Verify[] threads = new Verify[NUM_TEST_THREADS - 1];
+ for (int i = 0; i < NUM_TEST_THREADS - 1; i++)
+ {
+ threads[i] = new Verify(this, si, fields, terms);
+ threads[i].SetDaemon(true);
+ threads[i].Start();
+ }
+
+ (new Verify(this, si, fields, terms)).Run();
+
+ for (int i = 0; i < NUM_TEST_THREADS - 1; i++)
+ {
+ threads[i].Join();
+ Debug.Assert(!threads[i].Failed);
+ }
- terms.Dispose();
- dir.Dispose();
+ }
+ }
}
[Test]
@@ -834,20 +842,22 @@ namespace Lucene.Net.Index
SegmentInfo si = new SegmentInfo(dir, Constants.LUCENE_MAIN_VERSION, SEGMENT, 10000, false, codec, null);
SegmentWriteState state = new SegmentWriteState(InfoStream.Default, dir, si, fieldInfos, termIndexInterval, null, NewIOContext(Random()));
- FieldsConsumer consumer = codec.PostingsFormat.FieldsConsumer(state);
- Array.Sort(fields);
- foreach (FieldData field in fields)
+ // LUCENENET specific - BUG: we must wrap this in a using block in case anything in the below loop throws
+ using (FieldsConsumer consumer = codec.PostingsFormat.FieldsConsumer(state))
{
+ Array.Sort(fields);
+ foreach (FieldData field in fields)
+ {
#pragma warning disable 612, 618
- if (!allowPreFlex && codec is Lucene3xCodec)
+ if (!allowPreFlex && codec is Lucene3xCodec)
#pragma warning restore 612, 618
- {
- // code below expects unicode sort order
- continue;
+ {
+ // code below expects unicode sort order
+ continue;
+ }
+ field.Write(consumer);
}
- field.Write(consumer);
}
- consumer.Dispose();
}
[Test]
@@ -855,66 +865,70 @@ namespace Lucene.Net.Index
{
// tests that when fields are indexed with DOCS_ONLY, the Codec
// returns 1 in docsEnum.Freq()
- Directory dir = NewDirectory();
- Random random = Random();
- IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
- // we don't need many documents to assert this, but don't use one document either
- int numDocs = AtLeast(random, 50);
- for (int i = 0; i < numDocs; i++)
+ using (Directory dir = NewDirectory())
{
- Document doc = new Document();
- doc.Add(new StringField("f", "doc", Store.NO));
- writer.AddDocument(doc);
- }
- writer.Dispose();
+ Random random = Random();
+ using (IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))))
+ {
+ // we don't need many documents to assert this, but don't use one document either
+ int numDocs = AtLeast(random, 50);
+ for (int i = 0; i < numDocs; i++)
+ {
+ Document doc = new Document();
+ doc.Add(new StringField("f", "doc", Store.NO));
+ writer.AddDocument(doc);
+ }
+ }
- Term term = new Term("f", new BytesRef("doc"));
- DirectoryReader reader = DirectoryReader.Open(dir);
- foreach (AtomicReaderContext ctx in reader.Leaves)
- {
- DocsEnum de = ((AtomicReader)ctx.Reader).GetTermDocsEnum(term);
- while (de.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
+ Term term = new Term("f", new BytesRef("doc"));
+ using (DirectoryReader reader = DirectoryReader.Open(dir))
{
- Assert.AreEqual(1, de.Freq, "wrong freq for doc " + de.DocID);
+ foreach (AtomicReaderContext ctx in reader.Leaves)
+ {
+ DocsEnum de = ((AtomicReader)ctx.Reader).GetTermDocsEnum(term);
+ while (de.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
+ {
+ Assert.AreEqual(1, de.Freq, "wrong freq for doc " + de.DocID);
+ }
+ }
}
- }
- reader.Dispose();
- dir.Dispose();
+ }
}
[Test]
public virtual void TestDisableImpersonation()
{
Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(), new Lucene42RWCodec() };
- Directory dir = NewDirectory();
- IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
- conf.SetCodec(oldCodecs[Random().Next(oldCodecs.Length)]);
- IndexWriter writer = new IndexWriter(dir, conf);
+ using (Directory dir = NewDirectory())
+ {
+ IndexWriterConfig conf = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
+ conf.SetCodec(oldCodecs[Random().Next(oldCodecs.Length)]);
+ IndexWriter writer = new IndexWriter(dir, conf);
- Document doc = new Document();
- doc.Add(new StringField("f", "bar", Store.YES));
- doc.Add(new NumericDocValuesField("n", 18L));
- writer.AddDocument(doc);
+ Document doc = new Document();
+ doc.Add(new StringField("f", "bar", Store.YES));
+ doc.Add(new NumericDocValuesField("n", 18L));
+ writer.AddDocument(doc);
- OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
- try
- {
- writer.Dispose();
- Assert.Fail("should not have succeeded to impersonate an old format!");
- }
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
+ try
+ {
+ writer.Dispose();
+ Assert.Fail("should not have succeeded to impersonate an old format!");
+ }
#pragma warning disable 168
- catch (System.NotSupportedException e)
+ catch (System.NotSupportedException e)
#pragma warning restore 168
- {
- writer.Rollback();
- }
- finally
- {
- OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
- }
+ {
+ writer.Rollback();
+ }
+ finally
+ {
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+ }
- dir.Dispose();
+ }
}
}
}
\ No newline at end of file