Skip to content

Commit

Permalink
readme and example updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Modest-as committed Sep 20, 2020
1 parent e31e02d commit d574f11
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 30 deletions.
13 changes: 13 additions & 0 deletions Lucene.Net.Sql.MySql.Example/Lucene.Net.Sql.MySql.Example.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00012" />
<PackageReference Include="Lucene.Net.Sql.MySql" Version="0.0.3-alpha" />
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions Lucene.Net.Sql.MySql.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Util;

namespace Lucene.Net.Sql.MySql.Example
{
// dotnet pack -c Release -o out --version-suffix 0.0.3-alpha Lucene.Net.Sql.MySql/Lucene.Net.Sql.MySql.csproj
public class Program
{
public static void Main(string[] args)
{
const string connectionString = "server=localhost;port=3306;database=lucene;uid=root;password=password;Allow User Variables=True;";

var options = new SqlDirectoryOptions(connectionString, "ExampleDirectory");

using var mySqlOperator = MySqlLuceneOperator.Create(options);

using var directory = new LuceneSqlDirectory(options, mySqlOperator);

using var analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);

using var writer = new IndexWriter(directory, new IndexWriterConfig(LuceneVersion.LUCENE_48, analyzer));

var source = new
{
Name = "Kermit the Frog",
FavoritePhrase = "The quick brown fox jumps over the lazy dog"
};

var doc = new Document
{
new StringField(
"name",
source.Name,
Field.Store.YES),
new TextField(
"favoritePhrase",
source.FavoritePhrase,
Field.Store.YES)
};

writer.AddDocument(doc);

writer.Flush(false, false);

var phrase = new MultiPhraseQuery
{
new Term("favoritePhrase", "brown"),
new Term("favoritePhrase", "fox")
};

var searcher = new IndexSearcher(writer.GetReader(true));

var result = searcher.Search(phrase, 20);
}
}
}
6 changes: 4 additions & 2 deletions Lucene.Net.Sql.MySql/Lucene.Net.Sql.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<Product>Lucene.Net SQL</Product>
<Title>Lucene.Net SQL</Title>
<Description>Lucene.NET SQL is a library that enables persistance of Lucene index files to SQL databases.</Description>
<Copyright>MIT</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Copyright>GPL-3.0-or-later</Copyright>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/GowenGit/Lucene-net-sql</PackageProjectUrl>
<RepositoryUrl>https://github.com/GowenGit/Lucene-net-sql</RepositoryUrl>
<PackageTags>Lucene; SQL; MySQL; Storage; Directory; MySql</PackageTags>
Expand Down Expand Up @@ -49,6 +50,7 @@
<Target Name="IncludeReferenceAssets">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)Lucene.Net.Sql.dll" />
<BuildOutputInPackage Include="$(OutputPath)Lucene.Net.Sql.xml" />
</ItemGroup>
</Target>
</Project>
50 changes: 26 additions & 24 deletions Lucene.Net.Sql.Performance/LuceneLiteBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,61 @@ public override void GlobalSetup()
}

[Benchmark]
public void FuzzySearchMySqlLightNovel()
public void FuzzySearchMySqlTenNovels()
{
FuzzySearch(MySqlWriter);
}

[Benchmark]
public void FuzzySearchFileSystemLightNovel()
public void FuzzySearchFileSystemTenNovels()
{
FuzzySearch(FileWriter);
}

[Benchmark]
public void QuerySearchMySqlLightNovel()
public void QuerySearchMySqlTenNovels()
{
QuerySearch(MySqlWriter);
}

[Benchmark]
public void QuerySearchFileSystemLightNovel()
public void QuerySearchFileSystemTenNovels()
{
QuerySearch(FileWriter);
}

private static void IndexData(IndexWriter writer)
{
var text = File.ReadAllText("Data/data_01");
for (var i = 1; i <= 10; i++)
{
var file = $"Data/data_{i:00}";

var lines = text.Split(
new[] { "\r\n", "\r", "\n" },
StringSplitOptions.None
);
var lines = File.ReadAllText(file).Split(
new[] { "\r\n", "\r", "\n" },
StringSplitOptions.None
);

for (var i = 0; i < lines.Length; i++)
{
var doc = new Document
for (var j = 0; j < lines.Length; j++)
{
new Int32Field(
"line",
i,
Field.Store.YES),
new TextField(
"text",
lines[i],
Field.Store.YES)
};

writer.AddDocument(doc);
var doc = new Document
{
new Int32Field(
"line",
j,
Field.Store.YES),
new TextField(
"text",
lines[j],
Field.Store.YES)
};

writer.AddDocument(doc);
}
}

writer.Flush(false, false);
}


private static void FuzzySearch(IndexWriter writer)
{
var phrase = new FuzzyQuery(new Term("text", "Mary"));
Expand Down
4 changes: 2 additions & 2 deletions Lucene.Net.Sql.Performance/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class Program
{
public static void Main(string[] args)
{
BenchmarkRunner.Run<LuceneLiteBenchmark>();
// BenchmarkRunner.Run<LuceneHeavyBenchmark>();
// BenchmarkRunner.Run<LuceneLiteBenchmark>();
BenchmarkRunner.Run<LuceneHeavyBenchmark>();
}
}
}
5 changes: 5 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<configuration>
<packageSources>
<add key="repositoryPath" value="./out" />
</packageSources>
</configuration>
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,67 @@ Lucene.NET SQL is a library that enables persistance of Lucene index files to SQ
## Status

