Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Px.Search.Lucene/LuceneSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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;

Expand Down Expand Up @@ -154,7 +154,7 @@
);
searchResult.Description = doc.Get(SearchConstants.SEARCH_FIELD_DESCRIPTION);
searchResult.SortCode = doc.Get(SearchConstants.SEARCH_FIELD_SORTCODE);
if (DateTime.TryParse(doc.Get(SearchConstants.SEARCH_FIELD_UPDATED), out updated))

Check warning on line 157 in Px.Search.Lucene/LuceneSearcher.cs

View workflow job for this annotation

GitHub Actions / build

Use a format provider when parsing date and time.

Check warning on line 157 in Px.Search.Lucene/LuceneSearcher.cs

View workflow job for this annotation

GitHub Actions / build

Use a format provider when parsing date and time.

Check warning on line 157 in Px.Search.Lucene/LuceneSearcher.cs

View workflow job for this annotation

GitHub Actions / build

Use a format provider when parsing date and time.
{
searchResult.Updated = updated;
}
Expand Down
10 changes: 8 additions & 2 deletions PxWeb.UnitTests/Search/LuceneAnalyzerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, so this should also be true?
TestSearcher("sv", "region AND thistextdoesnotexist", 0);


private void TestSearcher(string language, string searchFor, int expectedCount)
{
Expand All @@ -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);
Expand Down
Loading