From 411738a999a1c0c7329c3c2e58d4d3445267ce97 Mon Sep 17 00:00:00 2001 From: oyessb <47382101+oyessb@users.noreply.github.com> Date: Thu, 17 Sep 2026 10:41:56 +0200 Subject: [PATCH] Change default search operator to OR in LuceneSearcher The default operator in LuceneSearcher is now OR, allowing queries to match documents with any of the terms. Added unit test SearchUsesOrAsDefaultOperator to verify this behavior. --- Px.Search.Lucene/LuceneSearcher.cs | 2 +- PxWeb.UnitTests/Search/LuceneAnalyzerTest.cs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Px.Search.Lucene/LuceneSearcher.cs b/Px.Search.Lucene/LuceneSearcher.cs index 3a8a722e..28e55cae 100644 --- a/Px.Search.Lucene/LuceneSearcher.cs +++ b/Px.Search.Lucene/LuceneSearcher.cs @@ -7,7 +7,7 @@ namespace Px.Search.Lucene public class LuceneSearcher : ISearcher { private readonly IndexSearcher _indexSearcher; - private static readonly Operator _defaultOperator = Operator.AND; + private static readonly Operator _defaultOperator = Operator.OR; private readonly Analyzer _analyzer; private readonly string[] _fieldNames; diff --git a/PxWeb.UnitTests/Search/LuceneAnalyzerTest.cs b/PxWeb.UnitTests/Search/LuceneAnalyzerTest.cs index 49280de7..b8b54f6d 100644 --- a/PxWeb.UnitTests/Search/LuceneAnalyzerTest.cs +++ b/PxWeb.UnitTests/Search/LuceneAnalyzerTest.cs @@ -16,6 +16,14 @@ public void UsingSwedishAnalyzerOnSingular() TestSearcher("sv", "region", 3); } + [TestMethod] + public void SearchUsesOrAsDefaultOperator() + { + // "region" has 3 hits in current test data. + // The second term should not exist, so with OR the result should still be 3. + // With AND this would become 0, so this test guards the default operator behavior. + TestSearcher("sv", "region thistextdoesnotexist", 3); + } private void TestSearcher(string language, string searchFor, int expectedCount) { @@ -36,8 +44,6 @@ private void TestSearcher(string language, string searchFor, int expectedCount) MyHost myHost = new MyHost(wwwPath); - - var myOptions = Microsoft.Extensions.Options.Options.Create(luceneConfigurationOptions); ILuceneConfigurationService conf = new LuceneConfigurationService(myOptions, myHost);