public void LuceneController_Search_With_Chinese_Chars_And_Custom_Analyzer(string customAlalyzer = "") { _mockHostController.Setup(c => c.GetString(Constants.SearchCustomAnalyzer, It.IsAny <string>())).Returns(customAlalyzer); //Arrange const string fieldName = "content"; const string fieldValue = Line_Chinese; //Act var field = new Field(fieldName, fieldValue, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS); var doc = new Document(); doc.Add(field); _luceneController.Add(doc); _luceneController.Commit(); var analyzer = _luceneController.GetCustomAnalyzer() ?? new SearchQueryAnalyzer(true); var keywordQuery = new BooleanQuery(); var parserContent = new QueryParser(Constants.LuceneVersion, fieldName, analyzer); var parsedQueryContent = parserContent.Parse(SearchKeyword_Chinese); keywordQuery.Add(parsedQueryContent, Occur.SHOULD); var hits = _luceneController.Search(CreateSearchContext(new LuceneQuery { Query = keywordQuery })); //Assert if (customAlalyzer == ValidCustomAnalyzer) { Assert.AreEqual(1, hits.Results.Count()); Assert.AreEqual(Line_Chinese.Replace(SearchKeyword_Chinese, string.Format("<b>{0}</b>", SearchKeyword_Chinese)), hits.Results.ElementAt(0).ContentSnippet); } else { Assert.AreEqual(0, hits.Results.Count()); } }
public void GetCustomAnalyzer_WithTheProvidedAnalyzer_ReturnsTheAnalyzerCorrectly() { // Arrange const string HostSettingsTableName = "HostSettings"; const string SettingNameColumnName = "SettingName"; const string SettingValueColumnName = "SettingValue"; const string SettingIsSecureColumnName = "SettingIsSecure"; const string CustomAnalyzerCacheKeyName = "Search_CustomAnalyzer"; const string CzechAnalyzerTypeName = "Lucene.Net.Analysis.Cz.CzechAnalyzer, Lucene.Net.Contrib.Analyzers"; var services = new ServiceCollection(); var mockData = MockComponentProvider.CreateDataProvider(); var hostSettings = new DataTable(HostSettingsTableName); var nameCol = hostSettings.Columns.Add(SettingNameColumnName); hostSettings.Columns.Add(SettingValueColumnName); hostSettings.Columns.Add(SettingIsSecureColumnName); hostSettings.PrimaryKey = new[] { nameCol }; hostSettings.Rows.Add(CustomAnalyzerCacheKeyName, CzechAnalyzerTypeName, true); mockData.Setup(c => c.GetHostSettings()).Returns(hostSettings.CreateDataReader()); var mockedApplicationStatusInfo = new Mock <IApplicationStatusInfo>(); mockedApplicationStatusInfo.Setup(s => s.Status).Returns(UpgradeStatus.Install); mockedApplicationStatusInfo.Setup(s => s.ApplicationMapPath).Returns(string.Empty); services.AddTransient(container => Mock.Of <IHostSettingsService>()); services.AddTransient(container => mockedApplicationStatusInfo.Object); services.AddTransient(container => Mock.Of <INavigationManager>()); Globals.DependencyProvider = services.BuildServiceProvider(); MockComponentProvider.CreateDataCacheProvider(); DataCache.ClearCache(); var luceneController = new LuceneControllerImpl(); // Act var analyzer = luceneController.GetCustomAnalyzer(); // Assert Assert.IsInstanceOf <CzechAnalyzer>(analyzer); }