Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Searcher Synchronously? #381

Closed
SerratedSharp opened this issue Apr 22, 2024 · 4 comments
Closed

Getting Searcher Synchronously? #381

SerratedSharp opened this issue Apr 22, 2024 · 4 comments
Labels

Comments

@SerratedSharp
Copy link

When in a .NET WASM project, Thread.Start() is not allowed. I believe _nrtReopenThread.Start(); in LuceneIndex.CreateSearcher() is doing this. I'm inside a using block .WithThreadingMode(IndexThreadingMode.Synchronous), but I take it that only affects indexing, and not searching.

Is there a work around that would allow me to perform searches synchrounously without threading?

Projected to ValueSets in 0.15048000000000006s
Indexing complete: 0.9268600000000001s
Operation is not supported on this platform.
System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Threading.Thread.ThrowIfNoThreadStart(Boolean internalThread)
   at System.Threading.Thread.Start(Boolean captureContext, Boolean internalThread)
   at System.Threading.Thread.Start()
   at J2N.Threading.ThreadJob.Start()
   at Examine.Lucene.Providers.LuceneIndex.CreateSearcher()
   at System.Lazy`1[[Examine.Lucene.Providers.LuceneSearcher, Examine.Lucene, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1[[Examine.Lucene.Providers.LuceneSearcher, Examine.Lucene, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1[[Examine.Lucene.Providers.LuceneSearcher, Examine.Lucene, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].CreateValue()
   at System.Lazy`1[[Examine.Lucene.Providers.LuceneSearcher, Examine.Lucene, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null]].get_Value()
   at Examine.Lucene.Providers.LuceneIndex.get_Searcher()
   at Program.Main(String[] args)
using (var luceneIndex = (LuceneIndex)index)
using (var syncIndexContext = luceneIndex.WithThreadingMode(IndexThreadingMode.Synchronous))
{
    index.IndexItems(cardsValueSets);
    Console.WriteLine($"Indexing complete: {sw.Elapsed.TotalSeconds - lastTotalSeconds}s");

    try
    {     
        var searcher = index.Searcher; // Get a searcher
        var results = searcher.Search("vault");
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        Console.WriteLine(ex);
    }
}
@Shazwazza
Copy link
Owner

Hrm, this is a rather interesting question. Examine currently doesn't use Thread.Start but uses a queue of Tasks to perform the indexing. Lucene itself however I believe is quite dependent on Threads but this potentially depends on what is happening.

I think in this case you are correct and that it is the NRT functionality.

To be able to toggle this functionality in Examine will require some feature updates. We can add a boolean to LuceneIndexOptions to enable/disable NRT but this will have some cascading effects through the indexer along with adding a bunch more unit tests to ensure that the behavior between non-NRT and NRT has the expected results.

@SerratedSharp
Copy link
Author

Thanks, if it's infeasible I understand. I was able to directly use Lucene.NET library instead and create/get IndexWriter/IndexSearcher's. So I will go that route for now. Thank you.

@Shazwazza
Copy link
Owner

Thanks, i'll close this for now but will look at creating this type of feature in the future.

@SerratedSharp
Copy link
Author

Thanks, i'll close this for now but will look at creating this type of feature in the future.

FYI While researching I saw some discussion about adding multithreaded support for WASM: dotnet/runtime#68162 (comment)

There'll probably be caveats even when supported, but it's possible this will just work in time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants