How to perform a search with existing SearchIndex in code

Benedikt Funk asked on October 3, 2014 14:11

Hi, today i have first touch with Kentico Smart Search. I wanted to perform an search request in code and want some results.

I found some Smart Search helper classes. In my approach i use SearchHelper.Search. But an error occured during the search.

Below you can find my simple search test:

public DataSet Search()
    {

        SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("FCBNews");

        var results = SearchHelper.Search(new SearchParameters
        {
            SearchIndexes = index.IndexCodeName,
            CurrentCulture = "de-CH",
            NumberOfResults = 10,
            SearchInAttachments = false,
            SearchSort = "DESC",

        });
        return results;
    }

And the error message:

An exception of type 'System.NotSupportedException' occurred in CMS.Core.dll but was not handled in user code Additional information: [ObjectFactory.CurrentObjectFactory]: Implementation for interface 'ISearchSyntaxHelper' was not found, make sure that assembly with implementation is present in the bin folder of your application, or call ObjectFactory<ISearchSyntaxHelper>.SetDefaultObjectTypeTo<SomeType>() to initialize the default type for this interface.

Any ideas? :-)

Many thanks, Benedikt

Recent Answers


Tomaso Pye answered on October 20, 2014 18:24

I ran into this earlier on and the issue for me was that I needed to have the CMS.Search.Lucene3.dll present. It may also require the Lucene.Net.v3.dll as well (I am less sure of this requirement, but easiest enough to try)

0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on November 30, 2014 09:28

Hi Benedikt,

Did you also try to perfom a search request via our user interface as described here https://docs.kentico.com/display/K81/Setting+up+search+on+your+website? Does smart search work correctly this way or are there any error messages?

Roman Konicek

0 votesVote for this answer Mark as a Correct answer

Aaron Fickes answered on January 19, 2015 19:23

I am doing a similar search, but the problem I am seeing is that the search always returns a null.

SearchParameters parameters = new SearchParameters { SearchFor = keywords, CurrentCulture = CultureHelper.DefaultUICultureCode, CheckPermissions = false, SearchInAttachments = false, SearchIndexes = "ProductSearch", }; DataSet sr = SearchHelper.Search(parameters);

The variable sr always comes back null. I've made sure the index files are there, and I can search in the index admin screen, but it always comes back null, whether I simplify the parameters or set them all explicitly.

0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on January 20, 2015 22:08

Hi,

I am just informing that the thread continues here http://devnet.kentico.com/questions/searchhelper-search(parameters)-always-returns-null

Best regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

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