Performing a search

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

The following sample code shows how you can perform a search and get the results into a DataSet:

 

[C#]

 

using System.Data;

using CMS.SiteProvider;

using CMS.CMSHelper;

using CMS.GlobalHelper;

 

...

 

        // Get index object from database by index code name

        SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo("TestIndex");

 

        int numberOfResults;

 

        // If index exists

        if (sii != null)

        {

 

            // Set properties

            string searchText = "Search text";

            string path = "/%";

            string classNames = "";

            string cultureCode = "EN-US";

            string defaultCulture = CultureHelper.DefaultCulture.IetfLanguageTag;

            Lucene.Net.Search.Sort sort = SearchHelper.GetSort("##SCORE##");

            bool combineWithDefaultCulture = false;

            bool checkPermissions = false;

            bool searchInAttachments = false;

            string searchIndexes = sii.IndexName;

            int displayResults = 100;

            int startingPosition = 0;

            int numberOfProcessedResults = 100;

            UserInfo userInfo = CMSContext.CurrentUser;

            string attachmentWhere = "";

            string attachmentOrderBy = "";

 

            // Get search results

          DataSet ds = SearchHelper.Search(searchText, sort, path, classNames, cultureCode, defaultCulture, combineWithDefaultCulture, checkPermissions, searchInAttachments, searchIndexes, displayResults, startingPosition, numberOfProcessedResults, userInfo, out numberOfResults, attachmentWhere, attachmentOrderBy);

 

            // If at least one item is found

            if (numberOfResults > 0)

            {

 

                // Perform some action with result dataset

 

            }

        }

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?api_performing_a_search.htm