コード例 #1
0
 public void Setup()
 {
     stopWords = new string[StopAnalyzer.ENGLISH_STOP_WORDS_SET.Values.Count + 1];
     stopWords[0] = "into";
     int i = 1;
     foreach (string value in StopAnalyzer.ENGLISH_STOP_WORDS_SET.Values) stopWords[i++] = value;
     _service = new SearchEngineService(new RAMDirectory(), new SnowballAnalyzer("English", stopWords));
 }
コード例 #2
0
 public void CreateSearchEngine()
 {
     stopWords = new string[StopAnalyzer.ENGLISH_STOP_WORDS_SET.Values.Count];
     int i = 0;
     foreach (string value in StopAnalyzer.ENGLISH_STOP_WORDS_SET.Values)
     {
         stopWords[i++] = value;
     }
     _service = new SearchEngineService(new RAMDirectory(), new SnowballAnalyzer("English", stopWords), new FullTextSearchEngineSettings());
 }
コード例 #3
0
        public void CreateSearchEngine()
        {
            stopWords = new string[StopAnalyzer.ENGLISH_STOP_WORDS_SET.Values.Count];
            int i = 0;

            foreach (string value in StopAnalyzer.ENGLISH_STOP_WORDS_SET.Values)
            {
                stopWords[i++] = value;
            }
            _service = new SearchEngineService(new RAMDirectory(), new SnowballAnalyzer("English", stopWords), new FullTextSearchEngineSettings());
        }
コード例 #4
0
        public void CanRemoveItemFromIndex()
        {
            CreateIndex(1);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(1))
            {
                int totalEntry = ses.GetTotalIndexedEntryCount();
                ses.RemovePost(2);
                Assert.IsTrue(ses.GetTotalIndexedEntryCount() == totalEntry - 1);
            }
        }
コード例 #5
0
        public void CanSearchAllSeasons()
        {
            CreateIndex(1);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(1))
            {
                SearchParameters sp = new SearchParameters();
                sp.Seasons = new [] { "winter", "summer", "spring", "fall" };
                SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false);
                Assert.IsTrue(ser.TotalCount == 100, ser.TotalCount.ToString());
            }
        }
コード例 #6
0
        public void CanSearchEventTypes()
        {
            CreateIndex(1);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(1))
            {
                SearchParameters sp = new SearchParameters();
                sp.EventTypes = new[] { "Formal Affair Evening" };
                SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false);
                Assert.IsTrue(ser.TotalCount > 0);
            }
        }
コード例 #7
0
        public void CanSearchFriendRateRange()
        {
            CreateIndex(1);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(1))
            {
                SearchParameters sp = new SearchParameters();
                sp.IsRatedByFriends = true;
                SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false);
                Assert.IsTrue(ser.TotalCount == 11, ser.TotalCount.ToString());
                Assert.IsTrue(ser.Results.Count() > 0);
            }
        }
コード例 #8
0
        public void CanSearchByBooleanField()
        {
            CreateIndex(1);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(1))
            {
                SearchParameters sp = new SearchParameters();
                sp.CreatedByMe = true;

                SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false);
                Assert.IsTrue(ser.TotalCount == 0, ser.TotalCount.ToString());
            }
        }
コード例 #9
0
        protected override async Task OnInitializedAsync()
        {
            ResponsePlace obj = SearchEngineService._download_serialized_json_data <ResponsePlace>(searchPattern, true);

            PlaceClass placeClass = new PlaceClass();

            ResponsePlaces = placeClass.CreateList(obj);
            //obj.'
            if (ResponsePlaces.Count != 0)
            {
                ChangePlace(0);
            }
            var response = placeModelService.GetPlaceModels();
        }
