2

My query is set to return both List Items and Documents.

contentclass:STS_ListItem OR contentclass:STS_ListItem_DocumentLibrary

When testing my query inside SharePoint the return results are correct. But in my KeyWordQuery no documents are being returned.

I believe the problem is not the query. Is there something else needed for document search?

KeywordQuery keywordQuery = new KeywordQuery(site);

string strQuery = "*";

foreach (string strPath in allLists)
{
    strQuery += " Path:" + strPath;
}

keywordQuery.QueryText = strQuery + " (contentclass:STS_ListItem OR contentclass:STS_ListItem_DocumentLibrary)";

keywordQuery.SelectProperties.Add("DMSDocTitle");

SearchExecutor searchExecutor = new SearchExecutor();
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);

var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
DataTable dataTable = resultTables.FirstOrDefault().Table;
1
  • Could you please post the code for the KeywordQuery as well? Could you also check if the user context you are running the query with actually has the permissions to see those list items and document libraries? Apr 6, 2016 at 5:49

2 Answers 2

2

You need to change it as below

contentclass:STS_ListItem OR IsDocument:True
2
  • I tested the original query and it returned the expected results, so I don't think the problem is in the query. But it doesn't hurt to try. Apr 6, 2016 at 5:51
  • I believe the problem is not the query. I gave that a try anyway and still no. thank you. Apr 6, 2016 at 15:07
1

Can you post the the next lines of the code? I'm concerned about the way you are trying to get the results agains the search service.

And the SharePoint 2013 Search Query Tool is pretty fine and helpful to test this kind of query.

EDIT:

I looked over a solution that I did years ago, and I saw that a few other parameters were needed:

KeywordQuery keywordQuery = new KeywordQuery(searchProxy);
keywordQuery.QueryText = MountTextQuery(strBusca); //method to build KQL query
keywordQuery.KeywordInclusion = KeywordInclusion.AnyKeyword;
keywordQuery.ResultsProvider = SearchProvider.Default;
keywordQuery.ResultTypes = ResultType.RelevantResults;
keywordQuery.EnableFQL = true;
keywordQuery.RowLimit = 10000;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.