Skip to content

Commit e027838

Browse files
committed
Getting to compile with NH 3.4.0.1000 and Lucene.Net 2.9.4.2
1 parent c6c9bfd commit e027838

File tree

10 files changed

+182
-42
lines changed

10 files changed

+182
-42
lines changed
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
using System;
12
using System.Collections;
23
using Lucene.Net.Index;
4+
using Lucene.Net.Search;
35

46
namespace NHibernate.Search.Tests.Filter
57
{
68
public class BestDriversFilter : Lucene.Net.Search.Filter
79
{
8-
public override BitArray Bits(IndexReader reader)
10+
public override DocIdSet GetDocIdSet(IndexReader reader)
911
{
10-
BitArray bitArray = new BitArray(reader.MaxDoc());
11-
TermDocs termDocs = reader.TermDocs(new Term("score", "5"));
12-
while (termDocs.Next())
13-
{
14-
bitArray.Set(termDocs.Doc(), true);
15-
}
12+
throw new NotImplementedException();
13+
//BitArray bitArray = new BitArray(reader.MaxDoc());
14+
//TermDocs termDocs = reader.TermDocs(new Term("score", "5"));
15+
//while (termDocs.Next())
16+
//{
17+
// bitArray.Set(termDocs.Doc(), true);
18+
//}
1619

17-
return bitArray;
20+
//return bitArray;
1821
}
1922
}
2023
}
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
using System;
22
using System.Collections;
33
using Lucene.Net.Index;
4+
using Lucene.Net.Search;
45

56
namespace NHibernate.Search.Tests.Filter
67
{
78
public class ExcludeAllFilter : Lucene.Net.Search.Filter
89
{
910
private static bool done = false;
1011

11-
public override BitArray Bits(IndexReader reader)
12+
public override DocIdSet GetDocIdSet(IndexReader reader)
1213
{
13-
if (done)
14-
{
15-
throw new NotSupportedException("Called twice");
16-
}
14+
throw new NotImplementedException();
15+
//if (done)
16+
//{
17+
// throw new NotSupportedException("Called twice");
18+
//}
1719

18-
BitArray bitArray = new BitArray(reader.MaxDoc());
19-
done = true;
20+
//BitArray bitArray = new BitArray(reader.MaxDoc());
21+
//done = true;
2022

21-
return bitArray;
23+
//return bitArray;
2224
}
2325
}
2426
}

src/NHibernate.Search/Filter/ChainedFilter.cs

Lines changed: 122 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace NHibernate.Search.Filter
24
{
35
using System.Collections;
@@ -16,32 +18,45 @@ public void AddFilter(Filter filter)
1618
chainedFilters.Add(filter);
1719
}
1820

