public ProductModel Execute() { using (var context = new RedisContext()) { var product = new ProductModel(); product.ProductId = ProductId; var cachedValue = context.Database.StringGet(product.CacheKey); if (cachedValue.IsNullOrEmpty) { var searcher = new ContentSearcher(); var productModel = searcher.GetProductById(this.ProductId); context.Database.StringSet(productModel.CacheKey, JsonConvert.SerializeObject(productModel)); return(productModel); } return(JsonConvert.DeserializeObject <ProductModel>(cachedValue)); } }
public ResultSet Get(string id, string searchTerms) { ContentSearcher search = null; try { if (id == "current") { search = this.GetSearcher(App.Instance.Content.ContentFolder); } else { search = this.GetSearcher(id); } var res = search.Search(searchTerms); return(new ResultSet { HitCount = res.HitCount, Results = res.Results.Select(r => new Result { AssetId = r.AssetId.ToString(), Title = r.Title, Url = r.Url, Blurb = r.Blurb }).ToArray() }); } finally { if (search != null) { this.ReleaseSeracher(search); } } }
public SearchResult <ProductModel> Execute() { using (var context = new RedisContext()) { var cachedObject = context.Database.StringGet(Query.CacheKey); if (cachedObject.IsNullOrEmpty) { var searcher = new ContentSearcher(); //Search with elastic search SearchResult <ProductModel> searchResult = searcher.Search(Query); Task.Run(() => { using (var tmpContext = new RedisContext()) { var serializedValue = JsonConvert.SerializeObject(searchResult); tmpContext.Database.StringSet(Query.CacheKey, serializedValue); } }); return(searchResult); } var result = JsonConvert.DeserializeObject <SearchResult <ProductModel> >(cachedObject); return(result); } }
private void ReleaseSeracher(ContentSearcher searcher) { searcher.Release(); }
public ActionResult IndexDocument(string id, int index) { string contentRoot = this.Content.GetContentRoot(id); string indexRoot = Path.Combine(contentRoot, "Index"); using (ContentSearcher searcher = new ContentSearcher(indexRoot)) { SearchResultSet result = searcher.Search("special:all", offset: index, count: 1, includeRawData: true); string nextUri; if (index == result.HitCount - 1) nextUri = null; else nextUri = Url.Action("IndexDocument", new { id, index = index + 1 }); string previousUri; if (index == 0) previousUri = null; else previousUri = Url.Action("IndexDocument", new { id, index = index - 1 }); string firstUri, lastUri; if (result.HitCount > 0) { firstUri = Url.Action("IndexDocument", new { id, index = 0 }); lastUri = Url.Action("IndexDocument", new { id, index = result.HitCount - 1 }); } else { firstUri = null; lastUri = null; } return this.View("IndexDocument", new IndexDocumentModel { Count = result.HitCount, Fields = result.Results.Length > 0 ? result.Results[0].RawDocument : null, Index = index, NextUri = nextUri, PreviousUri = previousUri, FirstUri = firstUri, LastUri = lastUri }); } }