Esempio n. 1
0
        private IEnumerable <DataSample> PopulateBucketedDataSamples(DimensionSpecification filterDims,
                                                                     Action <DataSample, TInternal, QuerySpecification>
                                                                     sampleAction, QuerySpecification querySpec)
        {
            using (SharedLock.OpenShared(this.dataLock))
            {
                var bucketQuery = new BucketQuery(this, filterDims);
                foreach (var bucket in bucketQuery)
                {
                    foreach (var match in (querySpec.IsCrossQuery
                                               ? bucket.GetMatchesSplitByDimension(filterDims,
                                                                                   querySpec.CrossQueryDimension)
                                               : bucket.GetMatches(filterDims)))
                    {
                        if (match.DataCount == 0)
                        {
                            continue;
                        }

                        var sample = new DataSample
                        {
                            Name       = this.Name,
                            Dimensions = match.DimensionValues.Data,
                            StartTime  = bucket.StartTime.ToMillisecondTimestamp(),
                            EndTime    = bucket.EndTime.ToMillisecondTimestamp(),
                        };

                        sampleAction(sample, match.Data, querySpec);
                        yield return(sample);
                    }
                }
            }

            Events.Write.EndQueryData(this);
        }
        /// <summary>
        /// Given a query, it will return the results for a particular page
        /// </summary>
        /// <returns>Returns a page of results. Default is 20 items per page</returns>
        /// <paramref name="page">Page Number</paramref>
        public static IEnumerable <SitecoreItem> Page(this BucketQuery query, int page, out int numberOfHits)
        {
            int hitCount = 0;

            numberOfHits = hitCount;
            return(Page(query, page, 20, out hitCount));
        }
        /// <summary>
        /// Deferred Execution of the Search
        /// </summary>
        public static IEnumerable <SitecoreItem> Run(this BucketQuery query, Item startLocationItem, int numberOfHits)
        {
            var returnQuery = query.Select(subQuery => new SearchStringModel()
            {
                Type = subQuery.Split(':')[0], Value = subQuery.Split(':')[1]
            }).ToList();
            int hitCount = 0;

            numberOfHits = hitCount;
            return(startLocationItem.Search(returnQuery, out hitCount));
        }
        /// <summary>
        /// Deferred Execution of the Search
        /// </summary>
        public static IEnumerable <SitecoreItem> First(this BucketQuery query)
        {
            var returnQuery = query.Select(subQuery => new SearchStringModel()
            {
                Type  = subQuery.Split(':')[0],
                Value = subQuery.Split(':')[1]
            }).ToList();
            int hitCount = 0;

            return(Sitecore.Context.Item.Search(returnQuery, out hitCount, numberOfItems: 1, pageNumber: 1));
        }
        /// <summary>
        /// Deferred Execution of the Search
        /// </summary>
        public static IEnumerable <SitecoreItem> Run(this BucketQuery query, out int numberOfHits)
        {
            var returnQuery = query.Select(subQuery => new SearchStringModel()
            {
                Type  = subQuery.Split(':')[0],
                Value = subQuery.Split(':')[1]
            }).ToList();
            int hitCount = 0;

            numberOfHits = hitCount;
            return(BucketManager.Search(Sitecore.Context.Item, out hitCount, returnQuery));
        }
        /// <summary>
        /// Deferred Execution of the Search
        /// </summary>
        public static IEnumerable <SitecoreItem> Skip(this BucketQuery query, int count, out int numberOfHits, int skipToPage)
        {
            var returnQuery = query.Select(subQuery => new SearchStringModel()
            {
                Type  = subQuery.Split(':')[0],
                Value = subQuery.Split(':')[1]
            }).ToList();
            int hitCount = 0;

            numberOfHits = hitCount;
            return(Sitecore.Context.Item.Search(returnQuery, out hitCount, numberOfItems: count, pageNumber: skipToPage));
        }
        /// <summary>
        /// Sort by a particular field name and Run the query
        /// </summary>
        public static IEnumerable <SitecoreItem> SortBy(this BucketQuery query, string fieldName, SortDirection sortDirection, out int numberOfHits, int page, int numberOfItemsPerPage)
        {
            query.Add("sort:" + fieldName);
            var returnQuery = query.Select(subQuery => new SearchStringModel()
            {
                Type  = subQuery.Split(':')[0],
                Value = subQuery.Split(':')[1]
            }).ToList();
            int hitCount = 0;

            numberOfHits = hitCount;
            return(Sitecore.Context.Item.Search(returnQuery, out hitCount, pageNumber: page, numberOfItems: numberOfItemsPerPage, sortDirection: sortDirection == SortDirection.Ascending ? "asc" : "desc"));
        }
        /// <summary>
        /// Deferred Execution of the Search
        /// </summary>
        public static bool AnyResults(this BucketQuery query)
        {
            var returnQuery = query.Select(subQuery => new SearchStringModel()
            {
                Type  = subQuery.Split(':')[0],
                Value = subQuery.Split(':')[1]
            }).ToList();
            int hitCount = 0;
            var blah     = new List <String>();

            Sitecore.Context.Item.Search(returnQuery, out hitCount, numberOfItems: 1, pageNumber: 1);
            return(hitCount > 0);
        }
