Fixes several code quality issues (Code Analysis) (#387)

* BUG: Lucene.Net.Document.CompressionTools: Pass the offset and length to the underlying MemoryStream

* BUG: Lucene.Net.Analysis.Common.Tartarus.Snowball.Among: Fixed MethodObject property to reference private field instead of itself

* BUG: Lucene.Net.TestFramework.Analysis.MockTokenizer: Pass the AttributeFactory argument that is provided as per the documentation comment. Note this bug exists in Lucene 4.8.0, also.

* TestTargetFramework.props: Disable IDE0052 and IDE0060 in test projects

* lucene-cli: Disabled IDE0060 warnings

* Lucene.Net.Demo: Disabled IDE0060 warnings

* PERFORMANCE: Fixes IDE0052 Remove unread private member, fixes IDE0060 Remove unused parameter

* BUG: Lucene.Net.Util.ExceptionExtensions.GetSuppressedAsList(): Use J2N.Collections.Generic.List<T> so the call to ToString() will automatically list the exception messages

* Lucene.Net.Tests.Support.TestApiConsistency: Added exclusion for System.Runtime.CompilerServices to skip our nullable attribute replacements for platforms that don't support them

* Fixes CA2213 Disposable fields should be disposed (except for IndexWriter and subclasses which need more work)

* Fixes CA1063: Implement IDisposable Properly (except for IndexWriter). Partially addresses #265.

* PERFORMANCE: Lucene.Net.Index: Changed FieldInfos, FreqProxTermsWriterPerField, IndexWriter, LogMergePolicy, SegmentCoreReaders, and SegmentReader to take advantage of the fact that TryGetValue returns a boolean

* PERFORMANCE: Lucene.Net.Index.DocValuesProducer: Optimized checks in AddXXXField() methods

* Fixes IDE0018: Inline variable declaration

* Fixes CA1507: Use nameof in place of string

* BUG: Fixed formatting in ArgumentException message for all analyzer factories so it will display the dictionary contents

* Removed pattern matching warning exclusions for IDE0019, IDE0020, and IDE0038

* Fixes IDE0019: Use pattern matching to avoid 'is' check followed by a cast

* Simplified reuse logic of TermsEnum classes

* Fixes IDE0038: Use pattern matching to avoid 'is' check followed by a cast

* Fixes IDE0020: Use pattern matching to avoid 'is' check followed by a cast

* Fixes CA1802: Use Literals Where Appropriate

* TestTargetFramework.props: Disabled IDE0044 warnings in test projects

* TestTargetFramework.props: Disabled IDE0019, IDE0020, IDE0038 from tests

* TestTargetFramework.props: Added CA1822 and IDE0059 and changed list to be in lexographical order by ID

* TestTargetFramework.props: Disabled IDE1006 (Naming rule violation) warnings in tests

* TestTargetFraework.props: Disabled CA1034 (Nested types should not be visible) warnings in tests

* TestTargetFramework.props: Disabled CA1825 (Avoid zero-length array allocations) warnings in tests

* TestTargetFramework.props: Disabled IDE0017 and IDE0028 warnings in tests (object and collection initialization can be simplified)

* TestTargetFramework.props: Disabled IDE0051 (Remove unused private member) warnings in tests

* Fixes IDE0044: Add readonly modifier

* Directory.Build.props: Disable IDE0032 warnings (use auto property)

* Fixes CA1813: Avoid unsealed attributes

* PERFORMANCE: Fixes CA1822: Mark members as static

* Added aggressive inlining to codecs, asserts and several other areas

* Removed InitializeInstanceFields() methods in all cases except in NumericTokenStream where we need to initialize from multiple constructors

* Lucene.Net.Util: Added aggressive inlining on several methods

* Fixes IDE0059: Remove unnecessary value assignment

* Fixes IDE0034: Simplify 'default' expression

* Fixes IDE0051: Remove unused private member. Also removed dead code/commented code.

* Directory.Build.props: Disabled CA1031 warnings (do not catch general exception types)

* lucene-cli: Disabled CA1034 (Nested types should not be visible) warnings in tests

* Fixes CA1819: Properties should not return arrays

* Fixes CA1012: Abstract types should not have constructors

* PERFORMANCE: Fixes CA1825: Avoid zero-length array allocations

* Fixes CA1052: Static holder types should be Static or NotInheritable

* Fixes IDE0028: Use collection initializers

* Fixes IDE1006: Naming Styles

* Fixes IDE0063: Use simple 'using' statement

* Fixes IDE0016: Use throw expression

* TestTargetFramework.props: Disabled IDE0031 (Use null propagation) warnings in tests

* Fixes IDE0031: Use null propagation

* Fixes IDE0029: Use coalesce expression

* Fixes IDE0030: Use coalesce expression (nullable)

* Fixes CA1820: Test for empty strings using string length

* Fixes CA1810: Initialize reference type static fields inline

* TestTargetFramework.props: Disabled CA2219 (Do not raise exceptions in exception clauses) warnings in tests

* Directory.Build.props: Disabled IDE0070 (Use 'System.HashCode.Combine') warnings because this functionality requires .NET Standard 2.1

* Fixes IDE0025: Use expression body for properties

* Fixes IDE0021: Use block body for constructors

* TestTargetFramework.props: Disabled IDE0040 (Add accessibility modifiers) warnings in tests

* Fixes IDE0040: Add accessibility modifiers

* Fixes IDE0041: Use is null check

* Fixes CA1815: Override equals and operator equals on value types

* TestTargetFramework.props: Disabled IDE0049 (Use language keywords instead of framework type names for type references) warnings in tests

* Fixes IDE0049: Use language keywords instead of framework type names for type references

* Fixes IDE0039: Use local function

* Fixes IDE0071: Simplify interpolation

* Fixes IDE0027: Use expression body for accessors

* fixes IDE1005: Use conditional delegate call

* Added .editorconfig file to control formatting and code analysis rules

* Directory.Build.props: Removed all Code Analysis settings that are now controlled by .editorconfig
1198 files changed
tree: 89107c8fa2b2b83804e17e96f895902d77c61bd6
  1. .vscode/
  2. branding/
  3. build/
  4. lib/
  5. src/
  6. websites/
  7. .asf.yaml
  8. .editorconfig
  9. .gitattributes
  10. .gitignore
  11. .rat-excludes
  12. ACKNOWLEDGEMENTS.txt
  13. azure-pipelines.yml
  14. build.bat
  15. CHANGES.txt
  16. CONTRIBUTING.md
  17. Directory.Build.props
  18. Directory.Build.targets
  19. global.json
  20. LICENSE.txt
  21. Lucene.Net.sln
  22. Lucene.Net.snk
  23. NOTICE.txt
  24. NuGet.config
  25. README.md
  26. TestTargetFramework.props
README.md

Apache Lucene.NET

Nuget Azure DevOps builds (master) GitHub

Full-text search for .NET

Apache Lucene.NET is a .NET full-text search engine framework, a C# port of the popular Apache Lucene project. Apache Lucene.NET is not a complete application, but rather a code library and API that can easily be used to add search capabilities to applications.

The Apache Lucene.NET web site is at: http://lucenenet.apache.org

Supported Frameworks

Lucene.NET 3.0.3

  • .NET Framework 4.0
  • .NET Framework 3.5

Lucene.NET 4.8.0

Status

Latest Stable Version: Lucene.NET 3.0.3

Working toward Lucene.NET 4.8.0 (currently in BETA)

Download

Lucene.NET 3.0.3

Core Library

NuGet version

PM> Install-Package Lucene.Net
All Packages

Lucene.NET 4.8.0

Core Library

NuGet version

PM> Install-Package Lucene.Net -Pre
All Packages

Documentation

We now have some preliminary documentation for Lucene.NET 4.8.0 on the Lucene.NET Website.

The API is similar to Java Lucene 4.8.0, which you may also find helpful to review.

NOTE: We are working on fixing issues with the documentation, but could use more help since it is a massive project. See #206.

Legacy Versions

Demos & Tools

There are several demos implemented as simple console applications that can be copied and pasted into Visual Studio or compiled on the command line in the Lucene.Net.Demo project.

There is also a dotnet command line tool available on NuGet. It contains all of the demos as well as tools maintaining your Lucene.NET index, featuring operations such as splitting, merging, listing segment info, fixing, deleting segments, upgrading, etc. Always be sure to back up your index before running any commands against it!

dotnet tool install lucene-cli -g --version 4.8.0-beta00012

Once installed, you can explore the commands and options that are available by entering the command lucene.

lucene-cli Documentation

How to Contribute

We love getting contributions! Read our Contribution Guide or read on for ways that you can help.

Join Mailing Lists

How to Join Mailing Lists

Ask a Question

If you have a general how-to question or need help from the Lucene.NET community, please subscribe to the user mailing list by sending an email to user-subscribe@lucenenet.apache.org and then follow the instructions to verify your email address. Note that you only need to subscribe once.

After you have subscribed to the mailing list, email your message to user@lucenenet.apache.org.

Alternatively, you can get help via StackOverflow's active community.

Please do not submit general how-to questions to GitHub, use GitHub for bug reports and tasks only.

Report a Bug

To report a bug, please use the GitHub issue tracker.

NOTE: In the past, the Lucene.NET project used the JIRA issue tracker, which has now been deprecated. However, we are keeping it active for tracking legacy issues. Please submit any new issues to GitHub.

Start a Discussion

To start a development discussion regarding technical features of Lucene.NET, please email the dev mailing list by sending an email to dev-subscribe@lucenenet.apache.org and then follow the instructions to verify your email address. Note that you only need to subscribe once.

After you have subscribed to the mailing list, email your message to dev@lucenenet.apache.org.

Submit a Pull Request

Before you start working on a pull request, please read our Contributing guide.

Building and Testing

Command Line

Building on the Command Line is currently only supported on Windows.

Prerequisites
  1. Powershell 3.0 or higher (see this question to check your Powershell version)
  2. .NET Core SDK 3.1 or higher
  3. .NET Framework 4.8 Developer Pack
Execution

To build the source, clone or download and unzip the repository. From the repository root, execute:

> build [options]
Build Options

NuGet packages are output by the build to the /release/NuGetPackages/ directory. Test results (if applicable) are output to the /release/TestResults/ directory.

You can setup Visual Studio to read the NuGet packages like any NuGet feed by following these steps:

  1. In Visual Studio, right-click the solution in Solution Explorer, and choose “Manage NuGet Packages for Solution”
  2. Click the gear icon next to the Package sources dropdown.
  3. Click the + icon (for add)
  4. Give the source a name such as Lucene.Net Local Packages
  5. Click the ... button next to the Source field, and choose the /src/release/NuGetPackages folder on your local system.
  6. Click Ok

Then all you need to do is choose the Lucene.Net Local Packages feed from the dropdown (in the NuGet Package Manager) and you can search for, install, and update the NuGet packages just as you can with any Internet-based feed.

Visual Studio

Prerequisites

  1. Visual Studio 2019 or higher
  2. .NET Core SDK 3.1 or higher
  3. .NET Framework 4.8 Developer Pack

Execution

  1. Open Lucene.Net.sln in Visual Studio.
  2. Choose the target framework to test by opening build/TestTargetFramework.proj and uncommenting the corresponding <TargetFramework>.
  3. Build a project or the entire solution, and wait for Visual Studio to discover the tests - this may take several minutes.
  4. Run or debug the tests in Test Explorer, optionally using the desired filters.

NOTE: When running tests in Visual Studio, be sure to set the default processor architecture to 64 bit to avoid running out of virtual memory on some tests.

Azure DevOps

We have setup our azure-pipelines.yml file with logical defaults so anyone with an Azure DevOps account can build Lucene.Net and run the tests with minimal effort. Even a free Azure DevOps account will work, but tests will run much faster if the account is setup as public, which enables up to 10 parallel jobs to run simultaneously.

Prerequisites

  1. An Azure DevOps account.
  2. A fork of this repository either on GitHub or Azure DevOps. The rest of these instructions assume a GitHub fork.

Execution

If you don't already have a pipeline set up:
  1. Create an Azure DevOps organization. If you already have one that you wish to use, you may skip this step.
  2. Create an Azure DevOps project. We recommend naming the project Lucene.NET. Note that if you are using a free Azure DevOps account, you should choose to make the project public in order to enable 10 parallel jobs. If you make the project private, you will only get 1 parallel job. Also, if disabling features, make sure to leave Pipelines enabled.
  3. Create an Azure DevOps pipeline.
    • Click on “Pipelines” from the left menu.
    • Click the “Create Pipeline” or “New Pipeline” button, depending on whether any pipelines already exist.
    • Select GitHub as the location to find the YAML file.
    • Select the fork of this repository you created in “Prerequisites”. Note that if this is a new Azure DevOps account you may need to setup extra permissions to access your GitHub account.
    • Next a “Review your YAML” page is presented showing the contents of azure-pipelines.yml. There is documentation near the top of the file indicating the variables that can be setup to enable additional options, but note that the default configuration will automatically run the build and all of the tests.
    • Click the “Run” button at the top right of the page.
If you already have a pipeline set up:
  1. Click on “Pipelines” from the left menu.
  2. Select the pipeline you wish to run.
  3. Click the “Queue” button on the upper right.
  4. (Optional) Select the branch and override any variables in the pipeline for this run.
  5. Click the “Run” button.

Note that after the build is complete, the nuget artifact contains .nupkg files which may be downloaded to your local machine where you can setup a local folder to act as a NuGet feed.

It is also possible to add an Azure DevOps feed id to a new variable named ArtifactFeedID, but we are getting mixed results due to permission issues.