public IEnumerable <JObject> Get(string contentType, int skip = 0, int take = 20) { JObject[] res = index.Search("contentType: " + contentType) .Skip(skip).Take(take) .Select(hit => hit.Json) //Note: Execute the pipeline for each element found .Select(json => { using (PipelineContext context = pipeline.CreateContext(contentType, (JObject)json)) { return(pipeline.ExecuteAfterGet(json, contentType, context)); } }) .Cast <JObject>().ToArray(); return(res); //TODO: Execute pipeline for array //TODO: Paging and other neat stuff... }
public SearchResult Search(string query, int skip = 0, int take = 20) { //TODO: Throw exception on invalid query. //if (string.IsNullOrWhiteSpace(query)) // Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Must specify a query."); ISearchResult result = index .Search(query) .Skip(skip) .Take(take); //TODO: extract contenttype based on configuration. SearchResult searchResult = new SearchResult(result .Select(hit => pipeline.ExecuteAfterGet(hit.Json, (string)hit.Json.contentType, pipeline.CreateContext((string)hit.Json.contentType, (JObject)hit.Json))) .ToArray(), result.TotalCount); performance.LogAsync("search", new { totalTime = (long)result.TotalTime.TotalMilliseconds, searchTime = (long)result.SearchTime.TotalMilliseconds, loadTime = (long)result.LoadTime.TotalMilliseconds, query, skip, take, results = result.TotalCount }); return(searchResult); }