Esempio n. 9
0
        public IEnumerable <string> GetDimensionValues(string dimensionName, DimensionSpecification filterDims)
        {
            if (ReservedDimensions.StartTimeDimension.Equals(dimensionName, StringComparison.OrdinalIgnoreCase))
            {
                return(this.GetTimestampValues(b => b.StartTime));
            }
            if (ReservedDimensions.EndTimeDimension.Equals(dimensionName, StringComparison.OrdinalIgnoreCase))
            {
                return(this.GetTimestampValues(b => b.EndTime));
            }

            var values = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            if (!this.HaveDimension(dimensionName))
            {
                throw new KeyNotFoundException(dimensionName);
            }

            // If all dimensions are provided we'll end up just adding the single value back for the given dimension
            // and pushing that out -- is this a neat hack to test if a dimension value exists, or is it ridiculous?
            // Going with ridiculous today.
            int matched = (from dim in filterDims.Keys where this.HaveDimension(dim) select dim).Count();

            if (matched == this.DimensionSet.dimensions.Length)
            {
                throw new ArgumentException("All known dimensions were supplied in filter.", "filterDims");
            }

            using (SharedLock.OpenShared(this.dataLock))
            {
                var bucketQuery = new BucketQuery(this, filterDims);
                foreach (var bucket in bucketQuery)
                {
                    foreach (var value in bucket.GetDimensionValues(dimensionName, filterDims))
                    {
                        values.Add(value);
                    }
                }
            }

            return(values);
        }
        public virtual void DeferredRebuild(DateTime startDate, DateTime endDate, Database database)
        {
            Assert.ArgumentNotNull(database, "database");
            using (new SecurityDisabler())
            {
                int  hitCount;
                Item rootItem = database.GetRootItem(Context.Language);
                var  items    = new BucketQuery().Starting(startDate).Ending(endDate).Run(out hitCount);
                var  pages    = hitCount / 20;

                for (int i = 0; i <= pages; i++)
                {
                    var pagedResults = new BucketQuery().Starting(startDate).Ending(endDate).Page(i, out hitCount);
                    foreach (var itm in pagedResults)
                    {
                        this.UpdateReferences(itm.GetItem());
                    }
                }
            }

            this.Compact(database);
        }
        public virtual void DeferredRebuild(DateTime startDate, DateTime endDate, Database database)
        {
            Assert.ArgumentNotNull(database, "database");
            using (new SecurityDisabler())
            {
                int hitCount;
                Item rootItem = database.GetRootItem(Context.Language);
                var items = new BucketQuery().Starting(startDate).Ending(endDate).Run(out hitCount);
                var pages = hitCount/20;

                for (int i = 0; i <= pages; i++ )
                {
                    var pagedResults = new BucketQuery().Starting(startDate).Ending(endDate).Page(i, out hitCount);
                    foreach (var itm in pagedResults)
                    {
                        this.UpdateReferences(itm.GetItem());
                    }

                }
            }

            this.Compact(database);
        }
 /// <summary>
 /// Search for Items that are by a particular list of Authors
 /// </summary>
 public static BucketQuery WhereAuthorIs(this BucketQuery query, IEnumerable <User> authors)
 {
     query.AddRange(authors.Select(author => "author:" + author.Name));
     return(query);
 }
 /// <summary>
 /// Search for Items that contain a list of string values
 /// </summary>
 public static BucketQuery WhereContentContains(this BucketQuery query, IEnumerable <string> searchStrings)
 {
     query.AddRange(searchStrings.Select(@string => "text:" + @string));
     return(query);
 }
 public static BucketQuery Or(this BucketQuery query)
 {
     return(query);
 }
 /// <summary>
 /// Negate the next Query
 /// </summary>
 public static BucketQuery Not(this BucketQuery query)
 {
     query.Add("-");
     return(query);
 }
 /// <summary>
 /// Search for Items within a particular location
 /// </summary>
 public static BucketQuery WhereLocationIs(this BucketQuery query, ID locationId)
 {
     query.Add("location:" + locationId);
     return(query);
 }
