Saturday, 3 October 2015

How to do Search Condition on Kentico Smart Search Module Using API

2 comments
Below is an example of using Smart Search API module in Kentico.
The API Example inside kentico not telling this, but i was able to figure out the way. 

Kindly have a try on the snippet example 

Smart Search Module API - Search With Condition 

   public void SmartSearchWithCondition(string searchText,string ClassName,string extraCondition)  
   {       
     DocumentSearchCondition docCondition = new DocumentSearchCondition();  
     docCondition.ClassNames = ClassName;  
     docCondition.Culture = "en-US";  
     //refer https://docs.kentico.com/display/K82/Smart+search+syntax for the extra condition syntax  
     var condition = new SearchCondition(extraCondition, SearchModeEnum.AllWords, SearchOptionsEnum.FullSearch, docCondition, true);  
     searchText = SearchSyntaxHelper.CombineSearchCondition(searchText, condition);  
      // Get the search index  
     SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("SearchIndex");  
     if (index != null)  
     {  
       // Prepare parameters  
       SearchParameters parameters = new SearchParameters()  
       {  
         SearchFor = searchText,  
         SearchSort = "##SCORE##",  
         CurrentCulture = "EN-US",  
         DefaultCulture = CultureHelper.EnglishCulture.IetfLanguageTag,  
         CombineWithDefaultCulture = false,  
         CheckPermissions = false,  
         SearchInAttachments = false,  
         User = (UserInfo)MembershipContext.AuthenticatedUser,  
         SearchIndexes = index.IndexName,  
         StartingPosition = 0,  
         AttachmentWhere = String.Empty,  
         AttachmentOrderBy = String.Empty,  
       };  
       // Search  
       DataSet results = SearchHelper.Search(parameters);  
       // If found at least one item  
       if (parameters.NumberOfResults > 0)  
       {  
         //do your works here  
       }  
     }  
   }  

Have a try!


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

2 comments:

  1. Kentico 13 xperience developers I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.

    ReplyDelete
  2. Excellent Write up. Thank you for the great information.  Kentico Developer

    ReplyDelete

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.