Question

How would I format my QueryText. I have multiple List paths. I want all items returned in the lists that i provide.

example:

* AND path={0}+path={1}+path={2}

Also, How do I include the columns I want returned?

Was it helpful?

Solution

You can just add multiple Path fragments - the default logic is that they will be "ORed" if there are multiple fragments for same managed property. However, you need to make a couple of more changes to your query. Firstly, you should use colon (:) after Path so that it would return you the items under the path and not just the list itself. Secondly, you should also add a filter so that only list items would be returned and not, for example, list forms. This should be the query you should use:

* Path:{0} Path:{1} Path:{2} ContentClass=STS_ListItem

or the following one for the document libraries:

* Path:{0} Path:{1} Path:{2} ContentClass=STS_ListItem_DocumentLibrary

You can use SelectProperties property to specify which managed properties you want to return, like this:

KeywordQuery query = new KeywordQuery(site);
query.QueryText = "* Path:{0} Path:{1} Path:{2} ContentClass=STS_ListItem";
query.SelectProperties.Add("AnotherManagedProperty");

Keep in mind that managed properties, which you can retrieve using search, are not the same as columns. In some cases the managed properties are created automatically during the crawl, but in other cases you have to create them manually, if you want to retrieve the column value from search.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top