You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: websites/apidocs/apiSpec/core/Lucene_Net_Codecs.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,15 +31,15 @@ Codecs API: API for customization of the encoding and structure of the index.
31
31
* FieldInfos - see <xref:Lucene.Net.Codecs.FieldInfosFormat>
32
32
* SegmentInfo - see <xref:Lucene.Net.Codecs.SegmentInfoFormat>
33
33
* Norms - see <xref:Lucene.Net.Codecs.NormsFormat>
34
-
* Live documents - see <xref:Lucene.Net.Codecs.LiveDocsFormat>
34
+
* Live documents - see <xref:Lucene.Net.Codecs.LiveDocsFormat>
35
35
36
36
For some concrete implementations beyond Lucene's official index format, see the [Codecs module](../codecs/overview.html).
37
37
38
38
Codecs are identified by name through the <xref:Lucene.Net.Codecs.ICodecFactory> implementation, which by default is the <xref:Lucene.Net.Codecs.DefaultCodecFactory>. To create your own codec, extend <xref:Lucene.Net.Codecs.Codec>. By default, the name of the class (minus the suffix "Codec") will be used as the codec's name.
39
39
40
40
```cs
41
41
// By default, the name will be "My" because the "Codec" suffix is removed
42
-
publicclassMyCodec : Codec
42
+
publicclassMyCodec : Codec
43
43
{
44
44
}
45
45
```
@@ -49,7 +49,7 @@ public class MyCodec : Codec
49
49
50
50
To override the default codec name, decorate the custom codec with the <xref:Lucene.Net.Codecs.CodecNameAttribute>.
51
51
52
-
The <xref:Lucene.Net.Codecs.CodecNameAttribute> can be used to set the name to that of a built-in codec to override its registration in the <xref:Lucene.Net.Codecs.DefaultCodecFactory>.
52
+
The <xref:Lucene.Net.Codecs.CodecNameAttribute> can be used to set the name to that of a built-in codec to override its registration in the <xref:Lucene.Net.Codecs.DefaultCodecFactory>.
53
53
54
54
```cs
55
55
[CodecName("MyCodec")] // Sets the codec name explicitly
If your application is not using dependency injection, you can register a custom codec by adding your codec at start up.
111
111
112
112
```cs
113
-
Codec.SetCodecFactory(newDefaultCodecFactory {
113
+
Codec.SetCodecFactory(newDefaultCodecFactory {
114
114
CustomCodecTypes=newType[] { typeof(MyCodec) }
115
115
});
116
116
```
@@ -178,7 +178,7 @@ The <xref:Lucene.Net.TestFramework> library contains specialized classes to mini
178
178
> See [Unit testing C# with NUnit and .NET Core](https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-nunit) for detailed instructions on how to set up a class library to use with NUnit.
179
179
180
180
> [!NOTE]
181
-
> .NET Standard is not an executable target. Tests will not run unless you target a framework such as `net6.0` or `net48`.
181
+
> .NET Standard is not an executable target. Tests will not run unless you target a framework such as `net8.0` or `net48`.
182
182
183
183
Here is an example project file for .NET 8 for testing a project named `MyCodecs.csproj`.
The <xref:Lucene.Net.Index.BasePostingsFormatTestCase> class includes a barrage of 8 tests that can now be run using your favorite test runner, such as Visual Studio Test Explorer.
245
+
The <xref:Lucene.Net.Index.BasePostingsFormatTestCase> class includes a barrage of 8 tests that can now be run using your favorite test runner, such as Visual Studio Test Explorer.
Copy file name to clipboardExpand all lines: websites/site/quick-start/tutorial.md
+29-29Lines changed: 29 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ However you are totally free to use [Visual Studio](https://visualstudio.microso
23
23
First you must install the .NET Core SDK, if it's not already installed on your machine. The .NET Core SDK contains the .NET runtime, .NET Libraries and the .NET CLI. If you haven't installed it yet, download it from https://dotnet.microsoft.com/en-us/download and run the installer. It's a pretty straightforward process. I'll be using the **.NET 6.0 SDK** in this tutorial.
24
24
25
25
> [!NOTE]
26
-
> The C# code we present **requires the .NET 6.0 SDK or later**. However, with a few simple modifications it can run on older SDKs including 4.x. To do that, the Program.cs file will need to have a namespace, Program class and a static void main method. See Microsoft docs [here](https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-5-0#code-try-3) for details. You will also need to add [braces to the using statements](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement#example).
26
+
> The C# code we present **requires the .NET 6.0 SDK or later**. However, with a few simple modifications it can run on older SDKs including 4.x. To do that, the Program.cs file will need to have a namespace, Program class and a static void main method. See Microsoft docs [here](https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-5-0#code-try-3) for details. You will also need to add [braces to the using statements](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement#example).
27
27
28
28
## Download and Install PowerShell
29
29
PowerShell is cross platform and runs everywhere .NET runs, so we will be using PowerShell for all of our command line work. If you don't already have PowerShell installed you can download and find instructions for installing it on Window, Unix or Mac on this [Installing PowerShell](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell) page. In my examples I'm using PowerShell 7.2 but the specific version probably doesn't make a difference.
@@ -36,7 +36,7 @@ Let's use PowerShell now to verify that you have the .NET SDK with the .NET CLI
36
36
This command will show the latest version of the .NET SDK installed and also show a list of all versions installed. If the .NET SDK is not installed this the command will return an error indicating the command was not found.
37
37
38
38
Below I show the top of the results for the `dotnet --info` command ran on my machine. You can see I'm using .NET SDK 6.0.200 on windows for this demo. In my case I had to scroll the screen up to see this info since I have many versions of the .NET SDK installed and it shows info on each version which scrolled the info about the latest version off the screen. Your latest version will likely be different than mine and perhaps you may be running on Unix or Mac. That's fine. But remember **you need .NET SDK 6 or later**. Or you need to modify the examples according to the note above.
We need to add references from our project to the Lucene.NET Nuget packages we need -- two separate packages in this case. Execute the first command in PowerShell: (Please note there are two dashes before prerelease not one.)
And now add the 2nd Nuget package by executing this command in PowerShell:
@@ -77,14 +77,14 @@ And now add the 2nd Nuget package by executing this command in PowerShell:
77
77
At this point, our directory has two files in it plus an obj directory with some additional files. We are mostly concerned with the lucene-example1.csproj project file and the Program.cs C# code file.
From here on out, you can use your favorite editor to view and edit files as we walk through the rest of the example. I'll be using Visual Studio 2022 on Windows, but you could just as easily use VIM, Visual Studio Code or any other editor and even be doing that on Ubuntu on a Raspberry Pi if you like. Remember, Lucene.NET and the .NET framework both support a wide variety of platforms.
85
85
86
86
Below is what the project file looks like which we created using the dotnet CLI. Notice that it contains package references to the two Lucene.NET Nuget packages we specified.
@@ -195,7 +195,7 @@ Console.WriteLine($"Title of first result: {title}");
195
195
```
196
196
197
197
> [!WARNING]
198
-
> As mentioned earlier, if you are not running .NET 6.0 SDK or later you will need to modify the above code in the following two ways: 1) Program.cs file will need to have a namespace, Program class and a static void main method. See Microsoft docs [here](https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-5-0#code-try-3) for details; and 2) you will need to add [braces to the using statements](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement#example).
198
+
> As mentioned earlier, if you are not running .NET 6.0 SDK or later you will need to modify the above code in the following two ways: 1) Program.cs file will need to have a namespace, Program class and a static void main method. See Microsoft docs [here](https://docs.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio?pivots=dotnet-5-0#code-try-3) for details; and 2) you will need to add [braces to the using statements](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement#example).
199
199
200
200
### Code Walkthrough
201
201
Before running the code let's talk about what it does.
@@ -204,7 +204,7 @@ The using declarations at the top of the file specify the various namespaces we
//Open the Directory using a Lucene Directory class
210
210
stringindexName="example_index";
@@ -215,7 +215,7 @@ using LuceneDirectory indexDir = FSDirectory.Open(indexPath);
215
215
216
216
Then in the next block we create an `IndexWriter` that will use our `LuceneDirectory`. The `IndexWriter` is a important class in Lucene.NET and is used to write documents to the Index (among other things).
217
217
218
-
The `IndexWriter` will create our subdirectory for us since it doesn't yet exist and it will create the index since it also doesn't yet exist. By using `OpenMode.CREATE` we are telling Lucene.NET that we want to recreate the index if it already exists. This works great for a demo like this since every time the console app is ran we will be recreating our LuceneIndex which means we will get the same output each time.
218
+
The `IndexWriter` will create our subdirectory for us since it doesn't yet exist and it will create the index since it also doesn't yet exist. By using `OpenMode.CREATE` we are telling Lucene.NET that we want to recreate the index if it already exists. This works great for a demo like this since every time the console app is ran we will be recreating our LuceneIndex which means we will get the same output each time.
219
219
220
220
```c#
221
221
//Create an index writer
@@ -281,12 +281,12 @@ Console.WriteLine($"Title of first result: {title}");
281
281
282
282
### View of the Project.cs file with Our Code
283
283
The `Program.cs` file should now look something like this in your editor:
So now you can hit F5 in Visual Studio or VS Code or you can execute `dotnet run` in PowerShell to see the code run and to see if it outputs what we expect.
And in the above screenshot we can see that the 2nd time we executed `dotnet run` (ie. after we modified the Program.cs file, out output says:
@@ -297,7 +297,7 @@ Title of first result: Powerful open source search library for .NET
297
297
This is exactly what we would expect.
298
298
299
299
300
-
### Conclusion - Example 1
300
+
### Conclusion - Example 1
301
301
While this example is not particularly complicated, it will get you started. It provides fully working code that uses Lucne.NET that you now understand.
302
302
303
303
When looking at this code it's pretty easy to imagine how one might use a while loop instead of inline code for adding documents and how one could perhaps add 10,000 documents (or a million documents) instead of just three. And it's pretty easy to imagine how one would add several fields per document rather then just two.
@@ -310,7 +310,7 @@ Then move onto the next example that demonstrates full text search.
310
310
We are going to create a console application that uses Lucene.NET to index three documents that each have two fields and then the app will search those docs on a certain field doing an full text search and output some info about the results.
311
311
312
312
This example assumes you did Example 1 so:
313
-
1. You already have the .NET SDK installed,
313
+
1. You already have the .NET SDK installed,
314
314
2. You already have PowerShell installed,
315
315
3. You know how to create a C# console application project,
316
316
4. You are familiar with the Example 1 code.
@@ -337,7 +337,7 @@ Technically the line above to `dotnet add package Lucene.Net --prerelease` is no
337
337
338
338
### View the Project Files
339
339
Just like in the prior example the project folder will have two files and an obj directory with some files. Now use your favorite editor to view the project's .proj file. It should look like this:
@@ -455,7 +455,7 @@ As you might guess we have an additional using declaration `using Lucene.Net.Que
455
455
456
456
We are creating a `LuceneDirectory` and `IndexWriter` the same way and we are adding the same documents and then committing them. All stuff we saw in Example1. Also in this example we get our index reader and searcher the same way we did in the last example.
457
457
458
-
**But** the way we query back documents in this example is different.
458
+
**But** the way we query back documents in this example is different.
459
459
460
460
This time around, instead of using a `TermQuery` to do an exact match search, have these two lines of code:
These lines allow us to create a query that will perform a full text search. This type of search is similar to what you are use to when doing a google or bing search.
468
468
469
-
What we are saying in these two lines is that we want to create a query that will search the `title` field of our documents and we want back document that contain "open source" or just "open" or just "source" and we want them sorted by how well they match our "open source" query.
469
+
What we are saying in these two lines is that we want to create a query that will search the `title` field of our documents and we want back document that contain "open source" or just "open" or just "source" and we want them sorted by how well they match our "open source" query.
470
470
471
471
So when the line of code below runs, Lucene.NET will score each of our docs that match the query and return the top 3 matching documents sorted by score.
472
472
@@ -491,17 +491,17 @@ for (int i = 0; i < topDocs.TotalHits; i++)
491
491
492
492
### View of the Project.cs file with Our Code
493
493
The `Program.cs` file should now look something like this in your editor:
So now you can hit F5 in Visual Studio or VS Code or you can execute `dotnet run` in PowerShell to see the code run and to see if it outputs what we expect.
If you go back and review the contents of the `title` field for each document you will see the output from running the code does indeed return the only two documents that that contain "open source" in the title field.
502
+
If you go back and review the contents of the `title` field for each document you will see the output from running the code does indeed return the only two documents that that contain "open source" in the title field.
503
503
504
-
### Conclusion - Example 2
504
+
### Conclusion - Example 2
505
505
In this Example we saw Lucene.NET's full text search feature. But we only scratched the surface.
506
506
507
507
It's the responsibility of the analyzer to tokenize the text and it's the tokens that are stored in the index as terms. In our case we used the `StandardAnalyzer` which removes punctuation, lower cases the text so it's not case sensitive and removes stop words (common words like "a" "an" and "the").
0 commit comments