/// <summary>
        /// Determine Bucket Count and Render Output
        /// </summary>
        private void RenderBucketCount()
        {
            var writer = new HtmlTextWriter(new StringWriter());
            writer.Write("<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\">");
            var items = new List<SitecoreItem>();

            foreach (var index in SearchHelper.GetIndexes())
            {
                using (var searcher = new IndexSearcher(index.Name))
                {
                    items.AddRange(searcher.GetItemsViaFieldQuery("isbucket", "1").Value);
                }
            }

            var bucketCount = items.Count;
            writer.Write("<tr>");
            writer.Write("<td align=\"right\">");
            writer.Write("Number of Buckets: ");
            writer.Write("</td>");
            writer.Write("<td align=\"right\">");
            writer.Write(bucketCount);
            writer.Write(' ');
            writer.Write("Items");
            writer.Write("</td>");
            writer.Write("</tr>");
            this.Buckets.Controls.Add(new LiteralControl(writer.InnerWriter.ToString()));
        }
Ejemplo n.º 2
0
        public List<FacetReturn> Filter(Query query, List<SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
        {
            var buckets = new List<SitecoreItem>();
            using (var searcher = new IndexSearcher(Constants.Index.Name))
            {
                if (locationFilter.IsNotEmpty())
                {
                    buckets.AddRange(
                        searcher.GetItemsViaFieldQuery("isbucket", "1", 200).Value.Where(item => item.GetItem().IsNotNull()).Where(
                            itm => Context.ContentDatabase.GetItem(locationFilter).Axes.IsAncestorOf(itm.GetItem())));
                }
            }

            var bucketsSelectToList = buckets.OrderBy(i => i.GetItem().Name).Select(item => item.GetItem().ID.ToString()).ToList();

            var returnFacets = this.GetSearch(query, bucketsSelectToList, searchQuery, locationFilter, baseQuery).Select(
                          facet =>
                          new FacetReturn
                          {
                              KeyName = Context.ContentDatabase.GetItem(facet.Key).Name,
                              Value = facet.Value.ToString(),
                              Type = "location",
                              ID = facet.Key
                          });

            return returnFacets.ToList();
        }
Ejemplo n.º 3
0
        public List <FacetReturn> Filter(Query query, List <SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
        {
            var buckets = new List <SitecoreItem>();

            using (var searcher = new IndexSearcher(Constants.Index.Name))
            {
                if (locationFilter.IsNotEmpty())
                {
                    buckets.AddRange(
                        searcher.GetItemsViaFieldQuery("isbucket", "1", 200).Value.Where(item => item.GetItem().IsNotNull()).Where(
                            itm => Context.ContentDatabase.GetItem(locationFilter).Axes.IsAncestorOf(itm.GetItem())));
                }
            }

            var bucketsSelectToList = buckets.OrderBy(i => i.GetItem().Name).Select(item => item.GetItem().ID.ToString()).ToList();

            var returnFacets = this.GetSearch(query, bucketsSelectToList, searchQuery, locationFilter, baseQuery).Select(
                facet =>
                new FacetReturn
            {
                KeyName = Context.ContentDatabase.GetItem(facet.Key).Name,
                Value   = facet.Value.ToString(),
                Type    = "location",
                ID      = facet.Key
            });

            return(returnFacets.ToList());
        }
Ejemplo n.º 4
0
 public Dictionary <string, int> GetSearch(Query query, List <string> filters, List <SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
 {
     using (var searcher = new IndexSearcher(Constants.Index.Name))
     {
         var results = searcher.RunFacet(query, false, true, 0, 0, "_path", filters, baseQuery, locationFilter);
         return(results);
     }
 }
Ejemplo n.º 5
0
 public Dictionary<string, int> GetSearch(Lucene.Net.Search.Query query, List<string> filter, List<Util.SearchStringModel> searchQuery, string locationFilter, System.Collections.BitArray baseQuery)
 {
     using (var searcher = new IndexSearcher(ItemBucket.Kernel.Util.Constants.Index.Name))
     {
         var results = searcher.RunFacet(query, false, false, 0, 0, "dimensions", filter, baseQuery, locationFilter);
         return results;
     }
 }
Ejemplo n.º 6
0
 public Dictionary<string, int> GetSearch(Query query, List<string> filters, List<SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
 {
     using (var searcher = new IndexSearcher(Constants.Index.Name))
     {
         var results = searcher.RunFacet(query, false, true, 0, 0, "_template", filters, baseQuery,locationFilter);
         return results;
     }
 }
 public Dictionary<string, int> GetSearch(Query query, List<string> filter, List<SearchStringModel> searchQuery, string locationFilter, BitArray baseQuery)
 {
     using (var searcher = new IndexSearcher(ItemBucket.Kernel.Util.Constants.Index.Name))
     {
         var results = searcher.RunFacet(query, false, false, 0, 0, "size", filter, baseQuery, locationFilter);
         return results;
     }
 }
 public List<string> Process()
 {
     using (var searcher = new IndexSearcher(Constants.Index.Name))
     {
         var query = new RangeQuery(new Term(SearchFieldIDs.UpdatedDate, DateTime.Now.AddDays(-1).ToString("yyyyMMdd")), new Term(SearchFieldIDs.UpdatedDate, DateTime.Now.AddDays(1).ToString("yyyyMMdd")), true);
         var ret = searcher.RunQuery(query, 10, 1, SearchFieldIDs.UpdatedDate, "desc").Value.Where(item => item.GetItem().IsNotNull()).Select(i => i.GetItem().Name + "|" + i.GetItem().ID.ToString()).ToList();
         return ret.Any() ? ret : new List<string> { "There have been no items recently created within the last day" };
     }
 }
 public List <string> Process()
 {
     using (var searcher = new IndexSearcher(Constants.Index.Name))
     {
         var query = new RangeQuery(new Term(SearchFieldIDs.UpdatedDate, DateTime.Now.AddDays(-1).ToString("yyyyMMdd")), new Term(SearchFieldIDs.UpdatedDate, DateTime.Now.AddDays(1).ToString("yyyyMMdd")), true);
         var ret   = searcher.RunQuery(query, 10, 1, SearchFieldIDs.UpdatedDate, "desc").Value.Where(item => item.GetItem().IsNotNull()).Select(i => i.GetItem().Name + "|" + i.GetItem().ID.ToString()).ToList();
         return(ret.Any() ? ret : new List <string> {
             "There have been no items recently created within the last day"
         });
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
 /// </summary>
 /// <param name="itm">
 /// The itm.
 /// </param>
 /// <param name="currentSearchString">
 /// The current Search String.
 /// </param>
 /// <param name="hitCount">
 /// The hit Count.
 /// </param>
 /// <param name="indexName">
 /// The index Name.
 /// </param>
 /// <param name="sortField">
 /// The sort Field.
 /// </param>
 /// <param name="sortDirection">
 /// The sort Direction.
 /// </param>
 /// <param name="pageSize">
 /// The page Size.
 /// </param>
 /// <param name="pageNumber">
 /// The page Number.
 /// </param>
 /// <param name="parameters">
 /// The parameters.
 /// </param>
 /// <returns>
 /// IEnumreable List of Results that have been typed to a smaller version of the Item Object
 /// </returns>
 public static IEnumerable<SitecoreItem> FullSearch(this Item itm, List<SearchStringModel> currentSearchString, out int hitCount, string indexName = "itembuckets_buckets", string sortField = "", string sortDirection = "", int pageSize = 0, int pageNumber = 0, object[] parameters = null)
 {
     using (var searcher = new IndexSearcher(indexName))
     {
         var rangeSearch = SearchHelper.GetSearchSettings(currentSearchString, LocationFilter);
         var locationIdFromItem = itm != null ? itm.ID.ToString() : string.Empty;
         rangeSearch.SortDirection = sortDirection;
         rangeSearch.SortByField = sortField;
         rangeSearch.PageNumber = pageNumber;
         rangeSearch.PageSize = pageSize;
         rangeSearch.LocationIds = rangeSearch.LocationIds == string.Empty ? locationIdFromItem : rangeSearch.LocationIds;
         var returnResult = searcher.GetItems(rangeSearch);
         hitCount = returnResult.Key;
         return returnResult.Value;
     }
 }
Ejemplo n.º 11
0
 /// <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;
     }
 }
Ejemplo n.º 12
0
   /// <summary>
   /// Gets the items from searcher.
   /// </summary>
   /// <param name="searcher">The searcher.</param>
   /// <param name="dateSearchParam">The date search parameter.</param>
   /// <param name="hitCount">The hit count.</param>
   /// <returns>The list of the items.</returns>
   private static IEnumerable<SitecoreItem> GetItemsFromSearcher(
 IndexSearcher searcher, DateRangeSearchParam dateSearchParam, out int hitCount)
   {
       KeyValuePair<int, List<SitecoreItem>> keyValuePair = searcher.GetItems(dateSearchParam);
         hitCount = keyValuePair.Key;
         return keyValuePair.Value;
   }
Ejemplo n.º 13
0
        /// <summary>
        /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
        /// </summary>
        /// <returns>IEnumreable List of Results that have been typed to a smaller version of the Item Object</returns>
        public static IEnumerable<SitecoreItem> Search(this Item itm, out int hitCount, string relatedIds = "", string indexName = "itembuckets_buckets", string text = "", string templates = "", string location = "", string sortDirection = "", string language = "en", string id = "", string sortField = "", string itemName = "", string startDate = "", string endDate = "", int numberOfItemsToReturn = 20, int pageNumber = 0)
        {
            using (var searcher = new IndexSearcher(indexName))
            {
                var dateSearchParam = new DateRangeSearchParam
                                          {
                                              ItemName = itemName,
                                              FullTextQuery = text,
                                              RelatedIds = relatedIds,
                                              TemplateIds = templates,
                                              LocationIds = location.IsEmpty() ? itm.ID.ToString() : location,
                                              Language = language,
                                              ID = id,
                                              SortDirection = sortDirection,
                                              SortByField = sortField,
                                              PageSize = numberOfItemsToReturn,
                                              PageNumber = pageNumber,
                                              Ranges = SearchHelper.GetDateRefinements(startDate,endDate)
                                          };
                var keyValuePair = searcher.GetItems(dateSearchParam);

                hitCount = keyValuePair.Key;
                return keyValuePair.Value;
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
 /// </summary>
 /// <returns>IEnumerable List of Results that have been typed to a smaller version of the Item Object</returns>
 public static IEnumerable<SitecoreItem> Search(this Item itm, SearchParam queryParser, out int hitCount, string indexName = "itembuckets_buckets")
 {
     using (var searcher = new IndexSearcher(indexName))
     {
         var keyValuePair = searcher.GetItems(queryParser);
         hitCount = keyValuePair.Key;
         return keyValuePair.Value;
     }
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
        /// </summary>
        /// <returns>IEnumreable List of Results that have been typed to a smaller version of the Item Object</returns>
        public static IEnumerable<SitecoreItem> Search(this Item itm, List<SearchStringModel> currentSearchString, out int hitCount, string indexName = "itembuckets_buckets", string sortField = "", string sortDirection = "", int numberOfItems = 20, int pageNumber = 0)
        {
            var refinements = new SafeDictionary<string>();
            var searchStringModels = SearchHelper.GetTags(currentSearchString);

            if (searchStringModels.Count > 0)
            {
                foreach (var ss in searchStringModels)
                {
                    var query = ss.Value;
                    if (query.Contains("tagid="))
                    {
                        query = query.Split('|')[1].Replace("tagid=", string.Empty);
                    }
                    var db = Context.ContentDatabase ?? Context.Database;
                    refinements.Add("_tags", db.GetItem(query).ID.ToString());
                }
            }

            using (var searcher = new IndexSearcher(indexName))
            {
                var sitecoreItems = searcher.GetItems(new DateRangeSearchParam()
                    {
                        FullTextQuery = SearchHelper.GetText(currentSearchString),
                        RelatedIds = string.Empty,
                        TemplateIds = SearchHelper.GetTemplates(currentSearchString),
                        LocationIds = itm.ID.ToString(),
                        Refinements = refinements,
                        SortByField = sortField,
                        PageNumber = pageNumber,
                        PageSize = numberOfItems
                    });

                hitCount = sitecoreItems.Key;
                return sitecoreItems.Value;
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
        /// </summary>
        /// <returns>IEnumerable List of Results that have been typed to a smaller version of the Item Object</returns>
        public static IEnumerable<SitecoreItem> Search(this Item itm, SafeDictionary<string> refinements, out int hitCount,
            string relatedIds = "",
            string indexName = "itembuckets_buckets", 
            string text = "", 
            string templates = "", 
            string location = "", 
            string language = "en", 
            string id = "", 
            string sortField = "", 
            string itemName = "", 
            string startDate = "",
            int pageNumber = 0,
            string endDate = "", 
            string sortDirection = "",
            int numberOfItemsToReturn = 20, 
            object[] parameters = null)
        {
            if (itm.IsNull())
            {
                Log.Warn("You are trying to run an Item Extension on an item that is null", "");
                hitCount = 0;
                return new List<SitecoreItem>();
            }

            using (var searcher = new IndexSearcher(indexName))
            {
                var dateSearchParam = new DateRangeSearchParam
                                          {
                                              ItemName = itemName,
                                              FullTextQuery = text,
                                              RelatedIds = relatedIds,
                                              TemplateIds = templates,
                                              LocationIds = location.IsEmpty() ? itm.ID.ToString() : location,
                                              Language = language,
                                              SortDirection = sortDirection,
                                              Refinements = refinements,
                                              ID = id,
                                              SortByField = sortField,
                                              PageSize = numberOfItemsToReturn,
                                              PageNumber = pageNumber,
                                              Ranges = SearchHelper.GetDateRefinements(startDate, endDate)
                                          };
                var keyValuePair = searcher.GetItems(dateSearchParam);
                hitCount = keyValuePair.Key;
                return keyValuePair.Value;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Searches the with parameter occurrence.
        /// </summary>
        /// <param name="startLocationItem">The start location item.</param>
        /// <param name="refinements">The refinements.</param>
        /// <param name="hitCount">The hit count.</param>
        /// <param name="relatedIds">The related ids.</param>
        /// <param name="indexName">Name of the index.</param>
        /// <param name="text">The text.</param>
        /// <param name="templates">The templates.</param>
        /// <param name="location">The location.</param>
        /// <param name="language">The language.</param>
        /// <param name="id">The id.</param>
        /// <param name="sortField">The sort field.</param>
        /// <param name="sortDirection">The sort direction.</param>
        /// <param name="itemName">Name of the item.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <param name="numberOfItemsToReturn">The number of items to return.</param>
        /// <param name="pageNumber">The page number.</param>
        /// <param name="customParametersOccurance">The custom parameters occurrence.</param>
        /// <returns></returns>
        public static IEnumerable<SitecoreItem> SearchWithParameterOccurance(
      Item startLocationItem,
      SafeDictionary<string> refinements,
      out int hitCount,
      string relatedIds = "",
      string indexName = "itembuckets_buckets",
      string text = "",
      string templates = "",
      string location = "",
      string language = "en",
      string id = "",
      string sortField = "",
      string sortDirection = "",
      string itemName = "",
      string startDate = "",
      string endDate = "",
      int numberOfItemsToReturn = 20,
      int pageNumber = 1,
      QueryOccurance customParametersOccurance = QueryOccurance.Must)
        {
            Contract.Requires(startLocationItem.IsNotNull());

              using (var searcher = new IndexSearcher(indexName))
              {
            DateRangeSearchParam dateSearchParam = GetFullParameters(
              startLocationItem,
              refinements,
              relatedIds,
              indexName = "itembuckets_buckets",
              text,
              templates,
              location,
              language,
              id,
              sortField,
              sortDirection,
              itemName,
              startDate,
              endDate,
              numberOfItemsToReturn,
              pageNumber,
              customParametersOccurance);
            if (dateSearchParam.IsNull())
            {
              hitCount = 0;
              return new List<SitecoreItem>();
            }
            return GetItemsFromSearcher(searcher, dateSearchParam, out hitCount);
              }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
        /// </summary>
        /// <returns>IEnumreable List of Results that have been typed to a smaller version of the Item Object</returns>
        public static IEnumerable<SitecoreItem> Search(this Item itm, out int hitCount, string relatedIds = "", string indexName = "itembuckets_buckets", string text = "", string templates = "", string location = "", string sortDirection = "", string language = "en", string id = "", string sortField = "", string itemName = "", string startDate = "", string endDate = "", int numberOfItemsToReturn = 20, int pageNumber = 0)
        {
            var culture = CultureInfo.CreateSpecificCulture("en-US");
            var startDateOut = new DateTime();
            var endDateOut = new DateTime();
            var startFlag = true;
            var endFlag = true;
            if (!DateTime.TryParse(startDate, culture, DateTimeStyles.None, out startDateOut))
            {
                startDateOut = DateTime.Now;
                startFlag = false;
            }

            if (!DateTime.TryParse(endDate, culture, DateTimeStyles.None, out endDateOut))
            {
                endDateOut = DateTime.Now.AddDays(1);
                endFlag = false;
            }

            using (var searcher = new IndexSearcher(indexName))
            {
                var dateSearchParam = new DateRangeSearchParam
                                          {
                                              ItemName = itemName,
                                              FullTextQuery = text,
                                              RelatedIds = relatedIds,
                                              TemplateIds = templates,
                                              LocationIds = location.IsEmpty() ? itm.ID.ToString() : location,
                                              Language = language,
                                              ID = id,
                                              SortDirection = sortDirection,
                                              SortByField = sortField,
                                              PageSize = numberOfItemsToReturn,
                                              PageNumber = pageNumber
                                          };
                var keyValuePair = searcher.GetItems(dateSearchParam);

                if (startFlag || endFlag)
                {
                    dateSearchParam.Ranges = new List<DateRangeSearchParam.DateRangeField>
                                                 {
                                                     new DateRangeSearchParam.DateRangeField(SearchFieldIDs.CreatedDate, startDateOut, endDateOut)
                                                         {
                                                             InclusiveStart = true, InclusiveEnd = true
                                                         }
                                                 };
                }

                hitCount = keyValuePair.Key;
                return keyValuePair.Value;
            }
        }
Ejemplo n.º 19
0
 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();
     }
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Get Items to be loaded when the Control is loaded on the item
        /// </summary>
        /// <param name="current">
        /// The current.
        /// </param>
        /// <returns>
        /// Array of Item
        /// </returns>
        protected override Item[] GetItems(Item current)
        {
            Assert.ArgumentNotNull(current, "current");
            var values = StringUtil.GetNameValues(Source, '=', '&');
            var refinements = new SafeDictionary<string>();
            if (values["FieldsFilter"] != null)
            {
                var splittedFields = StringUtil.GetNameValues(values["FieldsFilter"], ':', ',');
                foreach (string key in splittedFields.Keys)
                {
                    refinements.Add(key, splittedFields[key]);
                }
            }

            var locationFilter = values["StartSearchLocation"];
            locationFilter = MakeFilterQuerable(locationFilter);

            var templateFilter = values["TemplateFilter"];
            templateFilter = MakeTemplateFilterQuerable(templateFilter);

            var pageSize = values["PageSize"];
            var searchParam = new DateRangeSearchParam
            {
                Refinements = refinements,
                LocationIds = locationFilter.IsNullOrEmpty() ? Sitecore.Context.ContentDatabase.GetItem(this.ItemID).GetParentBucketItemOrRootOrSelf().ID.ToGuid().ToEnumerable() : IdHelper.ParseId(locationFilter),
                TemplateIds = IdHelper.ParseId(templateFilter),
                FullTextQuery = values["FullTextQuery"],
                Language = values["Language"],
                PageSize = pageSize.IsEmpty() ? 10 : int.Parse(pageSize),
                PageNumber = this.pageNumber,
                SortByField = values["SortField"],
                SortDirection = values["SortDirection"]
            };

            this.filter = "&location=" + (locationFilter.IsNullOrEmpty() ? Sitecore.Context.ContentDatabase.GetItem(this.ItemID).GetParentBucketItemOrRootOrSelf().ID.ToString() : locationFilter) +
                     "&filterText=" + values["FullTextQuery"] +
                     "&language=" + values["Language"] +
                     "&pageSize=" + (pageSize.IsEmpty() ? 10 : int.Parse(pageSize)) +
                     "&sort=" + values["SortField"];

            if (values["TemplateFilter"].IsNotNull())
            {
                this.filter += "&template=" + templateFilter;
            }

            using (var searcher = new IndexSearcher(Constants.Index.Name))
            {
                var keyValuePair = searcher.GetItems(searchParam);
                var items = keyValuePair.Value;
                this.pageNumber = keyValuePair.Key / searchParam.PageSize;
                if (this.pageNumber <= 0)
                {
                    this.pageNumber = 1;
                }
                return items.Select(sitecoreItem => sitecoreItem.GetItem()).Where(i => i != null).ToArray();
            }
        }
Ejemplo n.º 21
0
        private List<List<FacetReturn>> GetFacets()
        {
            var ret = new List<List<FacetReturn>>();
            var facets = Context.ContentDatabase.GetItem(Constants.FacetFolder).Children;
            foreach (Item facet in facets)
            {
                if (facet.Fields["Enabled"].Value == "1")
                {
                    var type = Activator.CreateInstance(Type.GetType(facet.Fields["Type"].Value));
                    if ((type as IFacet).IsNotNull())
                    {
                        var locationOverride = GetLocationOverride();
                        var indexName = BucketManager.GetContextIndex(Context.ContentDatabase.GetItem(locationOverride));
                        using (var searcher = new IndexSearcher(indexName))
                        using (var context = new SortableIndexSearchContext(SearchManager.GetIndex(indexName)))
                        {

                            var query = SearchHelper.GetBaseQuery(this._searchQuery, locationOverride);
                            var queryBase = searcher.ContructQuery(query);
                            var searchBitArray = new QueryFilter(queryBase).Bits(context.Searcher.GetIndexReader());
                            var res = ((IFacet)type).Filter(queryBase, this._searchQuery, locationOverride, searchBitArray);
                            ret.Add(res);
                        }
                    }
                }
            }

            return ret;
        }
Ejemplo n.º 22
0
   /// <summary>
   /// An extension of Item that allows you to launch a Search from an item
   /// </summary>
   /// <param name="startLocationItem">The start location of the search</param>
   /// <param name="hitCount">This will output the hitCount of the search</param>
   /// <param name="currentSearchString">The raw JSON Parse query</param>
   /// <param name="indexName">Force query to run on a particular index</param>
   /// <param name="sortField">Sort query by field (must be in index)</param>
   /// <param name="sortDirection">Sort in either "asc" or "desc"</param>
   /// <returns>
   /// List of Results of Type IEnumerable List of SitecoreItem (which implements IItem)
   /// </returns>
   /// <example>BucketManager.Search(Sitecore.Context.Item, SearchModel)</example>
   public static IEnumerable<SitecoreItem> Search(
 Item startLocationItem,
 out int hitCount,
 List<SearchStringModel> currentSearchString,
 string indexName = "itembuckets_buckets",
 string sortField = "",
 string sortDirection = "")
   {
       string locationIdFromItem = startLocationItem != null ? startLocationItem.ID.ToString() : string.Empty;
         DateRangeSearchParam rangeSearch = SearchHelper.GetSearchSettings(currentSearchString, locationIdFromItem);
         if (!sortField.IsNullOrEmpty())
         {
       rangeSearch.SortByField = sortField;
         }
         if (!sortDirection.IsNullOrEmpty())
         {
       rangeSearch.SortDirection = sortDirection;
         }
         using (var searcher = new IndexSearcher(indexName))
         {
       KeyValuePair<int, List<SitecoreItem>> returnResult = searcher.GetItems(rangeSearch);
       hitCount = returnResult.Key;
       return returnResult.Value;
         }
   }
        /// <summary>
        /// Using a strongly types List of SearchStringModel, you can run a search based off a JSON String
        /// </summary>
        /// <param name="itm">
        /// The itm.
        /// </param>
        /// <param name="currentSearchString">
        /// The current Search String.
        /// </param>
        /// <param name="hitCount">
        /// The hit Count.
        /// </param>
        /// <param name="indexName">
        /// The index Name.
        /// </param>
        /// <param name="sortField">
        /// The sort Field.
        /// </param>
        /// <param name="sortDirection">
        /// The sort Direction.
        /// </param>
        /// <param name="pageSize">
        /// The page Size.
        /// </param>
        /// <param name="pageNumber">
        /// The page Number.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        /// <returns>
        /// IEnumreable List of Results that have been typed to a smaller version of the Item Object
        /// </returns>
        public static IEnumerable<SitecoreItem> FullSearch(this Item itm, List<SearchStringModel> currentSearchString, out int hitCount, string indexName = "itembuckets_buckets", string sortField = "", string sortDirection = "", int pageSize = 0, int pageNumber = 0, object[] parameters = null)
        {
            var startDate = DateTime.Now;
            var endDate = DateTime.Now.AddDays(1);
            var locationSearch = LocationFilter;
            var refinements = new SafeDictionary<string>();
            var searchStringModels = SearchHelper.GetTags(currentSearchString);

            if (searchStringModels.Count > 0)
            {
                foreach (var ss in searchStringModels)
                {
                    var query = ss.Value;
                    if (query.Contains("tagid="))
                    {
                        query = query.Split('|')[1].Replace("tagid=", string.Empty);
                    }
                    var db = Context.ContentDatabase ?? Context.Database;
                    refinements.Add("_tags", db.GetItem(query).ID.ToString());
                }
            }

            var author = SearchHelper.GetAuthor(currentSearchString);

            var languages = SearchHelper.GetLanguages(currentSearchString);
            if (languages.Length > 0)
            {
                refinements.Add("_language", languages);
            }

            var references = SearchHelper.GetReferences(currentSearchString);

            var custom = SearchHelper.GetCustom(currentSearchString);
            if (custom.Length > 0)
            {
                var customSearch = custom.Split('|');
                if (customSearch.Length > 0)
                {
                    try
                    {
                        refinements.Add(customSearch[0], customSearch[1]);
                    }
                    catch (Exception exc)
                    {
                      Log.Error("Could not parse the custom search query", exc);
                    }
                }
            }

            var search = SearchHelper.GetField(currentSearchString);
            if (search.Length > 0)
            {
                var customSearch = search;
                refinements.Add(customSearch, SearchHelper.GetText(currentSearchString));
            }

            var fileTypes = SearchHelper.GetFileTypes(currentSearchString);
            if (fileTypes.Length > 0)
            {
                refinements.Add("extension", SearchHelper.GetFileTypes(currentSearchString));
            }

            var s = SearchHelper.GetSite(currentSearchString);
            if (s.Length > 0)
            {
                SiteContext siteContext = SiteContextFactory.GetSiteContext(SiteManager.GetSite(s).Name);
                var db = Context.ContentDatabase ?? Context.Database;
                var startItemId = db.GetItem(siteContext.StartPath);
                locationSearch = startItemId.ID.ToString();
            }

            var culture = CultureInfo.CreateSpecificCulture("en-US");
            var startFlag = true;
            var endFlag = true;
            if (SearchHelper.GetStartDate(currentSearchString).Any())
            {
                if (!DateTime.TryParse(SearchHelper.GetStartDate(currentSearchString), culture, DateTimeStyles.None, out startDate))
                {
                    startDate = DateTime.Now;
                }

                startFlag = false;
            }

            if (SearchHelper.GetEndDate(currentSearchString).Any())
            {
                if (!DateTime.TryParse(SearchHelper.GetEndDate(currentSearchString), culture, DateTimeStyles.None, out endDate))
                {
                    endDate = DateTime.Now.AddDays(1);
                }

                endFlag = false;
            }

            using (var searcher = new IndexSearcher(indexName))
            {
                var location = SearchHelper.GetLocation(currentSearchString, locationSearch);
                var locationIdFromItem = itm != null ? itm.ID.ToString() : string.Empty;
                var rangeSearch = new DateRangeSearchParam
                                {
                                    ID = SearchHelper.GetID(currentSearchString).IsEmpty() ? SearchHelper.GetRecent(currentSearchString) : SearchHelper.GetID(currentSearchString),
                                    ShowAllVersions = false,
                                    FullTextQuery = SearchHelper.GetText(currentSearchString),
                                    Refinements = refinements,
                                    RelatedIds = references.Any() ? references : string.Empty,
                                    SortDirection = sortDirection,
                                    TemplateIds = SearchHelper.GetTemplates(currentSearchString),
                                    LocationIds = location == string.Empty ? locationIdFromItem : location,
                                    Language = languages,
                                    SortByField = sortField,
                                    PageNumber = pageNumber,
                                    PageSize = pageSize,
                                    Author = author == string.Empty ? string.Empty : author,
                                };

                if (!startFlag || !endFlag)
                {
                    rangeSearch.Ranges = new List<DateRangeSearchParam.DateRangeField>
                                             {
                                                 new DateRangeSearchParam.DateRangeField(SearchFieldIDs.CreatedDate, startDate, endDate)
                                                     {
                                                         InclusiveStart = true, InclusiveEnd = true
                                                     }
                                             };
                }

                var returnResult = searcher.GetItems(rangeSearch);
                hitCount = returnResult.Key;
                return returnResult.Value;
            }
        }