how to set searchmode to allwords in api SearchHelper.Search(params)

santosh maroju asked on June 18, 2019 08:54

Hi team, I want to set searchmode to allword before SearchHelper.Search(params). Following is the snippet i am using. Please help. Thanks in advance!

SearchIndexInfo articleIndex = SearchIndexInfoProvider.GetSearchIndexInfo("ArticleIndex");
                    SearchIndexInfo GAndPIndex = SearchIndexInfoProvider.GetSearchIndexInfo("GuidesAndPublication");

                    SearchParameters pars = new SearchParameters()
                    {
                        SearchFor = key,
                        Path = "/%",
                        CurrentCulture = CultureHelper.EnglishCulture.IetfLanguageTag,
                        DefaultCulture = null,
                        CombineWithDefaultCulture = false,
                        CheckPermissions = false,
                        SearchInAttachments = false,
                        SearchIndexes = articleIndex.IndexName + ";" + GAndPIndex.IndexName,
                        User = MembershipContext.AuthenticatedUser,
                        DisplayResults = 100,
                        NumberOfProcessedResults = 100,
                        NumberOfResults = 0,
                        AttachmentWhere = null,
                        AttachmentOrderBy = null,
                        ClassNames = "custom.article,custom.GuidesAndPublication",
                        SearchSort = null
                    };

                    result = SearchHelper.Search(pars);

Correct Answer

Dmitry Bastron answered on June 18, 2019 13:24

Hi Santosh,

You can do it like this:

var condition = new SearchCondition(null, SearchModeEnum.AllWords, SearchOptionsEnum.FullSearch);
var searchText = SearchSyntaxHelper.CombineSearchCondition(key, condition);

SearchParameters pars = new SearchParameters()
{
    SearchFor = searchText,
    // ...
};

result = SearchHelper.Search(pars);
0 votesVote for this answer Unmark Correct answer

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