コード例 #10
0
ファイル: RelatedLinks.cs プロジェクト: euvin3582/Subtext
        protected override void OnLoad(EventArgs e)
        {
            int   blogId          = Blog.Id >= 1 ? Blog.Id : 0;
            var   urlRelatedLinks = FindControl("Links") as Repeater;
            Entry entry           = Cacher.GetEntryFromRequest(true, SubtextContext);

            urlRelatedLinks.DataSource = SearchEngineService.RelatedContents(entry.Id, RowCount, blogId);;
            urlRelatedLinks.DataBind();
            if (urlRelatedLinks.Items.Count == 0)
            {
                this.Visible = false;
            }
            base.OnLoad(e);
        }
コード例 #11
0
 public void GetIndex()
 {
     using (SearchEngineService ses = SearchEngineService.GetByCloset(98))
     {
         SearchParameters sp = new SearchParameters();
         sp.Seasons = new[] { "winter", "summer", "spring", "fall" };
         SearchEngineResponse ser = ses.Search(sp, 0, 9, "EditorRating", false);
         Console.WriteLine(ser.TotalCount);
         foreach (SearchEngineResult res in ser.Results)
         {
             Console.WriteLine(res.EntryId);
         }
     }
 }
コード例 #12
0
        public static void RunSearch(object closet)
        {
            using (SearchEngineService ses = SearchEngineService.GetByCloset(Convert.ToInt32(closet)))
            {
                SearchParameters sp = new SearchParameters();
                sp.FreeText         = "";
                sp.IsRatedByMe      = false;
                sp.FlavorId         = 2;
                sp.IsRatedByFriends = true;

                SearchEngineResponse response = ses.Search(sp, 0, 10, "MyRating", true);
                Assert.IsTrue(response.TotalCount > 0);
                Console.WriteLine(response.TotalCount);
            };
        }
コード例 #13
0
        public static void CreateIndex(object closet)
        {
            using (SearchEngineService ses = SearchEngineService.GetByCloset(Convert.ToInt32(closet)))
            {
                IList <SearchEngineEntry> lst = new List <SearchEngineEntry>();
                for (int i = ((Convert.ToInt32(closet) - 1) * maxRecordsPerCloset); i < maxRecordsPerCloset * Convert.ToInt32(closet); i++)
                {
                    SearchEngineEntry see = new SearchEngineEntry();
                    see.EntryId = i;

                    int amountOfClothes = rnd.Next(10) + 1;

                    see.Categories   = GetRandom(categories, amountOfClothes / 2);
                    see.Colors       = GetRandom(colors, amountOfClothes);
                    see.Silouhettes  = GetRandom(silouhettes, amountOfClothes);
                    see.EventTypes   = GetRandom(eventTypes);
                    see.Fabrics      = GetRandom(fabrics);
                    see.Seasons      = GetRandom(seasons);
                    see.Tags         = GetRandom(tags);
                    see.EditorRating = Convert.ToInt32(GetRandom(rating, 1));
                    see.FriendRating = 0;
                    see.FlavorId     = Convert.ToInt32(GetRandom(flavor, 1));

                    see.CreatedByMe = false;
                    see.MyRating    = 0;

                    if (i == 1)
                    {
                        see.MyRating = 5;
                    }

                    if (i <= 10)
                    {
                        see.FriendRating = 3;
                    }

                    lst.Add(see);
                }

                ses.AddEntries(lst);
            }
        }
コード例 #14
0
        public ActionResult Search(String q, int? page)
        {
            Int32 currentPage = page ?? 1;

            SearchResultViewModel searchResult = new SearchResultViewModel()
            {
                SearchQuery = q,
                SearchSuggestion=String.Empty
            };
            IList<XsQuestion> searchQuestions = new List<XsQuestion>();

            if (!String.IsNullOrEmpty(q))
            {
                ISearchEngineService searchService = new SearchEngineService(questionRepository);
                searchQuestions = searchService.SearchQuestions(q);
            }

            IPagination pageQuestions = searchQuestions.AsPagination(currentPage,Settings.QUESTIONS_PAGINATION_SIZE);

            Int32 currentPageSize = Settings.TAGS_PAGINATION_SIZE;

            if (currentPage == pageQuestions.TotalPages)
            {
                currentPageSize = pageQuestions.TotalItems - (pageQuestions.TotalPages - 1) * Settings.TAGS_PAGINATION_SIZE;
            }
            else
            {
                if (0 == pageQuestions.TotalPages)
                {
                    currentPageSize = 0;
                }
            }

            searchResult.Questions = pageQuestions;
            if (0 == pageQuestions.TotalItems)
            {
                String searchSuggestion = new XpertSquare.Core.Search.GoogleSearchSuggestor().GetSuggestion(q);
                searchResult.SearchSuggestion = searchSuggestion;
            }

            return View(searchResult);
        }
