public void CompensateScoreWithDocumentLength()
        {
            int[]        expected = { 1, 2, 3 };
            ReleaseLogic logic    = new ReleaseLogic(new ReleaseRepository(new ReleaseMockContext(
                                                                               new List <Release> {
                new Release {
                    Id = 2, Title = "query none", Category = new Category {
                        Name = "query none"
                    }, Description = "query none"
                },
                new Release {
                    Id = 3, Title = "query none none", Category = new Category {
                        Name = "query none none"
                    }, Description = "query none none"
                },
                new Release {
                    Id = 1, Title = "query", Category = new Category {
                        Name = "query"
                    }, Description = "query"
                }
            }
                                                                               ), new CategoryMockContext()));
            List <int> results = logic.SearchReleases("query").ToList();

            for (int i = 0; i < results.Count; i++)
            {
                Assert.Equal(results[i], expected[i]);
            }
        }
        public void GiveLessValueToDeadWords()
        {
            int[]        expected = { 2, 1, 3 };
            ReleaseLogic logic    = new ReleaseLogic(new ReleaseRepository(new ReleaseMockContext(
                                                                               new List <Release> {
                new Release {
                    Id = 3, Title = "last", Category = new Category {
                        Name = "last"
                    }, Description = "last"
                },
                new Release {
                    Id = 1, Title = "second", Category = new Category {
                        Name = "second"
                    }, Description = "last"
                },
                new Release {
                    Id = 2, Title = "first", Category = new Category {
                        Name = "first"
                    }, Description = "first"
                }
            }
                                                                               ), new CategoryMockContext()));
            List <int> results = logic.SearchReleases("first second last").ToList();

            for (int i = 0; i < results.Count; i++)
            {
                Assert.Equal(results[i], expected[i]);
            }
        }
        public void BetterScoreBasedOnWordFrequency()
        {
            int[]        expected = { 2, 3, 1 };
            ReleaseLogic logic    = new ReleaseLogic(new ReleaseRepository(new ReleaseMockContext(
                                                                               new List <Release> {
                new Release {
                    Id = 2, Title = "query query", Category = new Category {
                        Name = "none"
                    }, Description = "none"
                },
                new Release {
                    Id = 3, Title = "query query query", Category = new Category {
                        Name = "none"
                    }, Description = "none"
                },
                new Release {
                    Id = 1, Title = "query", Category = new Category {
                        Name = "none"
                    }, Description = "none"
                }
            }
                                                                               ), new CategoryMockContext()));
            List <int> results = logic.SearchReleases("query").ToList();

            for (int i = 0; i < results.Count; i++)
            {
                Assert.Equal(results[i], expected[i]);
            }
        }
Esempio n. 4
0
        public IActionResult Search(string searchQuery)
        {
            List <ReleaseViewModelSmall> vm = new List <ReleaseViewModelSmall>();

            if (string.IsNullOrEmpty(searchQuery))
            {
                return(RedirectToAction("index"));
            }
            foreach (int id in releaseLogic.SearchReleases(searchQuery))
            {
                IRelease releaseModel             = releaseLogic.GetReleaseById(id);
                ReleaseViewModelSmall tempRelease = new ReleaseViewModelSmall
                {
                    Title         = releaseModel.Title,
                    Id            = releaseModel.Id,
                    FollowerCount = releaseModel.FollowerCount,
                    ImgLocation   = releaseModel.ImgLocation,
                    ReleaseDate   = releaseModel.ReleaseDate,
                    Category      = new CategoryViewModel
                    {
                        ImgLocation = releaseModel.Category.ImgLocation
                    }
                };
                vm.Add(tempRelease);
            }
            return(View(vm));
        }