smart search filter implementation

Farah El Agha asked on November 6, 2017 13:36

I want to implement a smart search filter in my project, I already bulit a smart search box connected to a searchResults pageand it is working fine, but now I want to add more options to filter these results. I am not using a web part structure so I have to implement this functionality in visual studio as a controller in aspx page. I could'nt find any example on how to do this. Can you please explain the process? or at least provide me with links where I can find examples?

also please note that I m not able to add it as a webpart directly from Kentico, I want to implement it in visual studio programatically

Recent Answers


David te Kloese answered on November 6, 2017 13:46

Hi, I assume you're building an MVC application?

You could look into the MVC sample site on nuget: https://github.com/Kentico/Mvc

this file seems like a filter: https://github.com/Kentico/Mvc/blob/master/samples/LearningKit/Controllers/ProductFilterController.cs

For the 'portal template way' you can also look into the webpart files directly.

you can find them in \CMSWebParts\SmartSearch\SearchFilter.ascx.cs

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on November 6, 2017 14:01

Hi, I dont think this is what I needed. I m going to share some of my code to make things clear: in the smart search results page:

<%@ Page Title="" Language="C#" MasterPageFile="~/CMSTemplates/Elections/Views/Templates-Ar/Site.master" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="CMSTemplates_Elections_Views_News" %>

<%@ Register Src="~/CMSTemplates/Elections/Views/Templates-Ar/SearchControls/SearchDialogWithResults.ascx" TagPrefix="uc2" TagName="SearchDialogWithResults" %> <%@ Register Src="~/CMSTemplates/Elections/Views/Templates-Ar/UserControls/SearchFilter.ascx" TagPrefix="uc1" TagName="SearchFilter" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" runat="Server">
    <section class="padding-top-bottom">
        <div class="container">            
            <div class="row">
                <section class="col-sm-8">
                    <!-- Search Panel -->
                    <uc2:SearchDialogWithResults runat="server" ID="SearchDialogWithResults"  TransformationName="cms.root.smartsearchresultswithimages" Indexes="Elections" />
                    <article class="padding-bottom">

                    </article>
                </section>
                <uc1:SearchFilter runat="server" id="SearchFilter" />
            </div>
        </div>
    </section>
</asp:Content>

for each Register I implemented a controller, for example, the code for search dialog:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="CMSWebParts_SmartSearch_SearchDialogWithResults" CodeFile="~/CMSWebParts/SmartSearch/SearchDialogWithResults.ascx.cs" %>

<%@ Register Src="~/CMSTemplates/Elections/Views/Templates-Ar/SearchControls/SearchDialog.ascx" TagPrefix="uc1" TagName="SearchDialog" %> <%@ Register Src="~/CMSTemplates/Elections/Views/Templates-Ar/SearchControls/SearchResults.ascx" TagPrefix="uc1" TagName="SearchResults" %>

<div class="padding-bottom">
    <h2 class="text-red">بحث</h2>
    <div class="SearchDialog">
        <uc1:SearchDialog runat="server" ID="srchDialog" />
    </div>
</div>
<div class="SearchResults">
    <uc1:SearchResults runat="server" ID="srchResults" />
</div>

Now I want to continue this way and add the filter for the search results.

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on November 6, 2017 14:17

I found this link:

https://devnet.kentico.com/articles/custom-filter-development-with-kentico-cms

Do you think this is what I need?

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on November 6, 2017 17:00

I think you are getting a bit confused since you are using ASPX and ASCX files but saying you are adding Controllers.

It is better to think of Kentico having 3 development models at present:

  1. Portal Development - use out of the box web parts
  2. ASPX Templates - build ASPX templates with ASCX user controls
  3. MVC - Seperate front-end to back-end (need to reimplement controls if required).

Since you are using ASPX templates you should be able to look at the SmartSearch\SearchFilter web part and copy in a lot of code as you have probably already done with the SearchResults and SearchDialog.

The key thing is the SearchResults control should contain a SearchCondition parameter so that you can pass a condition from your filter control to the results. Depending on how you actually structure the page you could potentially add the Filter HTML code to the ASPX template and process that at the Page level and then pass it into the SearchResults when it is loading.

0 votesVote for this answer Mark as a Correct answer

Laura Frese answered on November 6, 2017 18:25

Hi Farah. Please take a look at my blog post for tips on how to implement a custom search index with faceted searches.

1 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on November 7, 2017 08:32 (last edited on November 7, 2017 08:34)

Suneel Jhangiani thank you for your explanation,and you're right, I'm still new to Kentico and I handled this project after being developed by other people, so I dont have any idea on how they built the search and where they got the code. another question, can you share some examples? or for the link that I shared:

https://devnet.kentico.com/articles/custom-filter-development-with-kentico-cms

is this a right way to follow?

Also one more question, for smart search filter I would inherit from CMSAbstractQueryFilterControl right?

0 votesVote for this answer Mark as a Correct answer

Farah El Agha answered on November 7, 2017 14:00

hi guys, my problem is not solved yet, I m still not able to find any example for a smart search filter (on a ASPX structure), please help because I couldnt build my filter using the code SmartSearch\SearchFilter web part code. I need more examples to understand how to manage the code for my project requirements.

0 votesVote for this answer Mark as a Correct answer

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