コード例 #15
0
        public ActionResult RemoveOutfitFromCloset(int outfitSelected)
        {
            ClosetOutfit outfit = closetOutfitRepository.Get(outfitSelected);

            outfit.SendToColdStorage();
            closetOutfitRepository.SaveOrUpdate(outfit);

            if (outfit.Closet.FavoriteOutfit == outfit)
            {
                outfit.Closet.ClearFavoriteOutfit();
            }
            closetRepository.SaveOrUpdate(outfit.Closet);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId))
            {
                ses.RemovePost(outfitSelected);
            }

            return(Json(new { Success = true }));
        }
コード例 #16
0
        public void CanUpdateIndex()
        {
            CreateIndex(1);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(1))
            {
                //int totalEntry = ses.GetTotalIndexedEntryCount();
                //ses.RemovePost(2);
                //Assert.IsTrue(ses.GetTotalIndexedEntryCount() == totalEntry - 1);

                SearchEngineEntry see = new SearchEngineEntry();
                see.EntryId = 2;
                int amountOfClothes = rnd.Next(10) + 1;

                see.Categories   = GetRandom(categories, amountOfClothes / 2);
                see.Colors       = GetRandom(colors, amountOfClothes);
                see.Silouhettes  = GetRandom(silouhettes, amountOfClothes);
                see.EventTypes   = GetRandom(eventTypes);
                see.Fabrics      = GetRandom(fabrics);
                see.Seasons      = GetRandom(seasons);
                see.Tags         = GetRandom(tags);
                see.CreatedByMe  = true;
                see.EditorRating = Convert.ToInt32(GetRandom(rating, 1));
                see.FriendRating = Convert.ToInt32(GetRandom(rating, 1));
                see.MyRating     = 6;
                see.FlavorId     = Convert.ToInt32(GetRandom(flavor, 1));

                ses.AddEntry(see);
                //Assert.IsTrue(ses.GetTotalIndexedEntryCount() == totalEntry);

                SearchParameters sp = new SearchParameters();
                //sp.CreatedByMe = true;
                sp.MyRating = 6;

                SearchEngineResponse ser = ses.Search(sp, 0, 10, "EditorRating", false);
                Assert.IsTrue(ser.TotalCount == 1);
            }
        }
コード例 #17
0
 public RepositoryFactory(
     CategoryService category,
     PostService post,
     TagService tag,
     UserService user,
     CommentService comment,
     SearchEngineService searchEngine,
     ConfigurationService configuration)
 {
     if (category != null)
     {
         this.Category = category;
     }
     if (post != null)
     {
         this.Post = post;
     }
     if (tag != null)
     {
         this.Tag = tag;
     }
     if (user != null)
     {
         this.User = user;
     }
     if (comment != null)
     {
         this.Comment = comment;
     }
     if (searchEngine != null)
     {
         this.SearchEngine = searchEngine;
     }
     if (configuration != null)
     {
         this.Configuration = configuration;
     }
 }
