Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Lucene 4.8 #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.suo
*.user
*.sln.docstates
.vs

# Build results

Expand Down Expand Up @@ -96,8 +97,7 @@ publish/
*.Publish.xml

# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
packages/

# Windows Azure Build Output
csx
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Lucene.Net.Documents;

namespace MultiFacetLuceneNet.Tests
namespace MultiFacetLucene.Tests
{
public static class DocumentExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MultiFacetLucene;
using Lucene.Net.Util;
using NUnit.Framework;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Analysis.Core;
using Lucene.Net.QueryParsers.Classic;

namespace MultiFacetLuceneNet.Tests
namespace MultiFacetLucene.Tests
{
[TestClass]
[TestFixture]
public class FacetSearcherTest
{
private FacetSearcher _target;

[TestInitialize]
[SetUp]
public void TestInitialize()
{
_target = new FacetSearcher(SetupIndex());
}

[TestMethod]
[Test]
public void MatchAllQueryShouldReturnCorrectFacetsAndDocuments()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand Down Expand Up @@ -55,7 +53,7 @@ public void MatchAllQueryShouldReturnCorrectFacetsAndDocuments()
Assert.AreEqual(2, typeFacets.Single(x => x.Value == "fruit").Count);
}

[TestMethod]
[Test]
public void DrilldownSingleFacetSingleValueShouldReturnCorrectFacetsAndDocuments()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand Down Expand Up @@ -83,7 +81,7 @@ public void DrilldownSingleFacetSingleValueShouldReturnCorrectFacetsAndDocuments
Assert.AreEqual(2, typeFacets.Single(x => x.Value == "fruit").Count);
}

[TestMethod]
[Test]
public void DrilldownSingleFacetMultiValueShouldReturnCorrectFacetsAndDocuments()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand Down Expand Up @@ -112,7 +110,7 @@ public void DrilldownSingleFacetMultiValueShouldReturnCorrectFacetsAndDocuments(
Assert.AreEqual(1, typeFacets.Single(x => x.Value == "drink").Count);
}

[TestMethod]
[Test]
public void MaxFacetRestrictionShouldReturnCorrectFacetsAndDocuments()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand All @@ -129,7 +127,7 @@ public void MaxFacetRestrictionShouldReturnCorrectFacetsAndDocuments()
Assert.AreEqual(3, colorFacets.Single(x => x.Value == "yellow").Count);
}

[TestMethod]
[Test]
public void MaxFacetRestrictionShouldStillReturnSelectedFacet()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand All @@ -146,7 +144,7 @@ public void MaxFacetRestrictionShouldStillReturnSelectedFacet()
Assert.AreEqual(1, colorFacets.Single(x => x.Value == "none").Count);
}


[Test]
public void MaxFacetRestrictionShouldReturnSelectedFacetAsWell()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand Down Expand Up @@ -174,10 +172,10 @@ public void MaxFacetRestrictionShouldReturnSelectedFacetAsWell()
}


[TestMethod]
[Test]
public void MatchSpecifiedQueryShouldReturnCorrectFacetsAndDocuments()
{
var query = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, string.Empty, new KeywordAnalyzer()).Parse("keywords:apa");
var query = new QueryParser(LuceneVersion.LUCENE_48, string.Empty, new KeywordAnalyzer()).Parse("keywords:apa");

var facetFieldInfos = new List<FacetFieldInfo>
{
Expand All @@ -190,8 +188,8 @@ public void MatchSpecifiedQueryShouldReturnCorrectFacetsAndDocuments()
var typeFacets = actual.Facets.Where(x => x.FacetFieldName == "type").ToList();

Assert.AreEqual(2, actual.Hits.TotalHits);
Assert.AreEqual("Banana", _target.Doc(actual.Hits.ScoreDocs[0].Doc).GetField("title").StringValue);
Assert.AreEqual("Water", _target.Doc(actual.Hits.ScoreDocs[1].Doc).GetField("title").StringValue);
Assert.AreEqual("Banana", _target.Doc(actual.Hits.ScoreDocs[0].Doc).GetField("title").GetStringValue());
Assert.AreEqual("Water", _target.Doc(actual.Hits.ScoreDocs[1].Doc).GetField("title").GetStringValue());

Assert.AreEqual(2, colorFacets.Count);
Assert.AreEqual(3, typeFacets.Count);
Expand All @@ -204,7 +202,7 @@ public void MatchSpecifiedQueryShouldReturnCorrectFacetsAndDocuments()
Assert.AreEqual(1, typeFacets.Single(x => x.Value == "fruit").Count);
}

