Smart Search Filter in ASP.NET Core MVC

Paul Truman asked on February 25, 2021 18:32

I'm looking to apply a smart search filter to an ASP.NET Core website. I've looked at the Dancing Goat example as inspiration and got my search results working fine, but I can't seem to find any guidance or information on how to apply a smart search filter to a Core website.

Can anybody give me some guidance / link to some example if they have them on how to achieve it please? I'm just looking to filter by document page type.

Correct Answer

Dmitry Bastron answered on February 26, 2021 11:09

Hi Paul,

You can do it something like this:

var condition = SearchSyntaxHelper.CombineSearchCondition("search query",
    new SearchCondition
        DocumentCondition = new DocumentSearchCondition
            { ClassNames = "custom.pagetype.classname", Culture = "en-US" }

var parameters = new SearchParameters
    SearchFor = condition,
    Path = $"{searchRootAliasPath}%",
    CombineWithDefaultCulture = false,
    CheckPermissions = false,
    SearchInAttachments = false,
    User = MembershipContext.AuthenticatedUser,
    SearchIndexes = Constants.SearchIndexes.SearchIndex,
    StartingPosition = skip,
    NumberOfProcessedResults = ((Int64)skip + (Int64)take) >= (Int64)Int32.MaxValue ? Int32.MaxValue : skip + take,
    DisplayResults = take,
    SearchSort = searchSort

var searchResults = SearchHelper.Search(parameters);
0 votesVote for this answer Unmark Correct answer

Recent Answers

Paul Truman answered on February 26, 2021 18:19

That worked great, many thanks :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.