Skip to content

Geta/EPi.Find.Extensions

Repository files navigation

Geta.EPi.Find.Extensions

  • Master
  • Develop
    Platform Platform

Description

Extension methods for EPiServer Find.

Features

  • 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.

Examples

Conditional filtering

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);

TermsFacetFor on int / number properties

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);

TermsFacetFor result size (take)

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);

Wildcards

return typeSearch.For(query, stringQuery =>
            {
                stringQuery.Query = AddWildcards(stringQuery.Query.ToString());
                stringQuery.AllowLeadingWildcard = allowLeadingWildcard;
                stringQuery.AnalyzeWildcard = analyzeWildCard;
                stringQuery.FuzzyMinSim = fuzzyMinSim;
            });

Wildcards with best bets applied

var searchResult = SearchClient.Instance.Search<ArticlePage>()
                .ForWithWildcards(searchQuery, (x => x.Title, 1.5), (x => x.Name, 0.5))
                .GetContentResultSafe();

Handle Client and Service exceptions

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);

Local development setup

See description in shared repository regarding how to setup local development environment.

Docker hostnames

Instead of using the static IP addresses the following hostnames can be used out-of-the-box.

Package Maintainer

https://github.com/DigIntSys

Changelog

Changelog