How to add the URL to Smart Search results

Tim Coy asked on July 15, 2019 04:34

Hi

I have been following the example for Smart Search on Github

The SearchResultItem has a field for Url.

Using the example SearchService

var searchItem = new SearchResultItem<BaseInfo>
{
    Fields = new SearchFields
    {
        Title = row["title"].ToString(),
        Content = row["content"].ToString(),
        ImagePath = GetImagePath(objectType, id, row["image"].ToString()),
        Date = date,
        ObjectType = objectType
    },
    Data = GetDataObject(id, objectType)
};

I can readily see the Title etc being extracted from row["Title"] etc.

I can not see how to get the url from the DataRow so that I can create a hyperlink to the page.

I have tried using

    ValidationHelper.GetString(SearchContext.GetSearchValue(id, SearchFieldsConstants.CUSTOM_URL), "#")

but this only returns the default value.

Would somebody please point me to the documentation or in the right direction?

Thanks

Tim

Correct Answer

Dragoljub Ilic answered on July 15, 2019 17:18

Hi Tim,

You should be able to access to all indexed content data through Data property, so if you need node alias path, you can try something like: ValidationHelper.GetString(resultItem.Data.GetValue(nameof(TreeNode.NodeAliasPath)), String.Empty)

where resultItem is returned from search service (SearchResultItem instance of object).

1 votesVote for this answer Unmark Correct answer

Recent Answers


Tim Coy answered on July 15, 2019 18:44

Thank you Dragoljub, that was exactly what I was looking for.

0 votesVote for this answer Mark as a Correct answer

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