How to use Sharepoint Server Search (KeywordQuery class) to search through a sharepoint list? -


we have requirement users allowed search list called "reports" front-end, , advanced search, such author:"john smith" or filetype:docx, supported.

we decided can achieved using sharepoint server search api (using keyword query language). also, since possible users don't have access items in list, decided go approach use web method elevated privileges query list.

this attempt far...

public string getsearchresults(string listname, string searchquery) {     spuser superuser = spcontext.current.web.allusers[@"sharepoint\system"];     using (spsite site = new spsite(spcontext.current.web.url, superuser.usertoken))     {         keywordquery keywordquery = new keywordquery(site);         keywordquery.querytext = searchquery;          //where should listname specified?          searchexecutor searchexecutor = new searchexecutor();          resulttablecollection resulttablecollection = searchexecutor.executequery(keywordquery);          var resulttables = resulttablecollection.filter("tabletype", knowntabletypes.relevantresults);          resulttable resulttable = resulttables.firstordefault();          datatable datatable = resulttable.table;      }      //how parse result filter items in given list? } 

...but don't understand how restrict search given list or how parse search result retrieve items of list matching search query.

i'm new sharepoint search, pointers help.

this possible either give list path or list guid in query text

keywordquery.querytext = "path:/sales/lists/prospects/ (contentclass:sts_listitem or isdocument:true) -contentclass=urn:content-class:spspeople "; 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -