예제 #1
0
        protected static void LoadIndexes()
        {
            if (_loadedIndexes)
            {
                return;
            }

            LoadTranslations();

            Searcher = Kernel.Get <CardSearcher>();

            var sw = new Stopwatch();

            sw.Start();
            Searcher.LoadIndexes();
            sw.Stop();
            _log.Info($"Searcher indexes loaded in {sw.ElapsedMilliseconds} ms");

            Spellchecker = Searcher.Spellchecker;

            sw.Start();
            KeywordSearcher = Kernel.Get <KeywordSearcher>();
            KeywordSearcher.Load();
            sw.Stop();
            _log.Info($"Keyword searcher index loaded in {sw.ElapsedMilliseconds} ms");

            LogManager.Flush();

            _loadedIndexes = true;
        }
예제 #2
0
        public Installer(
            AppSourceConfig appSourceConfig,
            MtgjsonSourceConfig mtgjsonSourceConfig,
            CardSearcher cardSearcher,
            KeywordSearcher keywordSearcher)
        {
            _appSourceConfig     = appSourceConfig;
            _mtgjsonSourceConfig = mtgjsonSourceConfig;
            _updateAppDir        = AppDir.Update.AddPath("app");

            _appOnlineSignatureFile     = Path.Combine(_updateAppDir, Signer.SignaturesFile);
            _appDownloadedSignatureFile = AppDir.Update.AddPath(Signer.SignaturesFile);
            _appInstalledVersionFile    = AppDir.Update.AddPath("version.txt");

            AppDownloadedSignature = getAppDownloadedSignature();

            _webClient = new WebClientBase();
            _megatools = new Megatools();

            _protectedFiles = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
            {
                AppDir.GeneralConfigXml,
                AppDir.DisplayConfigXml,
                cardSearcher.IndexDirectory.AddPath("*.*"),
                cardSearcher.Spellchecker.IndexDirectory.AddPath("*.*"),
                keywordSearcher.IndexDirectory.AddPath("*.*")
            };
        }
예제 #3
0
        public void Setup()
        {
            LoadTranslations();

            _cardSearcher    = new CardSearcher(Repo, new CardDocumentAdapter());
            _keywordSearcher = new KeywordSearcher(Repo);

            bool filterSet(Set set) => Str.Equals(set.Code, "ISD");

            _cardSearcher.Spellchecker.FilterSet =
                _cardSearcher.FilterSet          =
                    _keywordSearcher.FilterSet   = filterSet;
        }
예제 #4
0
        public void Setup()
        {
            _repo = new CardRepository(Kernel.Get <CardFormatter>(), () => null)
            {
                FilterSetCode = F.IsEqualTo("ISD", Str.Comparer)
            };

            _cardSearcher    = new CardSearcher(_repo, new CardDocumentAdapter(_repo));
            _keywordSearcher = new KeywordSearcher(_repo);

            _repo.LoadFile();
            _repo.Load();
            _repo.FillLocalizations();
        }
예제 #5
0
        public QuickFilterFacade(
            IList <IList <Regex> > patterns,
            IList <IList <string> > values,
            IList <string> fieldNames,
            IList <string> fieldNamesDisplay,
            KeywordSearcher searcher)
        {
            if (fieldNames.Count != values.Count || fieldNames.Count != fieldNamesDisplay.Count)
            {
                throw new ArgumentException(@"invalid length");
            }

            _values   = values;
            _searcher = searcher;
            _patterns = patterns;

            _indexByFieldNameDisplay = Enumerable.Range(0, fieldNamesDisplay.Count)
                                       .GroupBy(i => fieldNamesDisplay[i])
                                       .ToDictionary(
                gr => gr.Key,
                gr => new HashSet <int>(gr));

            Required = Enumerable.Range(0, fieldNames.Count)
                       .Select(i => new KeywordQueryTerm {
                FieldName = fieldNames[i]
            })
                       .ToArray();

            Prohibited = Enumerable.Range(0, fieldNames.Count)
                         .Select(i => new KeywordQueryTerm {
                FieldName = fieldNames[i]
            })
                         .ToArray();

            RequiredSome = Enumerable.Range(0, fieldNames.Count)
                           .Select(i => new KeywordQueryTerm {
                FieldName = fieldNames[i]
            })
                           .ToArray();

            Ignored = Enumerable.Range(0, fieldNames.Count)
                      .Select(i => new KeywordQueryTerm {
                FieldName = fieldNames[i]
            })
                      .ToArray();
        }
예제 #6
0
파일: Loader.cs 프로젝트: NikolayXHD/Mtgdb
        [UsedImplicitly]         // by ninject
        public Loader(
            CardRepository repository,
            PriceRepository priceRepository,
            ImageRepository imageRepository,
            CardSearcher cardSearcher,
            KeywordSearcher keywordSearcher,
            IApplication app)
        {
            _repository      = repository;
            _priceRepository = priceRepository;
            _imageRepository = imageRepository;
            _cardSearcher    = cardSearcher;
            _keywordSearcher = keywordSearcher;
            _app             = app;

            createLoadingActions();
        }
예제 #7
0
        public IActionResult Index(SearchRequestModel searchRequest)
        {
            try
            {
                var finder   = new KeywordSearcher(searchRequest.SearchEngine, searchRequest.SearchText);
                int location = 1 + finder.FindIndex(searchRequest.Keywords);

                searchRequest.Result = $"Found in position {location}";;
            }
            catch (NotImplementedException)
            {
                searchRequest.Result = $"{searchRequest.SearchEngine.ToString()} is not yet available";
            }
            catch (Exception)
            {
                searchRequest.Result = $"Could not perform search";
            }
            return(View("Index", searchRequest));
        }
예제 #8
0
        public void Setup()
        {
            _repo = new CardRepository
            {
                FilterSetCode = F.IsEqualTo("ISD", Str.Comparer)
            };

            _localizationRepo = new LocalizationRepository();
            _cardSearcher     = new CardSearcher(_repo, new CardDocumentAdapter(_repo));
            _keywordSearcher  = new KeywordSearcher(_repo);

            _repo.LoadFile();
            _repo.Load();

            _localizationRepo.LoadFile();
            _localizationRepo.Load();

            _repo.FillLocalizations(_localizationRepo);
        }
예제 #9
0
        public FormMain(
            UndoConfig undoConfig,
            CardRepository cardRepo,
            ImageRepository imageRepo,
            ImageCacheConfig imageCacheConfig,
            ImageLoader imageLoader,
            CollectionEditorModel collectionEditor,
            CardSearcher cardSearcher,
            CardDocumentAdapter cardAdapter,
            DeckDocumentAdapter deckAdapter,
            KeywordSearcher keywordSearcher,
            ForgeSetRepository forgeSetRepo,
            DeckListModel deckListModel,
            DeckSearcher deckSearcher,
            IconRecognizer iconRecognizer,
            FormManager formManager)
            : this()
        {
            DoubleBuffered = true;
            KeyPreview     = true;

            _viewCards = new MtgLayoutView(_layoutViewCards);
            _viewDeck  = new MtgLayoutView(_layoutViewDeck);

            _cardSearcher        = cardSearcher;
            _keywordSearcher     = keywordSearcher;
            _quickFilterControls = QuickFilterSetup.GetQuickFilterControls(this);

            _cardRepo         = cardRepo;
            _imageLoader      = imageLoader;
            _collectionEditor = collectionEditor;
            _serialization    = new DeckSerializationSubsystem(_cardRepo, forgeSetRepo);

            beginRestoreSettings();

            _fields = new Fields();

            QuickFilterSetup.SetQuickFilterProperties(this);
            QuickFilterImages.SetImages(this);

            _quickFilterFacade = new QuickFilterFacade(
                KeywordDefinitions.Patterns,
                KeywordDefinitions.Values.ToKeywordDisplayTexts(),
                KeywordDefinitions.PropertyNames,
                KeywordDefinitions.PropertyNamesDisplay,
                keywordSearcher);

            _buttons = new ButtonSubsystem();

            _cardSearch = new CardSearchSubsystem(
                this,
                _searchEditor,
                _panelIconSearch,
                _listBoxSuggest,
                cardSearcher,
                cardAdapter,
                _viewCards,
                _viewDeck);

            _panelSearchExamples.Setup(_cardSearch, _buttons, _buttonSearchExamplesDropDown);

            _sort = new SortSubsystem(_viewCards, _cardRepo, _fields, _cardSearch);

            endRestoreSettings();

            _tooltipViewCards = new LayoutViewTooltip(this, _viewCards, _cardSearch);
            _tooltipViewDeck  = new LayoutViewTooltip(this, _viewDeck, _cardSearch);

            var formZoomCard = new FormZoom(_cardRepo, imageRepo, _imageLoader);

            _scroll = new ScrollSubsystem(_viewDeck, _viewCards);

            _imagePreloading = new ImagePreloadingSubsystem(
                _viewCards,
                _viewDeck,
                _scroll,
                imageCacheConfig);

            _deckEditor = new DeckEditorModel();

            _dragging = new DraggingSubsystem(
                _viewDeck,
                _viewCards,
                _deckEditor,
                this,
                _imageLoader,
                formManager);

            _deckEditorUi = new DeckEditorUi(
                _viewCards,
                _viewDeck,
                _deckEditor,
                _collectionEditor,
                _dragging,
                Cursor,
                formZoomCard);

            _viewDeck.SetDataSource(_deckEditor.DataSource);
            _viewCards.SetDataSource(_searchResultCards);

            _legality = new LegalitySubsystem(
                _menuLegalityFormat,
                _buttonLegalityAllowLegal,
                _buttonLegalityAllowRestricted,
                _buttonLegalityAllowBanned);

            _drawing = new DrawingSubsystem(
                _viewCards,
                _viewDeck,
                _dragging,
                _cardSearch,
                cardAdapter,
                _deckEditor,
                _quickFilterFacade,
                _legality,
                _imageLoader,
                iconRecognizer);


            _printing = new PrintingSubsystem(imageRepo, _cardRepo);

            DeckZone = Zone.Main;

            scale();
            setRightPanelsWidth();

            _keywordsIndexUpToDate     = _keywordSearcher.IsUpToDate;
            _luceneSearchIndexUpToDate = _cardSearcher.IsUpToDate;
            _spellcheckerIndexUpToDate = _cardSearcher.Spellchecker.IsUpToDate;

            _searchTextSelection = new RichTextBoxSelectionSubsystem(_searchEditor);

            _history = new HistorySubsystem(undoConfig);

            _evaluators = new Evaluators
            {
                { 2, _legality.IsAllowedInFormat },
                { 3, evalFilterByCollection },
                { 4, evalFilterByDeck },
                { 0, _quickFilterFacade.Evaluate },
                { 1, evalFilterBySearchText }
            };

            _deckListControl.Init(
                deckListModel,
                iconRecognizer,
                deckSearcher,
                deckAdapter,
                this);

            _copyPaste = new CopyPasteSubsystem(
                _cardRepo,
                _serialization,
                _collectionEditor,
                _deckEditor,
                _formRoot,
                this,
                _layoutViewDeck,
                _tabHeadersDeck,
                _layoutViewCards,
                _deckListControl.DeckListView);

            setupCheckButtonImages();

            updateExcludeManaAbility();
            updateExcludeManaCost();
            updateShowProhibited();
            updateShowSampleHandButtons();
            updateDeckVisibility();

            subscribeToEvents();
        }
