Esempio n. 1
0
        private void IndexDocuments(JArray documents, IList <string> searchableFields)
        {
            foreach (var document in documents)
            {
                var uid = document.Value <string>(_uidFieldName);
                foreach (var searchableField in searchableFields)
                {
                    var fieldValues = GetFieldValue(document, searchableField);
                    if (fieldValues != null && fieldValues.Count > 0)
                    {
                        foreach (var fieldValue in fieldValues)
                        {
                            var fieldTokens = Tokenizer.Tokenize(TokenSantizer.Sanitize(fieldValue));
                            foreach (var fieldToken in fieldTokens)
                            {
                                var expandedTokens = IndexStrategy.ExpandToken(fieldToken);
                                foreach (var expandToken in expandedTokens)
                                {
                                    SearchIndex.IndexDocument(expandToken, uid, document);
                                }
                            }
                        }
                    }
                }
            }

            _initialized = true;
        }
        public void Test_Index_PageIndex0_Size1()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            PagingLocation location = new PagingLocation(0, 1);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(location, "TitleAscending", false);

            strategy.TypeName     = "TestArticle";
            strategy.EnablePaging = true;

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index());

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(2, location.AbsoluteTotal, "Absolute total invalid.");

            Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found.");
        }
        public void Test_Index_FilterValues()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(false);

            strategy.TypeName = "TestArticle";

            Dictionary <string, object> filterValues = new Dictionary <string, object>();

            filterValues.Add("Title", article.Title);

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index(filterValues));

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(1, foundArticles.Length, "Invalid number of test articles found.");
        }
        public void Test_Index_PageIndex1_Size2()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            PagingLocation location = new PagingLocation(1, 2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(location, "TitleAscending", false);

            strategy.TypeName     = "TestArticle";
            strategy.EnablePaging = true;

            TestArticle[] foundArticles = Collection <TestArticle> .ConvertAll(strategy.Index());

            Assert.IsNotNull(foundArticles);

            // There should be no articles found because it's requesting a page outside the available range
            Assert.AreEqual(0, foundArticles.Length, "Invalid number of test articles found.");
        }
Esempio n. 5
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            IndexStrategy indexMatchingStrategy = IndexStrategy.ForStringIndex();

            if (indexMatchingStrategy.Matches(binder, indexes))
            {
                string field = (string)indexes[0];
                return(values.TryGetValue(field, out result));
            }
            return(base.TryGetIndex(binder, indexes, out result));
        }
        protected virtual IEntity[] Load(Dictionary <string, object> filterValues)
        {
            using (LogGroup logGroup = LogGroup.StartDebug("Loading entities (matching the provided filter values) to be displayed as an index."))
            {
                IEntity[] entities = IndexStrategy.New(Command.TypeName).Index(filterValues);

                entities = Collection <IEntity> .Sort(entities, SortExpression);

                DataSource = entities;
            }

            return(DataSource);
        }
        public void Test_Index()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Test Title";

            TestArticle article2 = new TestArticle();

            article2.ID    = Guid.NewGuid();
            article2.Title = "Test Title 2";

            DataAccess.Data.Saver.Save(article);
            DataAccess.Data.Saver.Save(article2);

            IIndexStrategy strategy = IndexStrategy.New <TestArticle>(false);

            TestArticle[] foundArticles = strategy.Index <TestArticle>();

            Assert.IsNotNull(foundArticles);

            Assert.AreEqual(2, foundArticles.Length, "Invalid number of test articles found.");
        }