Currently this package is in `alpha` while we wait for `lucene.net 4.8` to be released.

## License

### Commercial license

If you want to use Lucene.NET SQL to develop commercial projects, and applications, the Commercial license is the appropriate license. With this option, your source code is kept proprietary. Purchase a Lucene.NET SQL Commercial License at [gowengit.github.io/lucene-net-sql](https://gowengit.github.io/lucene-net-sql)

### Open source license

If you are creating an open source application under a license compatible with the [GNU GPL license v3](https://www.gnu.org/licenses/gpl-3.0.html), you may use Lucene.NET SQL under the terms of the GPLv3.

## Examples

Below are some general use examples of the library.

### MySQL

```cs
var options = new SqlDirectoryOptions(connectionString, "ExampleDirectory");

using var mySqlOperator = MySqlLuceneOperator.Create(options);

using var directory = new LuceneSqlDirectory(options, mySqlOperator);

// Rest is standard Lucene code
using var analyzer = new StandardAnalyzer(LuceneVersion.LUCENE_48);

using var writer = new IndexWriter(directory, new IndexWriterConfig(LuceneVersion.LUCENE_48, analyzer));

// ...
```

*Note:* `MySqlLuceneOperator` is linked to a single `MySQL` connection so should be either transient or short lived.

## Performance Benchmarks

Performance benchmarks were done to compare local file system vs local SQL instance performance.

``` ini
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.508 (2004/?/20H1)
AMD Ryzen 5 2600, 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=3.1.401
[Host] : .NET Core 3.1.7 (CoreCLR 4.700.20.36602, CoreFX 4.700.20.37001), X64 RyuJIT
Job-QKPTDT : .NET Core 3.1.7 (CoreCLR 4.700.20.36602, CoreFX 4.700.20.37001), X64 RyuJIT
```

### A run on ten indexed novels line by line, around *7MB* of text data.

| Method | Mean | Error | StdDev | Median |
|------------------------------- |----------:|----------:|----------:|----------:|
| FuzzySearchMySqlTenNovels | 28.877 ms | 0.4831 ms | 0.4519 ms | 28.771 ms |
| FuzzySearchFileSystemTenNovels | 3.107 ms | 0.0950 ms | 0.2771 ms | 3.046 ms |
| QuerySearchMySqlTenNovels | 6.424 ms | 0.1187 ms | 0.2554 ms | 6.332 ms |
| QuerySearchFileSystemTenNovels | 1.170 ms | 0.0233 ms | 0.0635 ms | 1.143 ms |

### A run on one hundred indexed novels, around *70MB* of text data.

| Method | Mean | Error | StdDev | Median |
|----------------------------------- |----------:|---------:|---------:|----------:|
| FuzzySearchMySqlHundredNovels | 290.90 ms | 1.621 ms | 1.354 ms | 290.74 ms |
| FuzzySearchFileSystemHundredNovels | 20.94 ms | 0.288 ms | 0.256 ms | 20.83 ms |
| QuerySearchMySqlHundredNovels | 52.00 ms | 1.012 ms | 1.082 ms | 51.85 ms |
| QuerySearchFileSystemHundredNovels | 11.44 ms | 0.207 ms | 0.388 ms | 11.24 ms |
10 changes: 8 additions & 2 deletions lucene-net-sql.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lucene.Net.Sql", "Lucene.Ne
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lucene.Net.Sql.Tests", "Lucene.Net.Sql.Tests\Lucene.Net.Sql.Tests.csproj", "{3734271B-D0E1-4D5E-89EB-E1EB1D8753F9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Sql.MySql", "Lucene.Net.Sql.MySql\Lucene.Net.Sql.MySql.csproj", "{EDBA6E09-4581-476E-88E6-DBFD24B1A561}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lucene.Net.Sql.MySql", "Lucene.Net.Sql.MySql\Lucene.Net.Sql.MySql.csproj", "{EDBA6E09-4581-476E-88E6-DBFD24B1A561}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Sql.Performance", "Lucene.Net.Sql.Performance\Lucene.Net.Sql.Performance.csproj", "{D7AD39A2-F26F-45A1-8581-0ACB31E55923}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lucene.Net.Sql.Performance", "Lucene.Net.Sql.Performance\Lucene.Net.Sql.Performance.csproj", "{D7AD39A2-F26F-45A1-8581-0ACB31E55923}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net.Sql.MySql.Example", "Lucene.Net.Sql.MySql.Example\Lucene.Net.Sql.MySql.Example.csproj", "{81A7EFC1-B3DF-423D-8155-732BFA5C0F26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -33,6 +35,10 @@ Global
{D7AD39A2-F26F-45A1-8581-0ACB31E55923}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7AD39A2-F26F-45A1-8581-0ACB31E55923}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7AD39A2-F26F-45A1-8581-0ACB31E55923}.Release|Any CPU.Build.0 = Release|Any CPU
{81A7EFC1-B3DF-423D-8155-732BFA5C0F26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81A7EFC1-B3DF-423D-8155-732BFA5C0F26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81A7EFC1-B3DF-423D-8155-732BFA5C0F26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81A7EFC1-B3DF-423D-8155-732BFA5C0F26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit d574f11

Please sign in to comment.