Smart Search

Girish Patil asked on December 6, 2017 07:02

I wants to do the article list order by date descending and most repeated search keyword in titles article at top position of list from this method DataSet results = SearchHelper.Search(parameters);

Recent Answers


Matt Nield answered on December 6, 2017 10:56

You can change the order of the Smart Saerch results using the Search sort field on the Smart search results web part. The default is effectively ##SCORE## ascending, but you can put a comma separated list fo field in here and use the DESC keyword as you woulg in SQL to change the order.

Using the SearchHelper, you should be able to do something like:

var parameters = new SmartSearchParameters();
/* set your values */
parameters.SearchSort = "ArticelDate DESC"; // make this match your column names
DataSet results = SearchHelper.Search(parameters);
1 votesVote for this answer Mark as a Correct answer

Mariia Hrytsai answered on December 6, 2017 11:10

First of all I would recommend reading this article where is described how to sort results by relevance in title: https://www.bizstream.com/blog/march-2017/boost-kentico-smart-search-results-relevance-score

Then using the parameters specify all the conditions:

SearchParameters parameters = new SearchParameters()
{
    SearchFor = "(title:" + QueryHelper.GetString("searchtext", "") + ")",
    SearchSort = "ArticleCreated desc",
    Path = "/%",
    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,
    ClassNames = ""
    /* The 'SearchParameters.ClassNames' property only limits the attachment search,
    not the results of the basic SearchHelper.Search method. You can limit class names (page types)
    by adding a Lucene search condition to the text of the 'SearchFor' query. */
};

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

The code is given as examples. According to the information in article, you need to adjust your conditions.

3 votesVote for this answer Mark as a Correct answer

Girish Patil answered on December 6, 2017 15:36

Both the above solutions are not working in my case, First solution returns result as ascending order while the keyword is desc and, Second solution is returning empty result while putting string like- SearchFor = "(title:" + QueryHelper.GetString("searchtext", "") + ")",

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on December 7, 2017 17:55

I second Mariia answer. The only thing I can add is that your searchtext may contain anything - first you need strip all noise words, and boost only valid terms:

searchText="uniqueword in some other uniuqephrase"

you need transform into lucene syntax like:

_title:("uniqueword ", "uniuqephrase")^3 and _content:("uniqueword ","in", "some", "other", "uniuquniuqephrasephras")

P.S. You might end up with list of words you want to boost. My point is your want to boost only certain terms in the searchText.

1 votesVote for this answer Mark as a Correct answer

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