Skip to content

Commit a171099

Browse files
committed
feat!: upgrade to NHibernate 5
1 parent 16b6ee5 commit a171099

File tree

64 files changed

+5452
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5452
-70
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"csharpasyncgenerator.tool": {
6+
"version": "0.21.0",
7+
"commands": [
8+
"async-generator"
9+
]
10+
}
11+
}
12+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ consumable/
4444
employee/
4545
employer/
4646
lucenedirs/
47+
slave/
48+
master/

AsyncGenerator.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
projects:
2+
- filePath: src/NHibernate.Search/NHibernate.Search.csproj
3+
targetFramework: net461
4+
concurrentRun: true
5+
applyChanges: true
6+
analyzation:
7+
callForwarding: true
8+
cancellationTokens:
9+
enabled: true
10+
guards: true
11+
scanMethodBody: true
12+
scanForMissingAsyncMembers:
13+
- all: true
14+
asyncExtensionMethods:
15+
assemblyTypes:
16+
- fullTypeName: NHibernate.Linq.LinqExtensionMethods
17+
assemblyName: NHibernate
18+
# - fullTypeName: NHibernate.SessionExtensions
19+
# assemblyName: NHibernate
20+
# - fullTypeName: NHibernate.StatelessSessionExtensions
21+
# assemblyName: NHibernate
22+
# - fullTypeName: NHibernate.TransactionExtensions
23+
# assemblyName: NHibernate
24+
registerPlugin:
25+
- type: AsyncGenerator.Core.Plugins.TransactionScopeAsyncFlowAdder
26+
assemblyName: AsyncGenerator.Core
27+
28+
- filePath: src/NHibernate.Search.Tests/NHibernate.Search.Tests.csproj
29+
targetFramework: net461
30+
concurrentRun: true
31+
applyChanges: true
32+
analyzation:
33+
callForwarding: true
34+
cancellationTokens:
35+
enabled: true
36+
scanMethodBody: true
37+
scanForMissingAsyncMembers:
38+
- all: true
39+
asyncExtensionMethods:
40+
assemblyTypes:
41+
- fullTypeName: NHibernate.Linq.LinqExtensionMethods
42+
assemblyName: NHibernate
43+
# - fullTypeName: NHibernate.SessionExtensions
44+
# assemblyName: NHibernate
45+
# - fullTypeName: NHibernate.StatelessSessionExtensions
46+
# assemblyName: NHibernate
47+
# - fullTypeName: NHibernate.TransactionExtensions
48+
# assemblyName: NHibernate
49+
typeConversion:
50+
- conversion: Ignore
51+
rule: IsTestCase
52+
- conversion: Ignore
53+
anyBaseTypeRule: IsTestCase
54+
executionPhase: PostProviders
55+
registerPlugin:
56+
- type: AsyncGenerator.Core.Plugins.NUnitPlugin
57+
parameters:
58+
- name: createNewTypes
59+
value: true
60+
assemblyName: AsyncGenerator.Core
61+
- type: AsyncGenerator.Core.Plugins.TransactionScopeAsyncFlowAdder
62+
assemblyName: AsyncGenerator.Core
63+
typeRules:
64+
- filters:
65+
- name: TestCase
66+
- name: MultiplySessionFactoriesTestCase
67+
name: IsTestCase

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# NHibernate-Search
1+
# NHibernate.Search
2+
23
NHibernate Search is a port of [Hibernate Search][1]. NHibernate Search transparently indexes your objects and offers fast regular, full-text search.
34

45
[1]: http://hibernate.org/search/