コード例 #18
0
        public ActionResult RateOutfit(OutfitRate outfitRate)
        {
            ClosetOutfit closetOutfit = closetOutfitRepository.Get(outfitRate.ClosetOutfitId);

            if (closetOutfit.Rating == null)
            {
                closetOutfit.Rating = new Rating();
            }
            closetOutfit.Rating.Rate(closetOutfit, outfitRate.Rate);

            ActionResult res = Json(new { Success = true });

            if (outfitRate.Rate == 5)
            {
                if (closetOutfit.Closet.FavoriteOutfit != null)
                {
                    closetOutfitRepository.SaveOrUpdate(closetOutfit);
                    res = Json(new { Success = true, ReplaceFavorite = true });
                }
                else
                {
                    res = SetFavorite(outfitRate);
                }
            }

            if (closetOutfit.Closet.FavoriteOutfit != null && closetOutfit.Closet.FavoriteOutfit.Id == closetOutfit.Id)
            {
                res = Json(new { Success = true, RemoveFavorite = true });
            }

            closetOutfitRepository.SaveOrUpdate(closetOutfit);

            using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId))
                ses.AddEntry(closetOutfit.ToSearchEngineEntry());

            return(res);
        }
コード例 #19
0
ファイル: Search.cs プロジェクト: euvin3582/Subtext
        protected override void OnLoad(EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            var searchResults = FindControl("results") as Repeater;
            var noResults     = FindControl("noresults") as PlaceHolder;
            var terms         = FindControl("terms") as Literal;
            var txtSearch     = FindControl("txtSearch") as TextBox;


            string queryString = SubtextContext.RequestContext.GetQueryFromRequest();

            if (!String.IsNullOrEmpty(queryString))
            {
                if (txtSearch != null)
                {
                    txtSearch.Text = queryString;
                }
                var results = SearchEngineService.Search(queryString, MaxResultsCount, Blog.Id);
                if (results.Count() > 0)
                {
                    searchResults.DataSource = results;
                    searchResults.DataBind();
                    searchResults.Visible = true;
                }
                else
                {
                    terms.Text        = HttpUtility.HtmlEncode(queryString);
                    noResults.Visible = true;
                }
            }
            base.OnLoad(e);
        }
コード例 #20
0
 public void Setup()
 {
     _service = new SearchEngineService(
         _bingApiResultServiceMockBuilder.Build(),
         _googleApiResultServiceMockBuilder.Build());
 }
コード例 #21
0
        //
        // GET: /Questions/Details/5/What-is-what
        public ActionResult Details(long id, String seoName)
        {
            XsQuestion questionToView = null;
            QuestionViewModel questionViewModel = null;
            try
            {
                questionToView = questionRepository.GetById(id);
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Question GetById({0}) error: ", id) + ex.Message);
            }

            if (null == questionToView)
            {
                ViewData["EntityID"] = id;
                return View("NotFound");
            }

            if (User.Identity.IsAuthenticated)
            {
                ViewData["IsAuthenticated"] = true;
            }

            IList<XsQuestion> relatedQuestions = new List<XsQuestion>();

            ISearchEngineService searchService = new SearchEngineService(questionRepository);
            relatedQuestions = searchService.SearchRelatedQuestions(questionToView);

            questionViewModel = new QuestionViewModel() { Question = questionToView, RelatedQuestions = relatedQuestions };

            return View(questionViewModel);
        }
