public void SearchTermsShouldBeFoundInMultipleFields()
        {
            _provider.CreateIndex("default");
            _provider.Store("default",
                            _provider.New(42)
                            .Add("title", "title1 title2 title3").Analyze()
                            .Add("date", new DateTime(2010, 05, 28, 14, 13, 56, 123))
                            );

            Assert.IsNotNull(_provider.CreateSearchBuilder("default").Get(42));

            Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title1").Search().FirstOrDefault());
            Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title2").Search().FirstOrDefault());
            Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title3").Search().FirstOrDefault());
            Assert.IsNull(_provider.CreateSearchBuilder("default").WithField("title", "title4").Search().FirstOrDefault());
        }
        public ActionResult MediaItems(string folderPath, int skip = 0, int count = 0, string order = "created", string mediaType = "", string search = "")
        {
            var builder = _indexProvider.CreateSearchBuilder("Media");

            if (!String.IsNullOrEmpty(search))
            {
                builder.WithField("title", search);
                builder.WithField("author", search);
                builder.WithField("media-caption", search);
                builder.WithField("media-alternatetext", search);
                builder.WithField("media-filename", search);
            }

            if (!String.IsNullOrEmpty(mediaType))
            {
                builder.WithField("type", mediaType).Mandatory().AsFilter();
            }

            if (!String.IsNullOrEmpty(folderPath))
            {
                var path = folderPath.Replace("\\", "/");
                builder.WithField("media-folderpath", path.ToLowerInvariant()).AsFilter();
            }

            builder.SortBy(order);

            if (order == "title")
            {
                builder.Ascending();
            }

            var mediaPartsCount = builder.Count();
            var contentItemIds  = builder.Slice(skip, count).Search().Select(x => x.ContentItemId).ToArray();
            var mediaParts      = _contentManager.GetMany <MediaPart>(contentItemIds, VersionOptions.Published, QueryHints.Empty);

            var mediaItems = mediaParts.Select(x => new MediaManagerMediaItemViewModel {
                MediaPart = x,
                Shape     = _contentManager.BuildDisplay(x, "Thumbnail")
            }).ToList();

            var viewModel = new MediaManagerMediaItemsViewModel {
                MediaItems      = mediaItems,
                MediaItemsCount = mediaPartsCount,
                FolderPath      = folderPath
            };

            return(View(viewModel));
        }
Exemple #3
0
        public void ANewIndexShouldBeEmpty()
        {
            _provider.CreateIndex("default");
            var searchBuilder = _provider.CreateSearchBuilder("default");
            var hits          = searchBuilder.Search();

            Assert.That(hits.Count(), Is.EqualTo(0));
        }