/// <summary> /// An extension of Item that allows you to launch a Search from an item /// </summary> /// <returns>List of Results of Type IEnumerable List of SitecoreItem (which implements IItem)</returns> /// <param name="startLocationItem">The start location of the search</param> /// <param name="queryParser">The raw JSON Parse query</param> /// <param name="hitCount">This will output the hitCount of the search</param> /// <param name="indexName">Force query to run on a particular index</param> public static IEnumerable <SitecoreItem> Search(this Item itm, Query rawLuceneQuery, out int hitCount, int pageSize = 20, int pageNumber = 1, string indexName = "itembuckets_buckets") { using (var searcher = new IndexSearcher(indexName)) { var keyValuePair = searcher.RunQuery(rawLuceneQuery, pageSize, pageNumber); hitCount = keyValuePair.Key; return(keyValuePair.Value); } }
public List <string> GetRecent() { using (var searcher = new IndexSearcher(Constants.Index.Name)) { var query = new RangeQuery(new Term("__smallUpdatedDate", DateTime.Now.AddDays(-1).ToString("yyyyMMdd")), new Term("__smallUpdatedDate", DateTime.Now.ToString("yyyyMMdd")), true); var ret = searcher.RunQuery(query, 10, 0).Value.Select(i => i.GetItem().Name + "|" + i.GetItem().ID.ToString()).ToList(); ret.Reverse(); return(ret.Take(10).ToList()); } }