コード例 #22
0
        public ActionResult Vote(FriendRatingView view)
        {
            if (ModelState.IsValid)
            {
                FriendRatingInvitation invitation;

                // Check if this is a new invitation from an anonymous user
                if (view.InvitationId == 0)
                {
                    invitation = new FriendRatingInvitation();
                    invitation.ClosetOutfit = closetOutfitRepository.Get(view.ClosetOutfitId);
                    invitation.User         = invitation.ClosetOutfit.Closet.User;

                    invitation.FriendEmail      = "Generated by FaceBook";
                    invitation.KeyCode          = string.Empty;
                    invitation.InvitationSentOn = DateTime.Today;
                }
                else
                {
                    invitation = friendRatingInvitationRepository.Get(view.InvitationId);
                    if (!IsValidInvitation(invitation))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                invitation.Rate         = view.FriendRating;
                invitation.FriendRateOn = DateTime.Now;
                invitation.Message      = "";
                if (!string.IsNullOrEmpty(view.Comment))
                {
                    //invitation.Message = HttpUtility.HtmlEncode(view.Comment);
                    invitation.Message = view.Comment;
                }

                ClosetOutfit closetOutfit = closetOutfitRepository.Get(view.ClosetOutfitId);
                closetOutfit.Rating.Rate(view.FriendRating, invitation);
                closetOutfitRepository.SaveOrUpdate(closetOutfit);

                using (SearchEngineService ses = SearchEngineService.GetByCloset(ClosetId))
                    ses.AddEntry(closetOutfit.ToSearchEngineEntry());

                friendRatingInvitationRepository.SaveOrUpdate(invitation);

                ConfirmRatingData data = new ConfirmRatingData
                {
                    Components  = closetOutfit.Components,
                    Comments    = HttpUtility.HtmlEncode(view.Comment),
                    GarmentsUri = Resources.GetGarmentLargePath(),
                    RatingImg   = Resources.GetRatingLargePath() + view.FriendRating + ".jpg",
                    RatingText  = Resources.GetRatingText(view.FriendRating)
                };

                messageSenderService.SendWithTemplate("confirmrating", invitation.User, data, invitation.User.EmailAddress);
                return(RedirectToAction("Thanks"));
            }

            ClosetOutfitView cv = closetOutfitRepository.GetByClosetOutfitId(view.ClosetOutfitId);

            view = LoadViewData(view, cv, 0);

            return(View(view));
        }
コード例 #23
0
        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
            //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
            log4net.Config.XmlConfigurator.Configure();

            IQuestionRepository questionRepository = new QuestionRepository();
            ISearchEngineService searchEngine = new SearchEngineService(questionRepository);

            //ThreadStart ts = new ThreadStart(searchEngine.BuildIndex);

            Thread thread = new Thread(searchEngine.BuildIndex);
            thread.Start();
        }
コード例 #24
0
 public void CreateSearchEngine()
 {
     _service = new SearchEngineService(new RAMDirectory(), new StandardAnalyzer(Version.LUCENE_29), new FullTextSearchEngineSettings());
 }
コード例 #25
0
ファイル: HomeController.cs プロジェクト: ccczg/CoreHome
 public HomeController(IWebHostEnvironment environment, SearchEngineService searchEngineService, ProfileService profileService)
 {
     this.environment         = environment;
     this.searchEngineService = searchEngineService;
     this.profileService      = profileService;
 }
コード例 #26
0
 public void Setup()
 {
     _googleSearchEngineApiClientBuilder = new GoogleSearchEngineApiClientBuilder();
     _bingSearchEngineApiClientBuilder   = new BingSearchEngineApiClientBuilder();
     _service = new SearchEngineService(_googleSearchEngineApiClientBuilder.Build(), _bingSearchEngineApiClientBuilder.Build());
 }