[TestMethod]
[Test]
public void DrilldownMultiFacetsShouldReturnCorrectFacetsAndDocuments()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand All @@ -230,7 +228,7 @@ public void DrilldownMultiFacetsShouldReturnCorrectFacetsAndDocuments()
Assert.AreEqual(3, typeFacets.Single(x => x.Value == "food").Count);//only yellow
}

[TestMethod]
[Test]
public void IncludeEmptyFacetsShouldIncludeEmptyFacets()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand All @@ -246,7 +244,7 @@ public void IncludeEmptyFacetsShouldIncludeEmptyFacets()
Assert.AreEqual(1, colorFacets.Count(x => x.Count == 0));
}

[TestMethod]
[Test]
public void DoNotIncludeEmptyFacetsShouldNotIncludeEmptyFacets()
{
var facetFieldInfos = new List<FacetFieldInfo>
Expand All @@ -262,16 +260,16 @@ public void DoNotIncludeEmptyFacetsShouldNotIncludeEmptyFacets()
Assert.AreEqual(0, colorFacets.Count(x => x.Count == 0));
}

[TestMethod]
[Test]
public void RangeFacetsShouldReturnCorrectFacetsAndDocument()
{
var facetFieldInfos = new List<FacetFieldInfo>
{
new FacetFieldInfo{ FieldName = "price", IsRange = true, Ranges = new List<Range>
new FacetFieldInfo{ FieldName = "price", IsRange = true, Ranges = new List<MultiFacetLucene.Range>
{
new Range { Id = "A", From = "0", To = "10"},
new Range { Id = "B", From = "0", To = "20"},
new Range { Id = "C", From = "0", To = "30"}
new MultiFacetLucene.Range { Id = "A", From = "0", To = "10"},
new MultiFacetLucene.Range { Id = "B", From = "0", To = "20"},
new MultiFacetLucene.Range { Id = "C", From = "0", To = "30"}
},
Selections = new List<string>
{
Expand Down Expand Up @@ -309,8 +307,7 @@ public void RangeFacetsShouldReturnCorrectFacetsAndDocument()
protected static IndexReader SetupIndex()
{
var directory = new RAMDirectory();
var writer = new IndexWriter(directory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true,
IndexWriter.MaxFieldLength.LIMITED);
var writer = new IndexWriter(directory, new IndexWriterConfig(LuceneVersion.LUCENE_48, new StandardAnalyzer(LuceneVersion.LUCENE_48)));
writer.AddDocument(new Document()
.AddField("title", "Banana", Field.Store.YES, Field.Index.NOT_ANALYZED)
.AddField("color", "yellow", Field.Store.YES, Field.Index.NOT_ANALYZED)
Expand Down Expand Up @@ -341,10 +338,9 @@ protected static IndexReader SetupIndex()
.AddField("type", "drink", Field.Store.YES, Field.Index.NOT_ANALYZED)
.AddField("keywords", "apa hello cars", Field.Store.YES, Field.Index.ANALYZED)
.AddField("price", "0", Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.Flush(true, true, true);
writer.Optimize();
writer.Flush(true, true);
writer.Commit();
return IndexReader.Open(directory, true);
return DirectoryReader.Open(directory);

}
}
Expand Down
21 changes: 21 additions & 0 deletions MultiFacetLucene.Tests/MultiFacetLucene.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lucene.Net" Version="4.8.0-beta00015" />
<PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00015" />
<PackageReference Include="Lucene.Net.Queries" Version="4.8.0-beta00015" />
<PackageReference Include="Lucene.Net.QueryParser" Version="4.8.0-beta00015" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Nunit" Version="3.13.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MultiFacetLucene\MultiFacetLucene.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MultiFacetLucene;
using Version = Lucene.Net.Util.Version;
using NUnit.Framework;

namespace MultiFacetLuceneNet.Tests
namespace MultiFacetLucene.Tests
{
[Ignore]
[TestClass]
//[Ignore]
[TestFixture]
public class PerformanceTest
{
private static FacetSearcher _target;
Expand All @@ -31,14 +28,14 @@ public void Warmup()
_target.SearchWithFacets(new TermQuery(new Term("Price", "5")), 100, facetFieldInfos);
}

[TestInitialize]
[SetUp]
public void TestInitialize()
{
_target = new FacetSearcher(SetupIndex());
Warmup();
}

[TestMethod]
[Test]
public void MatchAllDocsAndCalculateFacetsPerformanceTest()
{
Warmup();
Expand All @@ -47,8 +44,8 @@ public void MatchAllDocsAndCalculateFacetsPerformanceTest()

var facetFieldInfos = new List<FacetFieldInfo>
{
new FacetFieldInfo{ FieldName = "color"},
new FacetFieldInfo{ FieldName = "type"},
new() { FieldName = "color"},
new() { FieldName = "type"},
};
var actual = _target.SearchWithFacets(new MatchAllDocsQuery(), 100, facetFieldInfos);

Expand All @@ -58,7 +55,7 @@ public void MatchAllDocsAndCalculateFacetsPerformanceTest()
Trace.WriteLine("Took " + vs + " ms");
}

[TestMethod]
[Test]
public void MatchAllDocsPerformanceTest()
{
var stopwatch = new Stopwatch();
Expand All @@ -76,19 +73,17 @@ public void MatchAllDocsPerformanceTest()
protected static IndexReader SetupIndex()
{
var directory = new RAMDirectory();
var writer = new IndexWriter(directory, new StandardAnalyzer(Version.LUCENE_29), true,
IndexWriter.MaxFieldLength.LIMITED);
var writer = new IndexWriter(directory, new IndexWriterConfig(Lucene.Net.Util.LuceneVersion.LUCENE_48, new StandardAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48)));
for (var i = 0; i < 50000; i++)
writer.AddDocument(new Document()
.AddField("title", Guid.NewGuid().ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)
.AddField("color", GenerateColor(), Field.Store.YES, Field.Index.NOT_ANALYZED)
.AddField("type", GenerateFood(), Field.Store.YES, Field.Index.NOT_ANALYZED)
.AddField("type", GenerateFruit(), Field.Store.YES, Field.Index.NOT_ANALYZED)
.AddField("price", "10", Field.Store.YES, Field.Index.NOT_ANALYZED));
writer.Flush(true, true, true);
writer.Optimize();
writer.Flush(true, true);
writer.Commit();
return IndexReader.Open(directory, true);
return DirectoryReader.Open(directory);
}


Expand Down
31 changes: 17 additions & 14 deletions MultiFacetLuceneNet.sln → MultiFacetLucene.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiFacetLucene", "MultiFacetLucene\MultiFacetLucene.csproj", "{086093FD-D444-48BE-B897-7FAC14133C23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiFacetLuceneNet.Tests", "MultiFacetLuceneNet.Tests\MultiFacetLuceneNet.Tests.csproj", "{F29DAEA8-7267-4230-B2F6-70062D2E890B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerformanceTest", "PerformanceTest\PerformanceTest.csproj", "{0065E899-596D-4B16-9CF5-E917DD957DAB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B13A814A-4ECA-4A5F-A340-FF4C6DCE5145}"
Expand All @@ -16,26 +12,33 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B13A81
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiFacetLucene", "MultiFacetLucene\MultiFacetLucene.csproj", "{87059512-913A-4B3D-BD07-C13419852B81}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiFacetLucene.Tests", "MultiFacetLucene.Tests\MultiFacetLucene.Tests.csproj", "{B2573CD0-8A9E-43EA-BFB3-6056FB41C2D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{086093FD-D444-48BE-B897-7FAC14133C23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{086093FD-D444-48BE-B897-7FAC14133C23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{086093FD-D444-48BE-B897-7FAC14133C23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{086093FD-D444-48BE-B897-7FAC14133C23}.Release|Any CPU.Build.0 = Release|Any CPU
{F29DAEA8-7267-4230-B2F6-70062D2E890B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F29DAEA8-7267-4230-B2F6-70062D2E890B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F29DAEA8-7267-4230-B2F6-70062D2E890B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F29DAEA8-7267-4230-B2F6-70062D2E890B}.Release|Any CPU.Build.0 = Release|Any CPU
{0065E899-596D-4B16-9CF5-E917DD957DAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0065E899-596D-4B16-9CF5-E917DD957DAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0065E899-596D-4B16-9CF5-E917DD957DAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0065E899-596D-4B16-9CF5-E917DD957DAB}.Release|Any CPU.Build.0 = Release|Any CPU
{87059512-913A-4B3D-BD07-C13419852B81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87059512-913A-4B3D-BD07-C13419852B81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87059512-913A-4B3D-BD07-C13419852B81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87059512-913A-4B3D-BD07-C13419852B81}.Release|Any CPU.Build.0 = Release|Any CPU
{B2573CD0-8A9E-43EA-BFB3-6056FB41C2D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2573CD0-8A9E-43EA-BFB3-6056FB41C2D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2573CD0-8A9E-43EA-BFB3-6056FB41C2D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2573CD0-8A9E-43EA-BFB3-6056FB41C2D2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D0C27F1D-550D-403C-9243-107D171EE003}
EndGlobalSection
EndGlobal
7 changes: 1 addition & 6 deletions MultiFacetLucene/FacetBitSetCalculatorProvider.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MultiFacetLucene.Configuration;
using MultiFacetLucene.Configuration;

namespace MultiFacetLucene
{
Expand Down
Loading