Extension methods for EPiServer Find.
- Conditional filtering: Adds an easy way to add filters based on a condition.
- Terms Facet: Retrieve TermsFacet for int properties instead of string properties.
- Wildcards: Allows you to perform queries with wildcards.
int? someId = ....;
var searchResult = client.Search<any>()
.Filter(x => x.ExampleProp1.Match(true))
// Only apply filter if someId has a value
.Conditional(someId.HasValue, r => r.Filter(x => x.ExampleProp2.Match(someId.Value)))
.Filter(x => x.ExampleProp3);
Useful if you want to have the termfacet for a given id property (where the id is an int obviously).
public class Test {
public virtual string StringProp { get; set; }
public virtual int IntProp { get; set; }
}
var searchResult = client.Search<Test>()
.Take(0)
.TermsFacetFor(x => x.StringProp)
// TermsFacetFor only exists for string properties
// The actual api works with ints (numbers) as well
.TermsFacetFor(x => x.IntProp);
Being able to set result size for termfacet, easily discoverable by IntelliSense.
var resultSize = 1000;
var searchResult = client.Search<Test>()
.Take(0)
// Easily add resultSize to TermsFacetFor
.TermsFacetFor(x => x.IntProp, resultSize)
// Resharper/IntelliSense does not like this notation too much
// And you obviously want to use it on int properties as well right!?
.TermsFacetFor(x => x.StringProp, r => r.Size = resultSize);
return typeSearch.For(query, stringQuery =>
{
stringQuery.Query = AddWildcards(stringQuery.Query.ToString());
stringQuery.AllowLeadingWildcard = allowLeadingWildcard;
stringQuery.AnalyzeWildcard = analyzeWildCard;
stringQuery.FuzzyMinSim = fuzzyMinSim;
});
var searchResult = SearchClient.Instance.Search<ArticlePage>()
.ForWithWildcards(searchQuery, (x => x.Title, 1.5), (x => x.Name, 0.5))
.GetContentResultSafe();
Makes it easy to return an empty results instead of an error, useful in case find is unstable/down. See this and this
// Throws exception
var contentResult = search
.GetContentResult(cacheForSeconds, cacheForEditorsAndAdmins);
// Returns empty result in case of ClientException or ServiceException
var contentResult = search
.GetContentResultSafe(cacheForSeconds, cacheForEditorsAndAdmins);
See description in shared repository regarding how to setup local development environment.
Instead of using the static IP addresses the following hostnames can be used out-of-the-box.