コード例 #27
0
        private IList <ClosetOutfitView> Search(out int totalCount, OutfitSearch outfitSearch, RegisteredUser user)
        {
            IList <ClosetOutfitView> result = new List <ClosetOutfitView>();

            using (SearchEngineService ses = SearchEngineService.GetByCloset(user.Closet.Id))
            {
                string sortBy = string.Empty;
                switch (outfitSearch.SortBy)
                {
                case "1":
                    sortBy = "EditorRating";
                    break;

                case "2":
                    sortBy = "MyRating";
                    break;

                case "3":
                    sortBy = "FriendRating";
                    break;

                case "4":
                    sortBy = "WornDate";
                    break;
                }

                SearchParameters sp = new SearchParameters();
                if (outfitSearch.MyFavorites)
                {
                    sp.MyRating = 5;
                }
                if (!string.IsNullOrEmpty(outfitSearch.Search))
                {
                    outfitSearch.Search = outfitSearch.Search.Replace(',', ' ');
                }
                if (!string.IsNullOrEmpty(outfitSearch.Color))
                {
                    outfitSearch.Color = outfitSearch.Color.Replace(',', ' ');
                }
                if (!string.IsNullOrEmpty(outfitSearch.Pattern))
                {
                    outfitSearch.Pattern = outfitSearch.Pattern.Replace(',', ' ');
                }
                sp.FreeText = string.Format("{0} {1} {2}", outfitSearch.Color, outfitSearch.Pattern, outfitSearch.Search);
                char[] separator = new char[1];
                separator[0] = ' ';
                if (!string.IsNullOrEmpty(outfitSearch.SeasonName))
                {
                    sp.Seasons = outfitSearch.SeasonName.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                }
                if (!string.IsNullOrEmpty(outfitSearch.Garment) && outfitSearch.Garment != NOCATEGORY)
                {
                    sp.FreeText += " " + outfitSearch.Garment;
                }
                separator[0] = ',';
                if (!string.IsNullOrEmpty(outfitSearch.SelectedEvents))
                {
                    sp.EventTypes = outfitSearch.SelectedEvents.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                }

                if (!string.IsNullOrEmpty(outfitSearch.Trend) && outfitSearch.Trend != NOTREND)
                {
                    Trend trend = trendRepository.GetByName(outfitSearch.Trend);
                    sp.TrendKeywords = new List <string>(trend.Keywords).ToArray();
                }

                if (outfitSearch.CreatedByMe)
                {
                    sp.CreatedByMe = true;
                }
                if (outfitSearch.IsRatedByMe)
                {
                    sp.IsRatedByMe = true;
                }
                if (outfitSearch.IsRatedByFriends)
                {
                    sp.IsRatedByFriends = true;
                }
                if (outfitSearch.IsUpToDate)
                {
                    sp.IsUpToDate = true;
                }

                if (outfitSearch.SelectedFlavors != null && outfitSearch.SelectedFlavors.Split(separator, StringSplitOptions.RemoveEmptyEntries).Length == 1)
                {
                    sp.FlavorId = Convert.ToInt32(outfitSearch.SelectedFlavors.Split(separator, StringSplitOptions.RemoveEmptyEntries)[0]);
                }

                SearchEngineResponse response = ses.Search(
                    sp,
                    (Convert.ToInt32(outfitSearch.Page) * Convert.ToInt32(outfitSearch.PageSize)) - Convert.ToInt32(outfitSearch.PageSize), Convert.ToInt32(outfitSearch.PageSize), sortBy, true);

                totalCount = response.TotalCount;
                List <int> lstIds = new List <int>();
                foreach (SearchEngineResult engineResult in response.Results)
                {
                    lstIds.Add(engineResult.EntryId);
                }
                if (lstIds.Count > 0)
                {
                    result = closetOutfitRepository.Search(lstIds, user.Closet.Id);
                }
            }
            return(result);
        }
コード例 #28
0
 public void CreateSearchEngine()
 {
     _service = new SearchEngineService(new RAMDirectory(), new StandardAnalyzer(Version.LUCENE_29), new FullTextSearchEngineSettings());
 }
コード例 #29
0
        public void SearchEngineService_MoreLikeThisSearch_WithMinDocumentSet_ReturnsEmptySet()
        {
            _service.Dispose();
            _service = new SearchEngineService(new RAMDirectory(), new SnowballAnalyzer("English", stopWords), new FullTextSearchEngineSettings() { Parameters = new TuningParameters() { MinimumDocumentFrequency = 20 } });

            for (int i = 1; i <= 10; i++)
            {
                _service.AddPost(new SearchEngineEntry()
                {
                    EntryId = i,
                    Body = "This is a sample post",
                    Title = "This is the title of the post",
                    Tags = ".net, mvc, post",
                    BlogName = "MyTestBlog",
                    IsPublished = true,
                    PublishDate = DateTime.UtcNow,
                    EntryName = "this-is-the-title"
                }
                );
            }

            var result = _service.RelatedContents(1, 100, 0) as List<SearchEngineResult>;
            Assert.AreEqual(0, result.Count());
        }
コード例 #30
0
 public SearchEngineServiceTest()
 {
     _sut = new SearchEngineService(_serviceSearchAgent.Object);
 }