src/Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<PropertyGroup>
3+
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
7+
</ItemGroup>
8+
</Project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System.Collections;
12+
using System.Collections.Generic;
13+
using Lucene.Net.Analysis.Standard;
14+
using Lucene.Net.QueryParsers;
15+
using Lucene.Net.Util;
16+
using NUnit.Framework;
17+
18+
namespace NHibernate.Search.Tests.Analyzer
19+
{
20+
using System.Threading.Tasks;
21+
[TestFixture]
22+
public class AnalyzerTestAsync : SearchTestCase
23+
{
24+
protected override IEnumerable<string> Mappings
25+
{
26+
get { return new string[] {"Analyzer.MyEntity.hbm.xml"}; }
27+
}
28+
29+
[Test]
30+
public async Task TestScopedAnalyzersAsync()
31+
{
32+
MyEntity en = new MyEntity();
33+
en.Entity = "Entity";
34+
en.Field = "Field";
35+
en.Property = "Property";
36+
en.Component = new MyComponent();
37+
en.Component.ComponentProperty = "component property";
38+
39+
IFullTextSession s = Search.CreateFullTextSession(OpenSession());
40+
ITransaction tx = s.BeginTransaction();
41+
await (s.SaveAsync(en));
42+
await (s.FlushAsync());
43+
await (tx.CommitAsync());
44+
45+
tx = s.BeginTransaction();
46+
47+
QueryParser parser = new QueryParser(Version.LUCENE_24, "id", new StandardAnalyzer(Version.LUCENE_24));
48+
Lucene.Net.Search.Query luceneQuery = parser.Parse("entity:alarm");
49+
IFullTextQuery query = s.CreateFullTextQuery(luceneQuery, typeof(MyEntity));
50+
Assert.AreEqual(1, query.ResultSize, "Entity query");
51+
52+
luceneQuery = parser.Parse("property:cat");
53+
query = s.CreateFullTextQuery(luceneQuery, typeof(MyEntity));
54+
Assert.AreEqual(1, query.ResultSize, "Property query");
55+
56+
luceneQuery = parser.Parse("field:energy");
57+
query = s.CreateFullTextQuery(luceneQuery, typeof(MyEntity));
58+
Assert.AreEqual(1, query.ResultSize, "Field query");
59+
60+
luceneQuery = parser.Parse("component.componentProperty:noise");
61+
query = s.CreateFullTextQuery(luceneQuery);
62+
Assert.AreEqual(1, query.ResultSize, "Component query");
63+
64+
await (s.DeleteAsync(await (query.UniqueResultAsync())));
65+
await (tx.CommitAsync());
66+
67+
s.Close();
68+
}
69+
}
70+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Collections;
13+
using System.Collections.Generic;
14+
using Lucene.Net.Analysis;
15+
using Lucene.Net.Analysis.Standard;
16+
using Lucene.Net.QueryParsers;
17+
using NHibernate.Cfg;
18+
using NUnit.Framework;
19+
using Version = Lucene.Net.Util.Version;
20+
21+
namespace NHibernate.Search.Tests.Bridge
22+
{
23+
using System.Threading.Tasks;
24+
[TestFixture]
25+
public class BridgeTestAsync : SearchTestCase
26+
{
27+
protected override void Configure(Configuration configuration)
28+
{
29+
base.Configure(configuration);
30+
configuration.SetProperty(Environment.AnalyzerClass, typeof(SimpleAnalyzer).AssemblyQualifiedName);
31+
}
32+
33+
protected override IEnumerable<string> Mappings
34+
{
35+
get { return new string[] {"Bridge.Cloud.hbm.xml"}; }
36+
}
37+
38+
[Test]
39+
public async Task CustomBridgesAsync()
40+
{
41+
Cloud cloud = new Cloud();
42+
cloud.CustomFieldBridge = ("This is divided by 2");
43+
cloud.CustomStringBridge = ("This is div by 4");
44+
ISession s = OpenSession();
45+
ITransaction tx = s.BeginTransaction();
46+
await (s.SaveAsync(cloud));
47+
await (s.FlushAsync());
48+
await (tx.CommitAsync());
49+
50+
tx = s.BeginTransaction();
51+
IFullTextSession session = Search.CreateFullTextSession(s);
52+
QueryParser parser = new QueryParser(Version.LUCENE_24, "id", new SimpleAnalyzer());
53+
54+
Lucene.Net.Search.Query query = parser.Parse("CustomFieldBridge:This AND CustomStringBridge:This");
55+
IList result = await (session.CreateFullTextQuery(query).ListAsync());
56+
Assert.AreEqual(1, result.Count, "Properties not mapped");
57+
58+
query = parser.Parse("CustomFieldBridge:by AND CustomStringBridge:is");
59+
result = await (session.CreateFullTextQuery(query).ListAsync());
60+
Assert.AreEqual(0, result.Count, "Custom types not taken into account");
61+
62+
await (s.DeleteAsync(await (s.GetAsync(typeof(Cloud), cloud.Id))));
63+
await (tx.CommitAsync());
64+
s.Close();
65+
}
66+
67+
[Test]
68+
public async Task DateTimeBridgeAsync()
69+
{
70+
Cloud cloud = new Cloud();
71+
72+
DateTime date = new DateTime(2000, 12, 15, 3, 43, 2);
73+
cloud.DateTime = (date); //5 millisecond
74+
cloud.DateTimeDay = (date);
75+
cloud.DateTimeHour = (date);
76+
cloud.DateTimeMillisecond = (date);
77+
cloud.DateTimeMinute = (date);
78+
cloud.DateTimeMonth = (date);
79+
cloud.DateTimeSecond = (date);
80+
cloud.DateTimeYear = (date);
81+
ISession s = OpenSession();
82+
ITransaction tx = s.BeginTransaction();
83+
await (s.SaveAsync(cloud));
84+
await (s.FlushAsync());
85+
await (tx.CommitAsync());
86+
87+
tx = s.BeginTransaction();
88+
IFullTextSession session = Search.CreateFullTextSession(s);
89+
QueryParser parser = new QueryParser(Version.LUCENE_24, "id", new StandardAnalyzer(Version.LUCENE_24));
90+
91+
Lucene.Net.Search.Query query = parser.Parse("DateTime:[19900101 TO 20060101]"
92+
+ " AND DateTimeDay:[20001214 TO 2000121501]"
93+
+ " AND DateTimeMonth:[200012 TO 20001201]"
94+
+ " AND DateTimeYear:[2000 TO 200001]"
95+
+ " AND DateTimeHour:[20001214 TO 2000121503]"
96+
+ " AND DateTimeMinute:[20001214 TO 200012150343]"
97+
+ " AND DateTimeSecond:[20001214 TO 20001215034302]"
98+
+ " AND DateTimeMillisecond:[20001214 TO 20001215034302005]"
99+
);
100+
IList result = await (session.CreateFullTextQuery(query).ListAsync());
101+
Assert.AreEqual(1, result.Count, "DateTime not found or not property truncated");
102+
103+
await (s.DeleteAsync(await (s.GetAsync(typeof(Cloud), cloud.Id))));
104+
await (tx.CommitAsync());
105+
s.Close();
106+
}
107+
108+
[Test]
109+
public async Task DefaultAndNullBridgesAsync()
110+
{
111+
Cloud cloud = new Cloud();
112+
cloud.DateTime = null;
113+
cloud.Double1 = (null);
114+
cloud.Double2 = (2.1d);
115+
cloud.Int1 = (null);
116+
cloud.Int2 = (2);
117+
cloud.Float1 = (null);
118+
cloud.Float2 = (2.1f);
119+
cloud.Long1 = (null);
120+
cloud.Long2 = (2L);
121+
cloud.String1 = (null);
122+
cloud.Type = (CloudType.Dog);
123+
cloud.Storm = (false);
124+
ISession s = OpenSession();
125+
ITransaction tx = s.BeginTransaction();
126+
await (s.SaveAsync(cloud));
127+
await (s.FlushAsync());
128+
await (tx.CommitAsync());
129+
130+
tx = s.BeginTransaction();
131+
IFullTextSession session = Search.CreateFullTextSession(s);
132+
QueryParser parser = new QueryParser(Version.LUCENE_24, "id", new StandardAnalyzer(Version.LUCENE_24));
133+
134+
Lucene.Net.Search.Query query = parser.Parse("Double2:[2 TO 2.1] AND Float2:[2 TO 2.1] " +
135+
"AND Int2:[2 TO 2.1] AND Long2:[2 TO 2.1] AND Type:\"Dog\" AND Storm:false");
136+
137+
IList result = await (session.CreateFullTextQuery(query).ListAsync());
138+
Assert.AreEqual(1, result.Count, "find primitives and do not fail on null");
139+
140+
query = parser.Parse("Double1:[2.1 TO 2.1] OR Float1:[2 TO 2.1] " +
141+
"OR Int1:[2 TO 2.1] OR Long1:[2 TO 2.1]");
142+
result = await (session.CreateFullTextQuery(query).ListAsync());
143+
Assert.AreEqual(0, result.Count, "null elements should not be stored"); //the query is dumb because restrictive
144+
145+
query = parser.Parse("Type:Dog");
146+
result = await (session.CreateFullTextQuery(query).SetProjection("Type").ListAsync());
147+
Assert.AreEqual(1, result.Count, "Enum projection works"); //the query is dumb because restrictive
148+
149+
await (s.DeleteAsync(await (s.GetAsync(typeof(Cloud), cloud.Id))));
150+
await (tx.CommitAsync());
151+
s.Close();
152+
}
153+
}
154+
}

0 commit comments

Comments
 (0)