public object Search(int siteid, string keywords = "", int offset = 0, int limit = 10) { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (!siteid.IsExistingNode()) { return(Request.CreateResponse(JsonMetaResponse.GetError("siteid is not valid"))); } int total = 0; int pageTotal = 0; int jobTotal = 0; int employeeTotal = 0; try { #region Normal Search SearchOptions initialSo = new SearchOptions { Text = keywords, RootIds = new int[] { siteid }, DocumentTypes = new string[] { Constants.SkyConstants.DocumentTypes.SubPage, Constants.SkyConstants.DocumentTypes.FrontPage }, // add your own doctypes Fields = { FieldList = new List <Field> { Field.GetFieldOption("nodeName_lci", 15, null), Field.GetFieldOption("title_lci", 15, null), Field.GetFieldOption("teaser_lci", 15, null), Field.GetFieldOption(Constants.SkyConstants.Properties.ContentGrid, null, null), // add more fields to search here } }, Order = new Order { OrderType = OrderType.Score }, Limit = limit, Offset = offset, Debug = HttpContext.Current.IsDebuggingEnabled }; List <IPublishedContent> results = SkybrudSearch.SearchDocuments( out pageTotal, initialSo ).ToList(); #endregion // create response body List <SiteSearchResult> returnResults = results.Select(x => SiteSearchResult.GetFromContent(x)).ToList(); JsonMetaResponse response = JsonMetaResponse.GetSuccess(returnResults.Take(limit)); total = pageTotal + jobTotal + employeeTotal; response.SetPagination(new JsonPagination { Total = total, Limit = limit, Offset = offset }); //Set groups JObject obj = JObject.FromObject(response); return(obj); } catch (Exception ex) { Error error = new Error("Der skete en fejl på serveren"); LogHelper.Error <SiteController>(error.ToString(), ex); return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, error.Message, error))); } }
public object Search(int contextId, string keywords = "", int offset = 0, int limit = 10, string year = "") { HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (!contextId.IsExistingNode()) { return(Request.CreateResponse(JsonMetaResponse.GetError("contextId is not a valid Umbraco-node"))); } List <IPublishedContent> results; int total; try { SpecificFields fields = new SpecificFields { Fields = new List <ISpecificField> { new SpecificField { FieldName = "year", SearchTerms = new [] { year } } } }; SearchOptions initialSo = new SearchOptions { Text = keywords, DocumentTypes = new string[] { Constants.SkyConstants.DocumentTypes.NewsPage }, RootIds = new int[] { contextId }, Fields = { FieldList = new List <Field> { Field.GetFieldOption("nodeName_lci", 15, null), Field.GetFieldOption("titel_lci", 15, null), Field.GetFieldOption("teaser_lci", 15, null), Field.GetFieldOption(Constants.SkyConstants.Properties.ContentGrid, null, null) } }, Order = new Order() { FieldName = string.Format("{0}_range", Constants.SkyConstants.Properties.ContentDate), OrderDirection = OrderDirection.Descending, OrderType = OrderType.String }, DateRange = new DateRange() { FieldName = Constants.SkyConstants.Properties.ContentDate, End = DateTime.MaxValue, Start = DateTime.MinValue.AddDays(1) }, Limit = limit, Offset = offset, Debug = HttpContext.Current.IsDebuggingEnabled }; if (!string.IsNullOrEmpty(year)) { initialSo.SpecificFields = fields; } results = Skybrud.Umbraco.Search.SkybrudSearch.SearchDocuments( out total, initialSo ).ToList(); } catch (Exception ex) { Error error = new Error("Der skete en fejl på serveren"); LogHelper.Error <NewsController>(error.ToString(), ex); return(Request.CreateResponse(JsonMetaResponse.GetError(HttpStatusCode.InternalServerError, error.Message, error))); } var returnResults = results.Select(x => NewsSearchResult.GetFromContent(x)); JsonMetaResponse response = JsonMetaResponse.GetSuccess(returnResults); response.SetPagination(new JsonPagination { Total = total, Limit = limit, Offset = offset }); return(Request.CreateResponse(response)); }