Skip to content

Instantly share code, notes, and snippets.

@alex-wilmer
Created February 27, 2015 21:06
Show Gist options
  • Save alex-wilmer/21e5db247fe593882447 to your computer and use it in GitHub Desktop.
Save alex-wilmer/21e5db247fe593882447 to your computer and use it in GitHub Desktop.
[WebMethod]
public static String GetTopDocuments(string SearchText, string RelativeSearchPath, string ResourceTypes, string LinkedListUrl, string Program)
{
if (SPUtility.ValidateFormDigest())
{
string siteUrl = SPContext.Current.Site.Url;
if (!string.IsNullOrEmpty(Program))
{
Program = string.Format(@" Program:""{0}"" ", Program);
}
//for when pages can be searchable
string queryConstant = @"(path:""{0}{1}"" contenttype:""Halton Document"" {2} {3}) OR (contenttype:""Page"" {2} {3}) ";
string query = string.Format(queryConstant, siteUrl, RelativeSearchPath, ResourceTypes, Program);
if (!string.IsNullOrEmpty(LinkedListUrl))
{
query = "(" + query + @") OR (path:""" + LinkedListUrl + @"/DispForm.aspx*"" " + ResourceTypes + Program + " ) " + SearchText;
}
List<TopDocument> topDocuments = HaltonContext.GetTopDocuments(siteUrl, HaltonContext.Search(siteUrl, query));
var jsonSerialiser = new JavaScriptSerializer();
return jsonSerialiser.Serialize(topDocuments);
}
return "error";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment