From 2623b1860a2e9007b65b83afee7a89fc86db0f7d Mon Sep 17 00:00:00 2001 From: Nikolaj Brask-Nielsen Date: Mon, 24 Oct 2022 09:35:08 +0200 Subject: [PATCH] fix: Fixed category not using queryparser (#302) --- .../Search/LuceneSearchQuery.cs | 2 +- .../Examine.Lucene/Search/FluentApiTests.cs | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Examine.Lucene/Search/LuceneSearchQuery.cs b/src/Examine.Lucene/Search/LuceneSearchQuery.cs index 01832b92d..0d782a894 100644 --- a/src/Examine.Lucene/Search/LuceneSearchQuery.cs +++ b/src/Examine.Lucene/Search/LuceneSearchQuery.cs @@ -200,7 +200,7 @@ private ISearchResults Search(QueryOptions options) query = new BooleanQuery { // prefix the category field query as a must - { GetFieldInternalQuery(ExamineFieldNames.CategoryFieldName, new ExamineValue(Examineness.Explicit, Category), false), Occur.MUST } + { GetFieldInternalQuery(ExamineFieldNames.CategoryFieldName, new ExamineValue(Examineness.Explicit, Category), true), Occur.MUST } }; // add the ones that we're already existing diff --git a/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs b/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs index 3d97ea3c6..ebd3d8b0e 100644 --- a/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs +++ b/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs @@ -92,6 +92,37 @@ public void NativeQuery_Single_Word() } } + [Test] + public void Uppercase_Category() + { + var analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion); + using (var luceneDir = new RandomIdRAMDirectory()) + using (var indexer = GetTestIndex( + luceneDir, + analyzer, + new FieldDefinitionCollection(new FieldDefinition("parentID", FieldDefinitionTypes.Integer)))) + { + indexer.IndexItems(new[] { + ValueSet.FromObject(1.ToString(), "cOntent", + new { nodeName = "location 1", bodyText = "Zanzibar is in Africa"}), + ValueSet.FromObject(2.ToString(), "cOntent", + new { nodeName = "location 2", bodyText = "In Canada there is a town called Sydney in Nova Scotia"}), + ValueSet.FromObject(3.ToString(), "cOntent", + new { nodeName = "location 3", bodyText = "Sydney is the capital of NSW in Australia"}) + }); + + var searcher = indexer.Searcher; + + var query = searcher.CreateQuery("cOntent").All(); + + Console.WriteLine(query); + + var results = query.Execute(); + + Assert.AreEqual(3, results.TotalItemCount); + } + } + [Test] public void NativeQuery_Phrase() {