Skip to content

Commit 4c217e6

Browse files
committed
Merge pull request #4 from rdavanzo/master
Providing more access to FilterDefs from IFullTextSession
2 parents faf2da5 + f2bc757 commit 4c217e6

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/NHibernate.Search/Engine/ISearchFactoryImplementor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ public interface ISearchFactoryImplementor : ISearchFactory
2525

2626
IFilterCachingStrategy GetFilterCachingStrategy();
2727

28-
FilterDef GetFilterDefinition(string name);
29-
3028
LuceneIndexingParameters GetIndexingParameters(IDirectoryProvider provider);
3129

3230
void AddIndexingParameters(IDirectoryProvider provider, LuceneIndexingParameters indexingParameters);
3331

3432
void Close();
33+
34+
/// <summary>
35+
/// Adds a FilterDef object to the ISearchFactory implementation with the given name.
36+
/// In most cases, FilterDefs should be added during mapping configuration in a
37+
/// custom ISearchMapping implementation. This method enables FilterDefs to be added
38+
/// after mapping at run-time anytime an IFullTextSession is available.
39+
/// </summary>
40+
/// <param name="name"></param>
41+
/// <param name="filter"></param>
42+
void AddFilterDefinition(string name, FilterDef filter);
3543
}
3644
}

src/NHibernate.Search/ISearchFactory.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using NHibernate.Search.Engine;
12
using NHibernate.Search.Reader;
23
using NHibernate.Search.Store;
34

@@ -35,5 +36,22 @@ public interface ISearchFactory
3536
/// </summary>
3637
/// <param name="entityType"></param>
3738
void Optimize(System.Type entityType);
39+
40+
/// <summary>
41+
/// Gets a FilterDef object by name from the ISearchFactory implementation.
42+
/// A return value indicates if a matching FilterDef was found
43+
/// </summary>
44+
/// <param name="name"></param>
45+
/// <param name="filter"></param>
46+
/// <returns>True/false whether or not a FilterDef exists for the name.</returns>
47+
bool TryGetFilterDefinition(string name, out FilterDef filter);
48+
49+
/// <summary>
50+
/// Gets a FilterDef object by name from the ISearchFactory implementation.
51+
/// Throws an exception if one does not exist.
52+
/// </summary>
53+
/// <param name="name"></param>
54+
/// <returns>A FilterDef object associated with the included name parameter.</returns>
55+
FilterDef GetFilterDefinition(string name);
3856
}
3957
}

src/NHibernate.Search/Impl/SearchFactoryImpl.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,21 @@ public void RegisterDirectoryProviderForLocks(IDirectoryProvider provider)
288288
}
289289
}
290290

291+
public bool TryGetFilterDefinition(string name, out FilterDef filter)
292+
{
293+
return filterDefinitions.TryGetValue(name, out filter);
294+
}
295+
291296
public FilterDef GetFilterDefinition(string name)
292297
{
293298
return filterDefinitions[name];
294299
}
295300

301+
public void AddFilterDefinition(string name, FilterDef filter)
302+
{
303+
filterDefinitions.Add(name, filter);
304+
}
305+
296306
public IOptimizerStrategy GetOptimizerStrategy(IDirectoryProvider provider)
297307
{
298308
return dirProviderOptimizerStrategy[provider];

0 commit comments

Comments
 (0)