예제 #10
0
        public void Interesting_keywords_Are_displayed_in_button_filter()
        {
            var keywords = KeywordDefinitions.PatternsByDisplayText[KeywordDefinitions.KeywordsIndex].Keys
                           .ToHashSet(Str.Comparer);

            var boringKeywords = new HashSet <string>(Str.Comparer)
            {
                "Devoid",
                "Plainswalk",
                "Forestwalk",
                "Swampwalk",
                "Mountainwalk",
                "Islandwalk",
                "Cumulative Upkeep",
                "Level Up"
            };

            boringKeywords.UnionWith(keywords.SkipWhile(F.IsNotEqualTo("Activate")));

            var popularity = keywords
                             .Where(F.IsNotNull)
                             .Select(kw =>
            {
                var cardIds = KeywordSearcher
                              .GetCardIds(nameof(KeywordDefinitions.Keywords), kw);

                return(
                    Keyword: kw,
                    TopPrice: getTopPriceInFormat(cardIds, "modern"));
            })
                             .OrderBy(p => boringKeywords.Contains(p.Keyword))
                             .ThenByDescending(p => p.TopPrice)
                             .ToArray();

            var popularityIndexByKeyword = Enumerable.Range(0, popularity.Length)
                                           .ToDictionary(i => popularity[i].Keyword, i => i);

            var popularityByKeyword = popularity
                                      .ToDictionary(p => p.Keyword, p => p.TopPrice);

            var displayKeywords = keywords
                                  .TakeWhile(F.IsNotEqualTo("Absorb"))
                                  .ToHashSet(Str.Comparer);

            var notDisplayedPopular = keywords
                                      .OrderBy(kw => popularityIndexByKeyword[kw])
                                      .Take(displayKeywords.Count)
                                      .Where(F.Not <string>(displayKeywords.Contains))
                                      .ToArray();

            if (notDisplayedPopular.Length > 0)
            {
                var toReplace = displayKeywords
                                .OrderByDescending(kw => popularityIndexByKeyword[kw])
                                .Take(notDisplayedPopular.Length)
                                .ToArray();

                var message = new StringBuilder($"Non displayed frequently used keywords ({notDisplayedPopular.Length}):")
                              .AppendLine()
                              .Append(string.Join(Str.Endl, notDisplayedPopular.Select(kw => $"{popularityByKeyword[kw]}: {kw}")))
                              .AppendLine()
                              .AppendLine("Shoud replace following keywords:")
                              .Append(string.Join(Str.Endl, toReplace.Select(kw => $"{popularityByKeyword[kw]}: {kw}")))
                              .ToString();

                Log.Info(message);
            }
        }
예제 #11
0
        public void Test100ResultsFoundForBing()
        {
            var count = new KeywordSearcher(SearchEngineType.Bing, "binging bing").ResultCount();

            Assert.That(count, Is.EqualTo(100));
        }
예제 #12
0
        public void Test100ResultsFound()
        {
            var count = new KeywordSearcher(SearchEngineType.Google, "googling google").ResultCount();

            Assert.That(count, Is.EqualTo(100));
        }
예제 #13
0
        public void TestFindKeyphraseFirstAppearanceIndex_DoesNotThrowException()
        {
            var index = new KeywordSearcher(SearchEngineType.Google, "e-settlements").FindIndex("sympli");

            Assert.Pass();
        }