19-
public override BitArray Bits(IndexReader reader)
21+
public override DocIdSet GetDocIdSet(IndexReader reader)
2022
{
2123
if (chainedFilters.Count == 0)
2224
{
2325
throw new AssertionFailure("ChainedFilter has no filters to chain for");
2426
}
2527

2628
// We need to copy the first BitArray because BitArray is assigned to by And
27-
Filter filter = chainedFilters[0];
28-
BitArray result = (BitArray)filter.Bits(reader).Clone();
29-
int size = result.Count;
30-
for (int index = 1; index < chainedFilters.Count; index++ )
31-
{
32-
BitArray b2 = chainedFilters[index].Bits(reader);
33-
int s2 = b2.Count;
34-
if (s2 != size)
29+
HashSet<int> result = null;
30+
31+
foreach (var filter in chainedFilters)
32+
{
33+
DocIdSet b2 = filter.GetDocIdSet(reader);
34+
int docId;
35+
DocIdSetIterator iterator = b2.Iterator();
36+
37+
if (result == null)
3538
{
36-
// Align the lengths, any extra elements are set to false, ok as as we are Anding
37-
b2.Length = size;
38-
}
39+
result = new HashSet<int>();
3940

40-
// Stared at this for hours - C# compiler doesn't warn when you discard a function result!
41-
result = result.And(b2);
41+
while ((docId = iterator.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
42+
{
43+
result.Add(docId);
44+
}
45+
}
46+
else
47+
{
48+
while ((docId = iterator.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
49+
{
50+
if (!result.Contains(docId))
51+
{
52+
result.Remove(docId);
53+
}
54+
}
55+
}
4256
}
4357

44-
return result;
58+
DocIdSet filteredCombinedDocIdSet = new EnumerableBasedDocIdSet(result);
59+
return filteredCombinedDocIdSet;
4560
}
4661

4762
public override string ToString()
@@ -55,4 +70,96 @@ public override string ToString()
5570
return sb.Append("\r\n]").ToString();
5671
}
5772
}
73+
74+
public class EnumerableBasedDocIdSet : DocIdSet
75+
{
76+
private readonly IEnumerable<int> _items;
77+
78+
public EnumerableBasedDocIdSet(IEnumerable<int> items)
79+
{
80+
if (items == null)
81+
{
82+
throw new ArgumentNullException("items");
83+
}
84+
85+
_items = items;
86+
}
87+
88+
/// <summary>
89+
/// Provides a <see cref="T:Lucene.Net.Search.DocIdSetIterator"/> to access the set.
90+
/// This implementation can return <c>null</c> or
91+
/// <c>EMPTY_DOCIDSET.Iterator()</c> if there
92+
/// are no docs that match.
93+
/// </summary>
94+
public override DocIdSetIterator Iterator()
95+
{
96+
return new EnumerableBasedDocIdSetIterator(_items);
97+
}
98+
}
99+
100+
public class EnumerableBasedDocIdSetIterator : DocIdSetIterator
101+
{
102+
private readonly IEnumerable<int> items;
103+
private IEnumerator<int> iterator;
104+
private int? currentIndex;
105+
106+
public EnumerableBasedDocIdSetIterator(IEnumerable<int> items)
107+
{
108+
if (items == null)
109+
{
110+
throw new ArgumentNullException("items");
111+
}
112+
113+
this.items = items;
114+
iterator = items.GetEnumerator();
115+
}
116+
117+
public override int Advance(int target)
118+
{
119+
if (currentIndex == null)
120+
{
121+
currentIndex = 0;
122+
}
123+
124+
if (target < currentIndex)
125+
{
126+
throw new ArgumentOutOfRangeException("target", target, "Iterator state past target: " + currentIndex);
127+
}
128+
129+
int remaining = target - currentIndex.Value;
130+
bool hasMore;
131+
132+
while ((hasMore = iterator.MoveNext()) && remaining > 0)
133+
{
134+
currentIndex++;
135+
}
136+
137+
if (!hasMore)
138+
{
139+
currentIndex = NO_MORE_DOCS;
140+
}
141+
142+
return currentIndex == NO_MORE_DOCS ? NO_MORE_DOCS : iterator.Current;
143+
}
144+
145+
public override int DocID()
146+
{
147+
if (currentIndex == NO_MORE_DOCS || currentIndex == null)
148+
{
149+
return NO_MORE_DOCS;
150+
}
151+
152+
return iterator.Current;
153+
}
154+
155+
public override int NextDoc()
156+
{
157+
if (currentIndex == NO_MORE_DOCS)
158+
{
159+
return NO_MORE_DOCS;
160+
}
161+
162+
return Advance(currentIndex.Value + 1);
163+
}
164+
}
58165
}

src/NHibernate.Search/Impl/FullTextSessionImpl.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,13 @@ public void Save(object obj, object id)
239239
public object Save(string entityName, object obj)
240240
{
241241
return session.Save(entityName, obj);
242-
}
243-
242+
}
243+
244+
public void Save(string entityName, object obj, object id)
245+
{
246+
session.Save(entityName, obj, id);
247+
}
248+
244249
public void SaveOrUpdate(object obj)
245250
{
246251
session.SaveOrUpdate(obj);
@@ -249,8 +254,13 @@ public void SaveOrUpdate(object obj)
249254
public void SaveOrUpdate(string entityName, object obj)
250255
{
251256
session.SaveOrUpdate(entityName, obj);
252-
}
253-
257+
}
258+
259+
public void SaveOrUpdate(string entityName, object obj, object id)
260+
{
261+
session.SaveOrUpdate(entityName, obj, id);
262+
}
263+
254264
public void Update(object obj)
255265
{
256266
session.Update(obj);
@@ -264,8 +274,13 @@ public void Update(object obj, object id)
264274
public void Update(string entityName, object obj)
265275
{
266276
session.Update(entityName, obj);
267-
}
268-
277+
}
278+
279+
public void Update(string entityName, object obj, object id)
280+
{
281+
session.Update(entityName, obj, id);
282+
}
283+
269284
public object Merge(object obj)
270285
{
271286
return session.Merge(obj);

src/NHibernate.Search/NHSearch.snk

596 Bytes
Binary file not shown.

src/NHibernate.Search/NHibernate.Search.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
<WarningLevel>4</WarningLevel>
5454
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
5555
</PropertyGroup>
56+
<PropertyGroup>
57+
<SignAssembly>true</SignAssembly>
58+
</PropertyGroup>
59+
<PropertyGroup>
60+
<AssemblyOriginatorKeyFile>NHSearch.snk</AssemblyOriginatorKeyFile>
61+
</PropertyGroup>
5662
<ItemGroup>
5763
<Reference Include="ICSharpCode.SharpZipLib">
5864
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
@@ -221,6 +227,7 @@
221227
<None Include="Cfg\nhs-configuration.xsx">
222228
<DependentUpon>nhs-configuration.xsd</DependentUpon>
223229
</None>
230+
<None Include="NHSearch.snk" />
224231
<None Include="packages.config" />
225232
</ItemGroup>
226233
<ItemGroup>

src/NHibernate.Search/Query/FullTextQueryImpl.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Text;
6-
using Lucene.Net.Search;
6+
using Lucene.Net.Search;
7+
using NHibernate.Engine;
78
using NHibernate.Engine.Query;
89
using NHibernate.Impl;
910
using NHibernate.Search.Engine;
@@ -16,7 +17,7 @@ namespace NHibernate.Search.Query
1617

1718
using Transform;
1819

19-
public class FullTextQueryImpl : AbstractQueryImpl, IFullTextQuery
20+
public class FullTextQueryImpl : QueryImpl, IFullTextQuery
2021
{
2122
private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(FullTextQueryImpl));
2223
private readonly Dictionary<string, FullTextFilterImpl> filterDefinitions;
@@ -175,7 +176,7 @@ private ILoader GetLoader(ISession session)
175176
}
176177
}
177178
}
178-
179+
179180
protected override IDictionary<string, LockMode> LockModes
180181
{
181182
get { return null; }
@@ -231,8 +232,13 @@ public override IList<T> List<T>()
231232
List(arrayList);
232233
return (T[])arrayList.ToArray(typeof(T));
233234
}
234-
}
235-
235+
}
236+
237+
//protected override IEnumerable<ITranslator> GetTranslators(ISessionImplementor sessionImplementor, QueryParameters queryParameters)
238+
//{
239+
// throw new NotImplementedException();
240+
//}
241+
236242
public override IList List()
237243
{
238244
using (new SessionIdLoggingContext(Session.SessionId))
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)