Esempio n. 17
0
        private IEnumerable <DataSample> PopulateCombinedDataSamples(DimensionSpecification filterDims,
                                                                     Action <DataSample, TInternal, QuerySpecification> sampleAction, QuerySpecification querySpec)
        {
            var combinedData = new Dictionary <string, CombinedSample>();

            long start = long.MaxValue;
            long end   = long.MinValue;

            using (SharedLock.OpenShared(this.dataLock))
            {
                var bucketQuery = new BucketQuery(this, filterDims);
                foreach (var bucket in bucketQuery)
                {
                    foreach (var match in (querySpec.IsCrossQuery
                                               ? bucket.GetMatchesSplitByDimension(filterDims,
                                                                                   querySpec.CrossQueryDimension)
                                               : bucket.GetMatches(filterDims)))
                    {
                        if (match.DataCount == 0)
                        {
                            continue;
                        }

                        CombinedSample value;
                        if (!combinedData.TryGetValue(match.SplitDimensionValue, out value))
                        {
                            value = new CombinedSample
                            {
                                Data       = match.Data,
                                Dimensions = match.DimensionValues,
                            };
                            combinedData[match.SplitDimensionValue] = value;
                        }
                        else
                        {
                            value.Data.MergeFrom(match.Data);
                        }

                        if (bucket.StartTicks < start)
                        {
                            start = bucket.StartTicks;
                        }
                        if (bucket.EndTicks > end)
                        {
                            end = bucket.EndTicks;
                        }
                    }
                }
            }

            foreach (var value in combinedData.Values)
            {
                var sample =
                    new DataSample
                {
                    Name      = this.Name,
                    StartTime =
                        new DateTime(start, DateTimeKind.Utc).ToMillisecondTimestamp(),
                    EndTime =
                        new DateTime(end, DateTimeKind.Utc).ToMillisecondTimestamp(),
                    Dimensions = value.Dimensions.Data,
                };

                sampleAction(sample, value.Data, querySpec);

                yield return(sample);
            }

            Events.Write.EndQueryData(this);
        }
 /// <summary>
 /// Search for Items that have a particular Item Name
 /// </summary>
 public static BucketQuery WhereItemNameIs(this BucketQuery query, string itemName)
 {
     query.Add("itemName:" + itemName);
     return(query);
 }
 /// <summary>
 /// Search for Items up to a certain Creation Date
 /// </summary>
 public static BucketQuery Ending(this BucketQuery query, DateTime endDate)
 {
     query.Add("end:" + endDate.ToString("MM/dd/yyyy"));
     return(query);
 }
 /// <summary>
 /// Search for Items within a particular language
 /// </summary>
 public static BucketQuery WhereLanguageIs(this BucketQuery query, IEnumerable <Language> language)
 {
     query.AddRange(language.Select(lang => "language:" + lang.CultureInfo.TwoLetterISOLanguageName));
     return(query);
 }
 /// <summary>
 /// Search for Items within a particular language
 /// </summary>
 public static BucketQuery WhereLanguageIs(this BucketQuery query, Language language)
 {
     query.Add("language:" + language.CultureInfo.TwoLetterISOLanguageName);
     return(query);
 }
 /// <summary>
 /// Search for Items within a particular language
 /// </summary>
 public static BucketQuery WhereLanguageIs(this BucketQuery query, string language)
 {
     query.Add("language:" + language);
     return(query);
 }
 /// <summary>
 /// Search for Items have a specific value for a field
 /// </summary>
 public static BucketQuery WhereFieldValueIs(this BucketQuery query, string fieldName, string fieldValue)
 {
     query.Add("custom:" + fieldName + "|" + fieldValue);
     return(query);
 }
 /// <summary>
 /// Sort your results by a Particular Field. Do not sort by fields that DO NOT exist
 /// </summary>
 public static BucketQuery SortBy(this BucketQuery query, string fieldName)
 {
     query.Add("sort:" + fieldName);
     return(query);
 }