예제 #14
0
        public FormMain(
            CardRepository cardRepo,
            PriceRepository priceRepo,
            ImageRepository imageRepo,
            ImageLoader imageLoader,
            UiConfigRepository uiConfigRepository,
            CollectionEditorModel collectionEditor,
            CardSearcher cardSearcher,
            CardDocumentAdapter cardAdapter,
            DeckDocumentAdapter deckAdapter,
            KeywordSearcher keywordSearcher,
            DeckListModel deckListModel,
            DeckSearcher deckSearcher,
            IconRecognizer iconRecognizer,
            DeckSerializationSubsystem serialization,
            MtgArenaIntegration mtgArenaIntegration,
            App app)
            : this()
        {
            DoubleBuffered = true;

            _app                 = app;
            _cardSearcher        = cardSearcher;
            _keywordSearcher     = keywordSearcher;
            _quickFilterControls = QuickFilterSetup.GetQuickFilterControls(this);

            _cardRepo            = cardRepo;
            _priceRepo           = priceRepo;
            _imageLoader         = imageLoader;
            _uiConfigRepository  = uiConfigRepository;
            _collectionEditor    = collectionEditor;
            _serialization       = serialization;
            _mtgArenaIntegration = mtgArenaIntegration;

            beginRestoreSettings();

            _fields = new CardFields();

            QuickFilterSetup.SetQuickFilterProperties(this);
            QuickFilterImages.SetImages(this);

            _quickFilterFacade = new QuickFilterFacade(
                KeywordDefinitions.Patterns,
                KeywordDefinitions.Values.ToKeywordDisplayTexts(),
                KeywordDefinitions.PropertyNames,
                KeywordDefinitions.PropertyNamesDisplay,
                keywordSearcher);

            _searchSubsystem = new CardSearchSubsystem(
                this,
                _searchBar,
                uiConfigRepository,
                cardSearcher,
                cardAdapter,
                _viewCards,
                _viewDeck);

            _cardSort = new CardSortSubsystem(_viewCards, _cardRepo, _fields, _searchSubsystem);

            endRestoreSettings();

            _countInputSubsystem = new CountInputSubsystem();
            _tooltipViewCards    = new LayoutViewTooltip(this, _viewCards, _searchSubsystem, _countInputSubsystem);
            _tooltipViewDeck     = new LayoutViewTooltip(this, _viewDeck, _searchSubsystem, _countInputSubsystem);

            _formZoom = new FormZoom(_cardRepo, imageRepo, _imageLoader);

            _imagePreloading = new ImagePreloadingSubsystem(
                _viewCards,
                _viewDeck,
                uiConfigRepository);

            _deckEditor = new DeckEditorModel();

            _dragging = new DraggingSubsystem(
                _viewDeck,
                _viewCards,
                _deckEditor,
                this,
                _imageLoader,
                _app);

            _deckEditorSubsystem = new DeckEditorSubsystem(
                _viewCards,
                _viewDeck,
                _deckEditor,
                _collectionEditor,
                _dragging,
                _countInputSubsystem,
                Cursor,
                _formZoom,
                this);

            _viewDeck.DataSource  = _deckEditor.DataSource;
            _viewCards.DataSource = _searchResultCards;

            _legality = new LegalitySubsystem(
                _dropdownLegality,
                _buttonLegalityAllowLegal,
                _buttonLegalityAllowRestricted,
                _buttonLegalityAllowBanned,
                _buttonLegalityAllowFuture);

            _drawing = new DrawingSubsystem(
                _viewCards,
                _viewDeck,
                _searchSubsystem,
                cardAdapter,
                _deckEditor,
                _countInputSubsystem,
                _quickFilterFacade,
                _legality,
                iconRecognizer);


            _printing = new PrintingSubsystem(imageRepo, _cardRepo);

            _deckZones = new DeckZoneSubsystem(
                _tabHeadersDeck,
                _dragging,
                _viewDeck)
            {
                DeckZone = Zone.Main
            };

            scale();
            setRightPanelsWidth();

            _keywordsIndexUpToDate     = _keywordSearcher.IsUpToDate;
            _luceneSearchIndexUpToDate = _cardSearcher.IsUpToDate;
            _spellcheckerIndexUpToDate = _cardSearcher.Spellchecker.IsUpToDate;

            _history = new HistorySubsystem(uiConfigRepository);

            _evaluators = new Evaluators
            {
                { 2, _legality.MatchesLegalityFilter },
                { 3, evalFilterByCollection },
                { 4, evalFilterByDeck },
                { 0, _quickFilterFacade.Evaluate },
                { 1, evalFilterBySearchText }
            };

            _deckSearcher = deckSearcher;
            _deckListControl.Init(
                deckListModel,
                iconRecognizer,
                _deckSearcher,
                deckAdapter,
                collectionEditor,
                uiConfigRepository,
                this,
                _app);

            _copyPaste = new CopyPasteSubsystem(
                _cardRepo,
                _serialization,
                _collectionEditor,
                _deckEditor,
                this,
                _deckListControl,
                _viewDeck,
                _tabHeadersDeck,
                _viewCards,
                _deckListControl.DeckListView);

            updateExcludeManaAbility();
            updateExcludeManaCost();
            updateShowProhibited();
            updateShowSampleHandButtons();
            updateDeckVisibility();

            subscribeToEvents();

            if (components == null)
            {
                components = new Container();
            }

            components.Add(_deckEditorSubsystem);
            components.Add(_countInputSubsystem);
            components.Add(_formZoom);
            components.Add(_copyPaste);

            _popupSearchExamples.MenuControl   = _menuSearchExamples;
            _popupSearchExamples.MenuAlignment = HorizontalAlignment.Right;
        }