Skip to content

Commit

Permalink
Completed work for Issue apache#916 - Conversion to native Array.Empt…
Browse files Browse the repository at this point in the history
…y<T>() (apache#953)

* Completed work for Issue apache#916

Removed ```Lucene.Net.Support.Arrays.Empty<T>()``` and ```FEATURE_ARRAYEMPTY```.
Converted all ```Arrays.Empty<T>()``` to ```Array.Empty<T>()``` and added ```using System;``` where required.
Removed ```using Lucene.Net.Support;``` statements that were no longer required.

* Issue apache#916 - Rectified Pull Request Issues

Rectified Pull request issues as identified by NightOwl888:
 - Removed to missed references to `FEATURE_ARRAYEMPTY'
 - Reverted `FieldComparator.cs` back to original state
 - Corrected sort order for using statements
 - Reverted indentation on `JavascriptLexer.cs`
  • Loading branch information
J-Exodus authored Aug 13, 2024
1 parent d3e7bf9 commit 09a6de9
Show file tree
Hide file tree
Showing 73 changed files with 477 additions and 528 deletions.
8 changes: 0 additions & 8 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
<PropertyGroup Condition=" $(TargetFramework.StartsWith('netstandard')) Or $(TargetFramework.StartsWith('netcoreapp')) Or $(TargetFramework.StartsWith('net5.')) Or $(TargetFramework.StartsWith('net6.')) Or $(TargetFramework.StartsWith('net7.')) Or $(TargetFramework.StartsWith('net8.')) ">

<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ARRAYEMPTY</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_CULTUREINFO_CURRENTCULTURE_SETTER</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_ENCODINGPROVIDERS</DefineConstants>

Expand Down Expand Up @@ -113,13 +112,6 @@

</PropertyGroup>

<!-- Features in .NET Framework 4.6+ only -->
<PropertyGroup Condition="$(TargetFramework.StartsWith('net46')) Or $(TargetFramework.StartsWith('net47')) Or $(TargetFramework.StartsWith('net48'))">

<DefineConstants>$(DefineConstants);FEATURE_ARRAYEMPTY</DefineConstants>

</PropertyGroup>

<!-- Features in .NET Framework 4.5+ -->
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Lucene version compatibility level 4.8.1
using J2N.Numerics;
using Lucene.Net.Diagnostics;
using Lucene.Net.Support;
using Lucene.Net.Util;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -129,4 +128,4 @@ protected virtual void AddOffCorrectMap(int off, int cumulativeDiff)
}
}
}
}
}
14 changes: 7 additions & 7 deletions src/Lucene.Net.Analysis.Common/Analysis/Hunspell/Dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Lucene.Net.Analysis.Hunspell
/// </summary>
public class Dictionary
{
private static readonly char[] NOFLAGS = Arrays.Empty<char>();
private static readonly char[] NOFLAGS = Array.Empty<char>();

private const string ALIAS_KEY = "AF";
private const string MORPH_ALIAS_KEY = "AM";
Expand Down Expand Up @@ -153,7 +153,7 @@ public class Dictionary
/// <param name="dictionary"> <see cref="Stream"/> for reading the hunspell dictionary file (won't be disposed). </param>
/// <exception cref="IOException"> Can be thrown while reading from the <see cref="Stream"/>s </exception>
/// <exception cref="Exception"> Can be thrown if the content of the files does not meet expected formats </exception>
public Dictionary(Stream affix, Stream dictionary)
public Dictionary(Stream affix, Stream dictionary)
: this(affix, new JCG.List<Stream>() { dictionary }, false)
{
}
Expand Down Expand Up @@ -752,12 +752,12 @@ private static Encoding GetSystemEncoding(string encoding) // LUCENENET: CA1822:
}
// .NET doesn't recognize the encoding without a dash between ISO and the number
// https://msdn.microsoft.com/en-us/library/system.text.encodinginfo.getencoding(v=vs.110).aspx
if (encoding.Length > 3 && encoding.StartsWith("ISO", StringComparison.OrdinalIgnoreCase) &&
if (encoding.Length > 3 && encoding.StartsWith("ISO", StringComparison.OrdinalIgnoreCase) &&
encoding[3] != '-')
{
encoding = "iso-" + encoding.Substring(3);
}
// Special case - for codepage 1250-1258, we need to change to
// Special case - for codepage 1250-1258, we need to change to
// windows-1251, etc.
else if (windowsCodePagePattern.IsMatch(encoding))
{
Expand Down Expand Up @@ -1285,7 +1285,7 @@ internal override char[] ParseFlags(string rawFlags)

for (int i = 0; i < rawFlagParts.Length; i++)
{
// note, removing the trailing X/leading I for nepali... what is the rule here?!
// note, removing the trailing X/leading I for nepali... what is the rule here?!
string replacement = leadingDigitPattern.Replace(rawFlagParts[i], "");
// note, ignoring empty flags (this happens in danish, for example)
if (replacement.Length == 0)
Expand Down Expand Up @@ -1313,7 +1313,7 @@ internal override char[] ParseFlags(string rawFlags)
{
if (rawFlags.Length == 0)
{
return Arrays.Empty<char>(); // LUCENENET: Optimized char[] creation
return Array.Empty<char>(); // LUCENENET: Optimized char[] creation
}

StringBuilder builder = new StringBuilder();
Expand Down Expand Up @@ -1458,4 +1458,4 @@ internal static void ApplyMappings(FST<CharsRef> fst, StringBuilder sb)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using Lucene.Net.Analysis.Core;
using Lucene.Net.Analysis.Util;
using Lucene.Net.Index;
using Lucene.Net.Support;
using Lucene.Net.Util;
using System;
using System.Collections.Generic;
using System.IO;
using JCG = J2N.Collections.Generic;
Expand All @@ -30,11 +30,11 @@ namespace Lucene.Net.Analysis.Query

/// <summary>
/// An <see cref="Analyzer"/> used primarily at query time to wrap another analyzer and provide a layer of protection
/// which prevents very common words from being passed into queries.
/// which prevents very common words from being passed into queries.
/// <para>
/// For very large indexes the cost
/// of reading TermDocs for a very common word can be high. This analyzer was created after experience with
/// a 38 million doc index which had a term in around 50% of docs and was causing TermQueries for
/// a 38 million doc index which had a term in around 50% of docs and was causing TermQueries for
/// this term to take 2 seconds.
/// </para>
/// </summary>
Expand Down Expand Up @@ -169,9 +169,9 @@ protected override TokenStreamComponents WrapComponents(string fieldName, TokenS
/// method calls will be returned </param>
/// <returns> the stop words identified for a field </returns>
public string[] GetStopWords(string fieldName)
{
{
var stopWords = stopWordsPerField[fieldName];
return stopWords != null ? stopWords.ToArray() : Arrays.Empty<string>();
return stopWords != null ? stopWords.ToArray() : Array.Empty<string>();
}

/// <summary>
Expand All @@ -192,4 +192,4 @@ public Term[] GetStopWords()
return allStopWords.ToArray();
}
}
}
}
33 changes: 16 additions & 17 deletions src/Lucene.Net.Analysis.Common/Analysis/Shingle/ShingleFilter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Lucene version compatibility level 4.8.1
using Lucene.Net.Analysis.TokenAttributes;
using Lucene.Net.Support;
using Lucene.Net.Util;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -29,12 +28,12 @@ namespace Lucene.Net.Analysis.Shingle
/// <summary>
/// <para>A <see cref="ShingleFilter"/> constructs shingles (token n-grams) from a token stream.
/// In other words, it creates combinations of tokens as a single token.
///
///
/// </para>
/// <para>For example, the sentence "please divide this sentence into shingles"
/// might be tokenized into shingles "please divide", "divide this",
/// "this sentence", "sentence into", and "into shingles".
///
///
/// </para>
/// <para>This filter handles position increments > 1 by inserting filler tokens
/// (tokens with termtext "_"). It does not handle a position increment of 0.
Expand All @@ -58,7 +57,7 @@ public sealed class ShingleFilter : TokenFilter
public const int DEFAULT_MIN_SHINGLE_SIZE = 2;

/// <summary>
/// default token type attribute value is "shingle"
/// default token type attribute value is "shingle"
/// </summary>
public const string DEFAULT_TOKEN_TYPE = "shingle";

Expand Down Expand Up @@ -131,7 +130,7 @@ public sealed class ShingleFilter : TokenFilter
/// <summary>
/// When the next input stream token has a position increment greater than
/// one, it is stored in this field until sufficient filler tokens have been
/// inserted to account for the position increment.
/// inserted to account for the position increment.
/// </summary>
private AttributeSource nextInputStreamToken;

Expand All @@ -141,7 +140,7 @@ public sealed class ShingleFilter : TokenFilter
private bool isNextInputStreamToken = false;

/// <summary>
/// Whether at least one unigram or shingle has been output at the current
/// Whether at least one unigram or shingle has been output at the current
/// position.
/// </summary>
private bool isOutputHere = false;
Expand Down Expand Up @@ -244,7 +243,7 @@ public void SetOutputUnigrams(bool outputUnigrams)
/// </para>
/// <para>Note that if outputUnigrams==true, then unigrams are always output,
/// regardless of whether any shingles are available.
///
///
/// </para>
/// </summary>
/// <param name="outputUnigramsIfNoShingles"> Whether or not to output a single
Expand Down Expand Up @@ -275,7 +274,7 @@ public void SetMaxShingleSize(int maxShingleSize)
/// calling this method.
/// </para>
/// <para>The unigram output option is independent of the min shingle size.
///
///
/// </para>
/// </summary>
/// <param name="minShingleSize"> min size of output shingles </param>
Expand Down Expand Up @@ -308,7 +307,7 @@ public void SetTokenSeparator(string tokenSeparator)
/// <param name="fillerToken"> string to insert at each position where there is no token </param>
public void SetFillerToken(string fillerToken)
{
this.fillerToken = null == fillerToken ? Arrays.Empty<char>() : fillerToken.ToCharArray();
this.fillerToken = null == fillerToken ? Array.Empty<char>() : fillerToken.ToCharArray();
}

public override bool IncrementToken()
Expand Down Expand Up @@ -434,7 +433,7 @@ private InputWindowToken GetNextToken(InputWindowToken target)
}
if (posIncrAtt.PositionIncrement > 1)
{
// Each output shingle must contain at least one input token,
// Each output shingle must contain at least one input token,
// so no more than (maxShingleSize - 1) filler tokens will be inserted.
numFillerTokensToInsert = Math.Min(posIncrAtt.PositionIncrement - 1, maxShingleSize - 1);
// Save the current token as the next input stream token
Expand Down Expand Up @@ -499,7 +498,7 @@ public override void End()
}

/// <summary>
/// <para>Fills <see cref="inputWindow"/> with input stream tokens, if available,
/// <para>Fills <see cref="inputWindow"/> with input stream tokens, if available,
/// shifting to the right if the window was previously full.
/// </para>
/// <para>
Expand Down Expand Up @@ -577,7 +576,7 @@ public override void Reset()
/// <para><code>gramSize</code> will take on values from the circular sequence
/// <b>{ [ 1, ] <see cref="minShingleSize"/> [ , ... , <see cref="maxShingleSize"/> ] }</b>.
/// </para>
/// <para>1 is included in the circular sequence only if
/// <para>1 is included in the circular sequence only if
/// <see cref="outputUnigrams"/> = true.
/// </para>
/// </summary>
Expand Down Expand Up @@ -606,7 +605,7 @@ public CircularSequence(ShingleFilter shingleFilter)
/// <code>gramSize</code> will take on values from the circular sequence
/// <b>{ [ 1, ] <see cref="minShingleSize"/> [ , ... , <see cref="maxShingleSize"/> ] }</b>.
/// </para>
/// <para>1 is included in the circular sequence only if
/// <para>1 is included in the circular sequence only if
/// <see cref="outputUnigrams"/> = true.
/// </para>
/// </summary>
Expand All @@ -628,13 +627,13 @@ public virtual void Advance()
}

/// <summary>
/// <para>Sets this circular number's value to the first member of the
/// <para>Sets this circular number's value to the first member of the
/// circular sequence
/// </para>
/// <para><code>gramSize</code> will take on values from the circular sequence
/// <b>{ [ 1, ] <see cref="minShingleSize"/> [ , ... , <see cref="maxShingleSize"/> ] }</b>.
/// </para>
/// <para>1 is included in the circular sequence only if
/// <para>1 is included in the circular sequence only if
/// <see cref="outputUnigrams"/> = true.
/// </para>
/// </summary>
Expand All @@ -650,7 +649,7 @@ public void Reset()
/// </para>
/// <para>If <see cref="outputUnigrams"/> = true, the first member of the circular
/// sequence will be 1; otherwise, it will be <see cref="minShingleSize"/>.
///
///
/// </para>
/// </summary>
/// <returns> true if the current value is the first member of the circular
Expand Down Expand Up @@ -685,4 +684,4 @@ public InputWindowToken(AttributeSource attSource)
}
}
}
}
}
Loading

0 comments on commit 09a6de9

Please sign in to comment.