Esempio n. 25
0
        private long RunExtensionMethods(Item itm)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            //Test 1 - Get All Items Under Home of Template "Sample Item"
            var hitsCount = 0;
            var HomeDescendantsOfTypeSampleItem =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount,
                                                                                templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");

            Page.Response.Write(HomeDescendantsOfTypeSampleItem.Count() + "</br>");
            //Test 2 - Get All Items Under Tim Folder that have the Title Field Starting with the Word Tim

            var TimDescendantsWithTitleOfTime =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(new SafeDictionary <string> {
                { "title", "Tim" }
            }, out hitsCount);

            Page.Response.Write(TimDescendantsWithTitleOfTime.Count() + "</br>");
            //Test 3

            var RepositoryFolderWithNameOfTim =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(new SafeDictionary <string> {
                { "_name", "Tim" }
            }, out hitsCount);

            Page.Response.Write(RepositoryFolderWithNameOfTim.Count() + "</br>");
            //Test 4 - Get All Items Under Home of Template "Sample Item"
            var HomeDescendantsOfTypeArticleWithTimContainedWithinIt =
                BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount,
                                     templates: "{14633DB7-360E-447F-808B-B71128628009}", text: "Tim");

            Page.Response.Write(HomeDescendantsOfTypeArticleWithTimContainedWithinIt.Count() + "</br>");
            //Test 6 - Items under Home that contain the word Tim, sort by Name
            var TimItemsSortedByName =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, text: "Tim", sortField: "_name");

            Page.Response.Write(TimItemsSortedByName.Count() + "</br>");
            //Test 7 - Items under Home that contain the word Tim, sort by Name
            var TimItemsOfTypeSampleItemSortedByName =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, text: "Tim", sortField: "_name", templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");

            Page.Response.Write(TimItemsOfTypeSampleItemSortedByName.Count() + "</br>");
            //Test 8 - Items under Home that contain the word Tim, sort by Name
            var ItemsUnderHomeContainingBrisbane =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, text: "Brisbane");

            Page.Response.Write(ItemsUnderHomeContainingBrisbane.Count() + "</br>");
            //Test 10 - Sort by unknown fieldname
            var GetVersion3OfItem =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, id: "{344E1BED-B68C-4E13-9689-97BB7797D844}");

            Page.Response.Write(GetVersion3OfItem.Count() + "</br>");
            //Test 10 - Sort by unknown fieldname
            var ComplexSearch =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount,
                                                                                startDate:
                                                                                "03/12/2012",
                                                                                endDate:
                                                                                "03/26/2012",
                                                                                numberOfItemsToReturn
                                                                                : 60,
                                                                                language: "en",
                                                                                sortField:
                                                                                "title");

            //Shanee Tests
            Page.Response.Write(ComplexSearch.Count() + "</br>");
            var items1 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount, numberOfItemsToReturn: 5, pageNumber: 1, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");

            Page.Response.Write(items1.Count() + "</br>");
            var items2 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "title");

            Page.Response.Write(items2.Count() + "</br>");
            var items3 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), new SafeDictionary <string> {
                { "_name", "Tim" }
            }, out hitsCount, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "_name");

            Page.Response.Write(items3.Count() + "</br>");
            var items4 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount, text: "Tim", templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "_name");

            Page.Response.Write(items4.Count() + "</br>");

            //New Test Folder Tests

            var hitCount1 = 0;
            //Get me two items that have the word tim in it
            var items5 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount1, numberOfItemsToReturn: 2, pageNumber: 1, text: "Tim");

            Page.Response.Write(items5.Count() + "</br>");
            //Get me all items that have the word tim in it
            var hitCount2 = 0;
            var items6    = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount2, numberOfItemsToReturn: 2000, pageNumber: 1, sortField: "_name", text: "Tim");

            Page.Response.Write(items6.Count() + "</br>");
            var hitCount3 = 0;
            //Get me all items that are named tim
            var items7 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), new SafeDictionary <string> {
                { "_name", "Tim" }
            }, out hitCount3, sortField: "_name");

            Page.Response.Write(items7.Count() + "</br>");
            var hitCount4 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items8 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount4, text: "Tim", templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "_name", sortDirection: "asc");

            Page.Response.Write(items8.Count() + "</br>");
            var hitCount5 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items9 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount5, text: "*Tim", sortField: "title");

            Page.Response.Write(items9.Count() + "</br>");
            var hitCount6 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items10 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount6, text: "Tim*", sortField: "title");

            Page.Response.Write(items10.Count() + "</br>");
            var hitCount7 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items11 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount7, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}|{14633DB7-360E-447F-808B-B71128628009}", sortField: "_name");

            Page.Response.Write(items11.Count() + "</br>");
            var hitCount8 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items112 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount8, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}|{14633DB7-360E-447F-808B-B71128628009}", sortField: "_name", sortDirection: "desc", numberOfItemsToReturn: 2, pageNumber: 2, language: "de");

            Page.Response.Write(items112.Count() + "</br>");
            var hitCount9 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items113 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount9, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}|{14633DB7-360E-447F-808B-B71128628009}", sortField: "_name", sortDirection: "desc", numberOfItemsToReturn: 2, pageNumber: 2, itemName: "Tim");

            Page.Response.Write(items113.Count() + "</br>");
            var hitCount10 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items114 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount10, sortField: "_name", sortDirection: "desc", numberOfItemsToReturn: 20, pageNumber: 1, startDate: "04/30/2012", endDate: "5/05/2012");

            Page.Response.Write(items114.Count() + "</br>");
            stopWatch.Stop();

            //All the movies where Tim is the director or the producer, but only where the move was in the 90's and starred JOhhny Depp and Helen Bonhem-Carter in the same movie
            int queryHits = 0;
            var res       = new BucketQuery().WhereFieldValueIs("Director", "Tim")
                            .WhereFieldValueIs("Producer", "Tim")
                            .Starting(new DateTime(1990, 1, 1))
                            .Ending(new DateTime(1999, 12, 31))
                            .WhereFieldValueIs("Actors", "Johnny Depp")
                            .WhereFieldValueIs("Actors", "Helen Bonham Carter").Run(itm, 200);

            return(stopWatch.ElapsedMilliseconds);
        }
 /// <summary>
 /// Set the operation between two query types
 /// </summary>
 public static BucketQuery And(this BucketQuery query)
 {
     query.Add("+");
     return(query);
 }
 /// <summary>
 /// Search for Items are by a particular Author
 /// </summary>
 public static BucketQuery WhereAuthorIs(this BucketQuery query, User author)
 {
     query.Add("author:" + author.Name);
     return(query);
 }
 /// <summary>
 /// Search for Items based off a Template ID
 /// </summary>
 public static BucketQuery WhereTemplateIs(this BucketQuery query, TemplateID templateId)
 {
     query.Add("template:" + templateId.ID);
     return(query);
 }
 /// <summary>
 /// Search for Items beginning from a certain Creation Date
 /// </summary>
 public static BucketQuery Starting(this BucketQuery query, DateTime startDate)
 {
     query.Add("end:" + startDate.ToString("MM/dd/yyyy"));
     return(query);
 }
 /// <summary>
 /// Search for Items that belong to a list of Item Names
 /// </summary>
 public static BucketQuery WhereItemNameIs(this BucketQuery query, IEnumerable <string> searchStrings)
 {
     query.AddRange(searchStrings.Select(@string => "itemName:" + @string));
     return(query);
 }
        private long RunExtensionMethods(Item itm)
        {
            var stopWatch = new Stopwatch();
            stopWatch.Start();
            //Test 1 - Get All Items Under Home of Template "Sample Item"
            var hitsCount = 0;
            var HomeDescendantsOfTypeSampleItem =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount,
                                     templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");
            Page.Response.Write(HomeDescendantsOfTypeSampleItem.Count() + "</br>");
            //Test 2 - Get All Items Under Tim Folder that have the Title Field Starting with the Word Tim

            var TimDescendantsWithTitleOfTime =
            Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(new SafeDictionary<string> { { "title", "Tim" } }, out hitsCount);
            Page.Response.Write(TimDescendantsWithTitleOfTime.Count() + "</br>");
            //Test 3

            var RepositoryFolderWithNameOfTim =
            Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(new SafeDictionary<string> { { "_name", "Tim" } }, out hitsCount);
            Page.Response.Write(RepositoryFolderWithNameOfTim.Count() + "</br>");
            //Test 4 - Get All Items Under Home of Template "Sample Item"
            var HomeDescendantsOfTypeArticleWithTimContainedWithinIt =
               BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount,
                                     templates: "{14633DB7-360E-447F-808B-B71128628009}", text: "Tim");
            Page.Response.Write(HomeDescendantsOfTypeArticleWithTimContainedWithinIt.Count() + "</br>");
            //Test 6 - Items under Home that contain the word Tim, sort by Name
            var TimItemsSortedByName =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, text: "Tim", sortField: "_name");
            Page.Response.Write(TimItemsSortedByName.Count() + "</br>");
            //Test 7 - Items under Home that contain the word Tim, sort by Name
            var TimItemsOfTypeSampleItemSortedByName =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, text: "Tim", sortField: "_name", templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");
            Page.Response.Write(TimItemsOfTypeSampleItemSortedByName.Count() + "</br>");
            //Test 8 - Items under Home that contain the word Tim, sort by Name
            var ItemsUnderHomeContainingBrisbane =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, text: "Brisbane");
            Page.Response.Write(ItemsUnderHomeContainingBrisbane.Count() + "</br>");
            //Test 10 - Sort by unknown fieldname
            var GetVersion3OfItem =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount, id: "{344E1BED-B68C-4E13-9689-97BB7797D844}");
            Page.Response.Write(GetVersion3OfItem.Count() + "</br>");
            //Test 10 - Sort by unknown fieldname
            var ComplexSearch =
                Factory.GetDatabase("master").GetItem(itm.ID.ToString()).Search(out hitsCount,
                                                                                                          startDate:
                                                                                                              "03/12/2012",
                                                                                                          endDate:
                                                                                                              "03/26/2012",
                                                                                                          numberOfItemsToReturn
                                                                                                              : 60,
                                                                                                          language: "en",
                                                                                                          sortField:
                                                                                                              "title");

            //Shanee Tests
            Page.Response.Write(ComplexSearch.Count() + "</br>");
            var items1 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount, numberOfItemsToReturn: 5, pageNumber: 1, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}");
            Page.Response.Write(items1.Count() + "</br>");
            var items2 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "title");
            Page.Response.Write(items2.Count() + "</br>");
            var items3 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), new SafeDictionary<string> { { "_name", "Tim" } }, out hitsCount, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "_name");
            Page.Response.Write(items3.Count() + "</br>");
            var items4 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitsCount, text: "Tim", templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "_name");
            Page.Response.Write(items4.Count() + "</br>");

            //New Test Folder Tests

            var hitCount1 = 0;
            //Get me two items that have the word tim in it
            var items5 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount1, numberOfItemsToReturn: 2, pageNumber: 1, text: "Tim");
            Page.Response.Write(items5.Count() + "</br>");
            //Get me all items that have the word tim in it
            var hitCount2 = 0;
            var items6 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount2, numberOfItemsToReturn: 2000, pageNumber: 1, sortField: "_name", text: "Tim");
            Page.Response.Write(items6.Count() + "</br>");
            var hitCount3 = 0;
            //Get me all items that are named tim
            var items7 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), new SafeDictionary<string> { { "_name", "Tim" } }, out hitCount3, sortField: "_name");
            Page.Response.Write(items7.Count() + "</br>");
            var hitCount4 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items8 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount4, text: "Tim", templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}", sortField: "_name", sortDirection: "asc");
            Page.Response.Write(items8.Count() + "</br>");
            var hitCount5 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items9 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount5, text: "*Tim", sortField: "title");
            Page.Response.Write(items9.Count() + "</br>");
            var hitCount6 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items10 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount6, text: "Tim*", sortField: "title");
            Page.Response.Write(items10.Count() + "</br>");
            var hitCount7 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items11 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount7, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}|{14633DB7-360E-447F-808B-B71128628009}", sortField: "_name");
            Page.Response.Write(items11.Count() + "</br>");
            var hitCount8 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items112 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount8, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}|{14633DB7-360E-447F-808B-B71128628009}", sortField: "_name", sortDirection: "desc", numberOfItemsToReturn: 2, pageNumber: 2, language: "de");
            Page.Response.Write(items112.Count() + "</br>");
            var hitCount9 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items113 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount9, templates: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}|{14633DB7-360E-447F-808B-B71128628009}", sortField: "_name", sortDirection: "desc", numberOfItemsToReturn: 2, pageNumber: 2, itemName: "Tim");
            Page.Response.Write(items113.Count() + "</br>");
            var hitCount10 = 0;
            //Get me all items that have the text tim in it but are of template sample item
            var items114 = BucketManager.Search(Factory.GetDatabase("master").GetItem(itm.ID.ToString()), out hitCount10, sortField: "_name", sortDirection: "desc", numberOfItemsToReturn: 20, pageNumber: 1, startDate: "04/30/2012", endDate: "5/05/2012");
            Page.Response.Write(items114.Count() + "</br>");
            stopWatch.Stop();

            //All the movies where Tim is the director or the producer, but only where the move was in the 90's and starred JOhhny Depp and Helen Bonhem-Carter in the same movie
            int queryHits = 0;
            var res = new BucketQuery().WhereFieldValueIs("Director", "Tim")
                                       .WhereFieldValueIs("Producer", "Tim")
                                       .Starting(new DateTime(1990, 1, 1))
                                       .Ending(new DateTime(1999, 12, 31))
                                       .WhereFieldValueIs("Actors", "Johnny Depp")
                                       .WhereFieldValueIs("Actors", "Helen Bonham Carter").Run(itm, 200);

            return stopWatch.ElapsedMilliseconds;
        }
 /// <summary>
 /// Search for Items within a particular Site
 /// </summary>
 public static BucketQuery ForSite(this BucketQuery query, Site site)
 {
     query.Add("site:" + site.Name);
     return(query);
 }