Skip to content

Commit

Permalink
reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
nzdev committed Jul 30, 2023
1 parent f92ca59 commit 774342b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/Examine.Core/BaseSearchProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ protected BaseSearchProvider(string name)

/// <inheritdoc />
public abstract IQuery CreateQuery(string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);


/// <inheritdoc />
public abstract IQuery CreateQuery(Action<IFilter> filter, string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);
}
}
12 changes: 12 additions & 0 deletions src/Examine.Core/ISearcher.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Examine.Search;

namespace Examine
Expand Down Expand Up @@ -29,5 +30,16 @@ public interface ISearcher
/// An instance of <see cref="IQueryExecutor"/>
/// </returns>
IQuery CreateQuery(string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);


/// <summary>
/// Creates a search criteria instance as required by the implementation
/// </summary>
/// <param name="category">The type of data in the index.</param>
/// <param name="defaultOperation">The default operation.</param>
/// <returns>
/// An instance of <see cref="IQueryExecutor"/>
/// </returns>
IQuery CreateQuery(Action<IFilter> filter, string? category = null, BooleanOperation defaultOperation = BooleanOperation.And);
}
}
6 changes: 0 additions & 6 deletions src/Examine.Core/Search/IQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,5 @@ public interface IQuery
/// <returns></returns>
IBooleanOperation RangeQuery<T>(string[] fields, T? min, T? max, bool minInclusive = true, bool maxInclusive = true) where T : struct;

/// <summary>
/// Apply Filters
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
IQuery Filter(Action<IFilter> filter);
}
}
27 changes: 13 additions & 14 deletions src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5246,20 +5246,19 @@ public void BasicFilter(FacetTestType withFacets)

var searcher = indexer.Searcher;

var criteria = searcher.CreateQuery("content")
.Filter(
filter =>
{
filter.Term(new FilterTerm("nodeTypeAlias", "CWS_Home"))
.And()
.TermPrefix(new FilterTerm("nodeName", "my name"))
.And()
.ChainFilters(chain =>
chain.Chain(chainedFilter => chainedFilter.FieldValueExists("nodeTypeAlias"))
.Chain(ChainOperation.ANDNOT, chainedFilter => chainedFilter.FieldValueNotExists("nodeTypeAlias"))
);

});
Action<IFilter> filtering = filter =>
{
filter.Term(new FilterTerm("nodeTypeAlias", "CWS_Home"))
.And()
.TermPrefix(new FilterTerm("nodeName", "my name"))
.And()
.ChainFilters(chain =>
chain.Chain(chainedFilter => chainedFilter.FieldValueExists("nodeTypeAlias"))
.Chain(ChainOperation.ANDNOT, chainedFilter => chainedFilter.FieldValueNotExists("nodeTypeAlias"))
);

};
var criteria = searcher.CreateQuery(filtering, "content");
var boolOp = criteria.Field("nodeTypeAlias", "CWS_Home".Escape());

if (HasFacets(withFacets))
Expand Down

0 comments on commit 774342b

Please sign in to comment.