none
SharePoint search programtically with using result source RRS feed

  • Question

  • Hello,

    •  I  have configured search service on my server .
    •  I create result source in central admin called "Test local Result Source" .
    • I write the following code to get data by search :

       using (SPSite site = new SPSite("{site URL}))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        KeywordQuery keywordQuery = new KeywordQuery(site);
                        keywordQuery.QueryText = "Hotels";

                        keywordQuery.SourceId = new Guid("7484c9ca-e248-45d0-b544-eb67ff8940fd"); The ID of result source .
                        SearchExecutor searchExecutor = new SearchExecutor();
                        ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
                        var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
                        var resultTable = resultTables.FirstOrDefault();
                        DataTable dataTable = resultTable.Table;

                    }
                }

    • When I test the code the data table is empty .
    • when I comment the line "keywordQuery.SourceId" . the data is returned .

        How Can I choose a result source when execute the query . 


    ASk

    Sunday, September 7, 2014 1:06 PM

Answers

All replies