SearchHelper.Search(parameters) always returns null

Aaron Fickes asked on January 19, 2015 21:56

            SearchIndexInfo sii =   SearchIndexInfoProvider.GetSearchIndexInfo("ProductSearch");
            SearchParameters parameters = new SearchParameters
                SearchFor = keywords,
                SearchSort = null,
                Path = null,
                ClassNames = null,
                CurrentCulture = "##ALL##",
                DefaultCulture = null,
                CombineWithDefaultCulture = false,
                CheckPermissions = false,
                SearchInAttachments = false,
                User = MembershipContext.AuthenticatedUser,
                SearchIndexes = sii.IndexName,
                NumberOfResults = 100,
                AttachmentWhere = null,
                AttachmentOrderBy = null,
            DataSet sr = SearchHelper.Search(parameters);

The result is always null. The SearchIndexInfo at the top is correctly populated with the right search index. What am I doing wrong with the parameters?

I can search in the index search screen, and that module is where I got the code above. If I put a smartsearch results web part on a page it displays results correctly, but I can't search through the API.

Recent Answers

Roman Koníček answered on January 20, 2015 13:45

Hi Steve,

Could you please specify also DisplayResults and NumberOfProcessedResults parameters? Does it make any difference if you add them to your code?

Best Regards, Roman Konicek

1 votesVote for this answer Mark as a Correct answer

Aaron Fickes answered on January 20, 2015 18:07

Yes! Now it comes back with results.

Now the question is how do I get the NodeID or DocumentID of a result? I can get a URL using the SearchResultUrl(bool absolute) method, but I need to load the document itself. How can I get the document represented by the result?

0 votesVote for this answer Mark as a Correct answer

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

Hi Steve,

I am glad to hear that. When using SearchHelper.Search, it returns a dataset. Looking at a single row, the id field contains up to 3 bits of information, e. g. e.g. id = 126;126_cms.document. First part is node id, second document id and the third the class name. So you can split the string and parse the document id or node id out and use it for accesing the document and its data. You could take an inspiration from code example below.

// Get Datarows for current results
Hashtable resultRows = RequestStockHelper.GetItem(SearchHelper.RESULTS_KEY) as Hashtable;

// Check whether id and datarow collection exists
if ((id != String.Empty) && (resultRows != null))
// Get current datarow
DataRow dr = resultRows[id] as DataRow;

// Check whether datarow exists and contains required column
if ((dr != null) && (dr.Table.Columns.Contains(columnName)))
// Return column value
return dr[columnName];

where ID is available in the dataset. I hope it helps.

Regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

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