marcel_g
marcel_g

Reputation: 2030

Kentico Smart Search Index - any way to read it with the API?

We need to get a search box autocomplete working based on Kentico search indexes, but half the site is in the CMS app pages, and half is in MVC. So the autocomplete webpart works on the CMS app pages, but not the MVC ones.

An option we're exploring is to use the Twitter Typeahead js library in both sides of the site, which requires the search terms to be in a json file.

So we'd like to be able to load the search index terms via the Kentico API and then write that out to a json file.

The SearchIndexInfo object doesn't seem to have a way to get the index's terms that it writes out to the index files.

Update

For clarification: We can do the search via the API, but the searchresultitems only return with the title and content fields, and they do not contain all the search terms that are stored in the index files.

For instance, a search index for a custom page type might build the index based on the DocumentName, Description, Location, City, Company Name, DesignCategory fields. All of those will be stored in the index somewhere, so how do we read the terms that are stored in the index?

Not just the results, which would only have DocumentName(title) and Description (content).

We're basically trying to convert the search index files into a json representation, not the search results.

Of course, if the SmartSearchDialog webpart just does its predictive search on only the title and content fields, then we would just go with that, but I believe the SmartSearchDialog does an actual search does it not?

thanks

Upvotes: 1

Views: 697

Answers (2)

marcel_g
marcel_g

Reputation: 2030

Roman's answer in the comments doesn't look like it would work, and in thinking about it some more we were perhaps trying to do something too complicated and weren't asking the right question maybe.

Instead of trying to replicate the search index in json for use by the twitter typeahead autocomplete, perhaps a better way to do it is to keep it simpler and just use the search results' title and content fields.

Then, in order to get additional fields into the content field of the search results ( such as project location ) we can then customize the search building code (CMSLoaderAttribute) to add the extra fields into the SearchDocument's Content field.

Upvotes: 0

Roman Hutnyk
Roman Hutnyk

Reputation: 1549

There is API for it:

// Gets the search index
SearchIndexInfo index = SearchIndexInfoProvider.GetSearchIndexInfo("NewIndex");

if (index != null)
{
    // Prepares the search parameters
    SearchParameters parameters = new SearchParameters()
    {
        SearchFor = "home",
        SearchSort = "##SCORE##",
        Path = "/%",
        ClassNames = "",
        CurrentCulture = "EN-US",
        DefaultCulture = CultureHelper.EnglishCulture.IetfLanguageTag,
        CombineWithDefaultCulture = false,
        CheckPermissions = false,
        SearchInAttachments = false,
        User = (UserInfo)MembershipContext.AuthenticatedUser,
        SearchIndexes = index.IndexName,
        StartingPosition = 0,
        DisplayResults = 100,
        NumberOfProcessedResults = 100,
        NumberOfResults = 0,
        AttachmentWhere = String.Empty,
        AttachmentOrderBy = String.Empty,
    };

    // Performs the search and saves the results into a DataSet
    System.Data.DataSet results = SearchHelper.Search(parameters);

    if (parameters.NumberOfResults > 0)
    {
        // The search found at least one matching result, and you can handle the results

    }
}

More details here.

Upvotes: 3

Related Questions