Smart Search MVC

Mohamad Ramadan asked on September 29, 2020 10:12

I'm working on a smart search

I need to know if I can search on specific fields of the page type and have something like advanced search

  • I have a page type called article with fields like "title, content" it has parents of Subcategory and main category page types
  • local smart search name "ArticleSearchIndes" over this page type
  • I've added the searchable fields on the page type definition

now on MVC live site, I need to implement advanced search where user can search on article title only or content or filter by category and/or subcategory

can this be implemented using smart search and how?

Recent Answers


David te Kloese answered on September 29, 2020 10:24

Hi,

How have you configured the index and page type?

To be able to search on specific fields you need to make sure the fields of the page type are set as "Searchable" (see docs: docs.kentico.com/k12sp/.../defining-local-page-indexes

Have a look at the API examples for some examples in the newest Search Patterns:

docs.kentico.com/api12sp/.../smart-search#Smartsearch-SearchingindexesofthePagestype

This does require to be on at least hotfix 12.0.32

0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on October 1, 2020 10:06 (last edited on October 1, 2020 10:08)

Hi

How to add multiple conditions/filters

i need to take user filers from text boxes like title, Content, Keywords and add them as search conditions with and between them

     var condition1 = string.Format("{0}:{1}", "title", "\"Histoy\"").ToLower();
     var searchCondition =  SearchSyntaxHelper.CombineSearchCondition(searchText, new SearchCondition(condition1,SearchModeEnum.ExactPhrase, SearchOptionsEnum.NoneSearch));
     SearchParameters searchParameters = SearchParameters.PrepareForPages(searchCondition, searchIndexNames, currentPageIndex, pageZize,MembershipContext.AuthenticatedUser, SiteContextService.CurrentSiteCulture, false);
0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on October 1, 2020 10:33

i've tested this query and seems its working if you please confirm

    var str_condition = string.Format("+({0}:{1})", "title", "\"smapleTitle\"").ToLower();
    str_condition +=  string.Format("+({0}:{1})", "Body", "\"SampleBosy\"").ToLower();
    var condition = new SearchCondition(str_condition, SearchModeEnum.ExactPhrase, SearchOptionsEnum.NoneSearch);
   searchText = SearchSyntaxHelper.CombineSearchCondition(searchText, condition);

if all ok, I need also to filter articles with its parent page types, how can I do this have the following hierarchy on the content tree - Main Category -> Sub Category -> Article

how to add a condition to the search for main and subcategories like filter only articles below one or more main category or one or more subcategories

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on October 2, 2020 10:59

Hi,

Visually it might seem more pleasant but would not recommend to use hierarchy as a filter. You could use the path as an additional filter, but it's a tricky one when you change names or move pages.

Might be an idea to have those properties (main and sub category) stored and maintained on the actual Article (can be just a drop down), this way you can also have an article that uses multiple categories.

0 votesVote for this answer Mark as a Correct answer

Mohamad Ramadan answered on October 3, 2020 09:59

can you please give a sample on how to use the path as an additional filter, and how to combine multiple paths on the filter?

on the second option shall id add those fields and make the insertion automatic I don't need the user to choose or see the main or subcategory?, and what event handler I should use in this case

0 votesVote for this answer Mark as a Correct answer

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