Skip to content

Commit

Permalink
reverts some last minute changes, ensures multiple searches work when…
Browse files Browse the repository at this point in the history
… not nrt
  • Loading branch information
Shazwazza committed Sep 26, 2024
1 parent b78465d commit dc0b886
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/Examine.Lucene/Indexing/Int32Type.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ namespace Examine.Lucene.Indexing
{
public class Int32Type : IndexFieldRangeValueType<int>
{
private readonly string _docValuesFieldName;

public Int32Type(string fieldName, ILoggerFactory logger, bool store = true)
: base(fieldName, logger, store)
{
_docValuesFieldName = "dv_" + fieldName;
}

/// <summary>
Expand Down
15 changes: 8 additions & 7 deletions src/Examine.Lucene/Providers/LuceneIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,10 +1078,15 @@ private LuceneSearcher CreateSearcher()
};

_nrtReopenThread.Start();
}

// wait for most recent changes when first creating the searcher
WaitForChanges();
// wait for most recent changes when first creating the searcher
_nrtReopenThread.WaitForGeneration(_latestGen.Value, 5000);

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Directories.SyncedFileSystemDirectoryFactoryTests ► Given_CorruptMainIndex_And_HealthyLocalIndex_When_CreatingDirectory_Then_LocalIndexSyncedToMain

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Lucene.Providers.LuceneIndex.get_Searcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 124
   at Examine.Test.Examine.Lucene.Directories.SyncedFileSystemDirectoryFactoryTests.Given_CorruptMainIndex_And_HealthyLocalIndex_When_CreatingDirectory_Then_LocalIndexSyncedToMain() in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Directories/SyncedFileSystemDirectoryFactoryTests.cs:line 113
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Index.LuceneIndexTests ► Can_Overwrite_Index_During_Indexing_Operation

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Lucene.Providers.LuceneIndex.get_Searcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 124
   at Examine.Test.Examine.Lucene.Index.LuceneIndexTests.Can_Overwrite_Index_During_Indexing_Operation() in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Index/LuceneIndexTests.cs:line 495
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Index.LuceneIndexTests ► Index_Read_And_Write_Ensure_No_Errors_In_Async(2000,5000,20,50,100,50,True)

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Lucene.Providers.LuceneIndex.get_Searcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 124
   at Examine.Test.Examine.Lucene.Index.LuceneIndexTests.Index_Read_And_Write_Ensure_No_Errors_In_Async(Int32 indexCount, Int32 searchCount, Int32 indexThreadCount, Int32 searchThreadCount, Int32 indexThreadWait, Int32 searchThreadWait, Boolean inMemory) in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Index/LuceneIndexTests.cs:line 738
   at InvokeStub_LuceneIndexTests.Index_Read_And_Write_Ensure_No_Errors_In_Async(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Index.LuceneIndexTests ► Index_Read_And_Write_Ensure_No_Errors_In_Async(500,2000,20,50,100,50,False)

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Lucene.Providers.LuceneIndex.get_Searcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 124
   at Examine.Test.Examine.Lucene.Index.LuceneIndexTests.Index_Read_And_Write_Ensure_No_Errors_In_Async(Int32 indexCount, Int32 searchCount, Int32 indexThreadCount, Int32 searchThreadCount, Int32 indexThreadWait, Int32 searchThreadWait, Boolean inMemory) in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Index/LuceneIndexTests.cs:line 738
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Search.FluentApiTests ► Custom_Lucene_Query_With_Native

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Lucene.Providers.LuceneIndex.get_Searcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 124
   at Examine.Test.Examine.Lucene.Search.FluentApiTests.Custom_Lucene_Query_With_Native() in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs:line 2184
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Search.FluentApiTests ► Grouped_And_Query_Output

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Test.Examine.Lucene.Search.FluentApiTests.Grouped_And_Query_Output() in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs:line 562
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Search.FluentApiTests ► Grouped_Not_Query_Output

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Test.Examine.Lucene.Search.FluentApiTests.Grouped_Not_Query_Output() in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs:line 617
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Check failure on line 1083 in src/Examine.Lucene/Providers/LuceneIndex.cs

View workflow job for this annotation

GitHub Actions / Publish Tests

Examine.Test.Examine.Lucene.Search.FluentApiTests ► Grouped_Or_Query_Output

Failed test found in: tests.trx Error: System.InvalidOperationException : Nullable object must have a value.
Raw output
System.InvalidOperationException : Nullable object must have a value.
   at System.Nullable`1.get_Value()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher() in /home/runner/work/Examine/Examine/src/Examine.Lucene/Providers/LuceneIndex.cs:line 1083
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at Examine.Test.Examine.Lucene.Search.FluentApiTests.Grouped_Or_Query_Output() in /home/runner/work/Examine/Examine/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs:line 512
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
}
else
{
// wait for most recent changes when first creating the searcher
searcherManager.MaybeRefreshBlocking();
}

return new LuceneSearcher(name + "Searcher", searcherManager, FieldAnalyzer, FieldValueTypeCollection, _options.NrtEnabled);
}
Expand Down Expand Up @@ -1230,10 +1235,6 @@ public void WaitForChanges()
_logger.LogDebug("{IndexName} WaitForChanges returned {GenerationFound}", Name, found);
}
}
else
{
_searcher.Value.MaybeRefreshBlocking();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Examine.Lucene/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Examine.Lucene.LuceneIndexOptions.NrtTargetMinStaleSec.set -> void
Examine.Lucene.Providers.LuceneSearcher.LuceneSearcher(string name, Lucene.Net.Search.SearcherManager searcherManager, Lucene.Net.Analysis.Analyzer analyzer, Examine.Lucene.FieldValueTypeCollection fieldValueTypeCollection, bool isNrt) -> void
Examine.Lucene.Providers.LuceneSearcher.MaybeRefresh() -> bool
Examine.Lucene.Providers.LuceneSearcher.MaybeRefreshBlocking() -> void
Examine.Lucene.Search.LuceneSearchResults.LuceneSearchResults(System.Collections.Generic.IReadOnlyCollection<Examine.ISearchResult> results, int totalItemCount, float maxScore, Examine.Lucene.Search.SearchAfterOptions searchAfterOptions) -> void
Examine.Lucene.Search.SearchContext.SearchContext(Lucene.Net.Search.SearcherManager searcherManager, Examine.Lucene.FieldValueTypeCollection fieldValueTypeCollection, bool isNrt) -> void
Examine.Lucene.Search.SearcherReference.SearcherReference() -> void
virtual Examine.Lucene.Providers.LuceneIndex.UpdateLuceneDocument(Lucene.Net.Index.Term term, Lucene.Net.Documents.Document doc) -> long?
4 changes: 2 additions & 2 deletions src/Examine.Lucene/Search/LuceneSearchExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public ISearchResults Execute()

// Order by Doc Id for improved perf!
// See https://cwiki.apache.org/confluence/display/lucene/ImproveSearchingSpeed
foreach (var scoreDoc in topDocs.ScoreDocs.OrderBy(x => x.Doc))
foreach (var scoreDoc in topDocs.ScoreDocs/*.OrderBy(x => x.Doc)*/)
{
var result = GetSearchResult(scoreDoc, topDocs, searcher.IndexSearcher);
results.Add(result);
}

var searchAfterOptions = scoreDocAfter != null ? GetSearchAfterOptions(topDocs) : null;
var searchAfterOptions = GetSearchAfterOptions(topDocs);
float maxScore = topDocs.MaxScore;

return new LuceneSearchResults(results, totalItemCount, maxScore, searchAfterOptions);
Expand Down
4 changes: 3 additions & 1 deletion src/Examine.Lucene/Search/LuceneSearchQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,15 @@ private ISearchResults Search(QueryOptions options)
return EmptySearchResults.Instance;
}

// TODO: Use a Filter for category, not a query
// https://cwiki.apache.org/confluence/display/lucene/ImproveSearchingSpeed
query = new BooleanQuery
{
// prefix the category field query as a must
{ GetFieldInternalQuery(ExamineFieldNames.CategoryFieldName, new ExamineValue(Examineness.Explicit, Category), true), Occur.MUST }
};

// add the ones that we're already existing
// add the ones that were already existing
foreach (var c in existingClauses)
{
query.Add(c);
Expand Down
6 changes: 2 additions & 4 deletions src/Examine.Lucene/Search/LuceneSearchResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections;
using System.Collections.Generic;

#nullable enable

namespace Examine.Lucene.Search
{
public class LuceneSearchResults : ILuceneSearchResults
Expand All @@ -16,7 +14,7 @@ public LuceneSearchResults(
IReadOnlyCollection<ISearchResult> results,
int totalItemCount,
float maxScore,
SearchAfterOptions? searchAfterOptions)
SearchAfterOptions searchAfterOptions)
{
_results = results;
TotalItemCount = totalItemCount;
Expand All @@ -32,7 +30,7 @@ public LuceneSearchResults(
/// </summary>
public float MaxScore { get; }

Check warning on line 31 in src/Examine.Lucene/Search/LuceneSearchResults.cs

View workflow job for this annotation

GitHub Actions / build


public SearchAfterOptions? SearchAfter { get; }
public SearchAfterOptions SearchAfter { get; }

Check warning on line 33 in src/Examine.Lucene/Search/LuceneSearchResults.cs

View workflow job for this annotation

GitHub Actions / build


public IEnumerator<ISearchResult> GetEnumerator() => _results.GetEnumerator();

Expand Down
26 changes: 26 additions & 0 deletions src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@ namespace Examine.Test.Examine.Lucene.Search
[TestFixture]
public class FluentApiTests : ExamineBaseTest
{
[Test]
public void Multiple_Searches()
{
var analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion);

using (var luceneDir1 = new RandomIdRAMDirectory())
using (var indexer1 = GetTestIndex(luceneDir1, analyzer, nrtEnabled: false))
{
indexer1.IndexItem(ValueSet.FromObject("1", "content", new { item1 = "value1", item2 = "The agitated zebras gallop back and forth in short, panicky dashes, then skitter off into the total absolute darkness." }));

var searcher = indexer1.Searcher;

var result = searcher.Search("darkness");
foreach (var r in result)
{
Console.WriteLine($"Id = {r.Id}, Score = {r.Score}");
}

result = searcher.Search("total darkness");
foreach (var r in result)
{
Console.WriteLine($"Id = {r.Id}, Score = {r.Score}");
}
}
}

[Test]
public void Allow_Leading_Wildcards()
{
Expand Down

0 comments on commit dc0b886

Please sign in to comment.