public void CheckAnalyzers() { var operation = new TestOperation("test", null); var fields = new Dictionary <string, IndexField>(); fields.Add(Constants.Documents.Indexing.Fields.AllFields, new IndexField()); Assert.Throws <InvalidOperationException>(() => operation.GetAnalyzer(fields, forQuerying: false)); fields.Clear(); fields.Add(Constants.Documents.Indexing.Fields.AllFields, new IndexField { Analyzer = "StandardAnalyzer" }); Assert.Throws <InvalidOperationException>(() => operation.GetAnalyzer(fields, forQuerying: false)); fields.Clear(); fields.Add("Field1", new IndexField { Analyzer = "StandardAnalyzer" }); // field must be 'NotAnalyzed' or 'Analyzed' var analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = "StandardAnalyzer", Indexing = FieldIndexing.Exact }); // 'NotAnalyzed' => 'KeywordAnalyzer' analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <KeywordAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = null, Indexing = FieldIndexing.Search }); // 'Analyzed = null' => 'StandardAnalyzer' analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <RavenStandardAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = typeof(NotForQueryingAnalyzer).AssemblyQualifiedName, Indexing = FieldIndexing.Search }); analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <NotForQueryingAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = typeof(NotForQueryingAnalyzer).AssemblyQualifiedName, Indexing = FieldIndexing.Search }); analyzer = operation.GetAnalyzer(fields, forQuerying: true); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <RavenStandardAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = typeof(NotForQueryingAnalyzer).AssemblyQualifiedName, Indexing = FieldIndexing.Search }); fields.Add("Field2", new IndexField { Name = "Field2", Analyzer = "KeywordAnalyzer", Indexing = FieldIndexing.Search }); analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <NotForQueryingAnalyzer>(analyzer.GetAnalyzer("Field1")); Assert.IsType <KeywordAnalyzer>(analyzer.GetAnalyzer("Field2")); }
public async Task CheckAnalyzers() { using (var store = GetDocumentStore()) { var configuration = RavenConfiguration.CreateForTesting("test", Raven.Server.ServerWide.ResourceType.Server); configuration.Initialize(); var database = await Databases.GetDocumentDatabaseInstanceFor(store); var index = new TestIndex(database, configuration.Indexing); var operation = new TestOperation(index, null); var fields = new Dictionary <string, IndexField>(); fields.Add(Constants.Documents.Indexing.Fields.AllFields, new IndexField()); Assert.Throws <InvalidOperationException>(() => operation.GetAnalyzer(fields, forQuerying: false)); fields.Clear(); fields.Add(Constants.Documents.Indexing.Fields.AllFields, new IndexField { Analyzer = "StandardAnalyzer" }); Assert.Throws <InvalidOperationException>(() => operation.GetAnalyzer(fields, forQuerying: false)); fields.Clear(); fields.Add("Field1", new IndexField { Analyzer = "StandardAnalyzer" }); // field must be 'NotAnalyzed' or 'Analyzed' var analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = "StandardAnalyzer", Indexing = FieldIndexing.Exact }); // 'NotAnalyzed' => 'KeywordAnalyzer' analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <KeywordAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = null, Indexing = FieldIndexing.Search }); // 'Analyzed = null' => 'StandardAnalyzer' analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <RavenStandardAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = typeof(NotForQueryingAnalyzer).AssemblyQualifiedName, Indexing = FieldIndexing.Search }); analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <NotForQueryingAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = typeof(NotForQueryingAnalyzer).AssemblyQualifiedName, Indexing = FieldIndexing.Search }); analyzer = operation.GetAnalyzer(fields, forQuerying: true); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <RavenStandardAnalyzer>(analyzer.GetAnalyzer("Field1")); fields.Clear(); fields.Add("Field1", new IndexField { Name = "Field1", Analyzer = typeof(NotForQueryingAnalyzer).AssemblyQualifiedName, Indexing = FieldIndexing.Search }); fields.Add("Field2", new IndexField { Name = "Field2", Analyzer = "KeywordAnalyzer", Indexing = FieldIndexing.Search }); analyzer = operation.GetAnalyzer(fields, forQuerying: false); Assert.IsType <LowerCaseKeywordAnalyzer>(analyzer.GetAnalyzer(string.Empty)); Assert.IsType <NotForQueryingAnalyzer>(analyzer.GetAnalyzer("Field1")); Assert.IsType <KeywordAnalyzer>(analyzer.GetAnalyzer("Field2")); } }