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 Mohd Zulkamal
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 =)
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.
ReplyDeleteExcellent Write up. Thank you for the great information. Kentico Developer
ReplyDelete