Using search api and specify ClassName in SearchParameters does not work.

Nattawut Comlon asked on November 9, 2015 06:12

I am trying to use this API to get the result from the document tree "SearchHelper.Search(parameters)". However, it looks like the result is not return with the class name that I specify within the "SearchParameters.ClassNames".

Anyone know how to filter the result by class name?

I am using Kentico 8.2 and this is the code that I create the search parameter object.

var parameters = new SearchParameters()
    SearchFor = this.txt.Text,
    SearchSort = "##SCORE##",
    Path = "/%",
    ClassNames = "CMS.MenuItem",
    CurrentCulture = "EN-AU",
    DefaultCulture = CultureHelper.EnglishCulture.IetfLanguageTag,
    CombineWithDefaultCulture = false,
    CheckPermissions = false,
    SearchInAttachments = false,
    User = (UserInfo)MembershipContext.AuthenticatedUser,
    SearchIndexes = index.IndexName,
    StartingPosition = 0,
    DisplayResults = int.MaxValue,
    NumberOfProcessedResults = int.MaxValue,
    NumberOfResults = 0,
    AttachmentWhere = string.Empty,
    AttachmentOrderBy = string.Empty,
    BlockFieldOnlySearch = false

Thank you in advance.

Recent Answers

Maarten van den Hooven answered on November 9, 2015 08:10

The code seems correct, so I think you need to debug and eliminate things: 1. If you put the same parameters in a smart search web part, do you get the expected results. 2. Do you receive results? 3. Is your indexed rebuilded?

Her also some articles and documentation:

Look for example to this forum post.

Here also more information about the Smart search API

Here you can find an code example :-)

0 votesVote for this answer Mark as a Correct answer

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