diff --git a/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs b/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs index 286167b25..f7f9df128 100644 --- a/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs +++ b/src/Examine.Test/Examine.Lucene/Search/FluentApiTests.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Examine.Lucene.Providers; using Examine.Lucene.Search; using Examine.Search; @@ -2198,6 +2200,55 @@ public void Category() } } + [Ignore("This test needs to be updated to ensure that searching calls GetFieldInternalQuery with useQueryParser = false, see https://github.com/Shazwazza/Examine/issues/335#issuecomment-1834677581")] + [Test] + public void Query_With_Category_Multi_Threaded() + { + var analyzer = new StandardAnalyzer(LuceneInfo.CurrentVersion); + using (var luceneDir = new RandomIdRAMDirectory()) + using (var indexer = GetTestIndex(luceneDir, analyzer)) + { + indexer.IndexItems(new[] { + ValueSet.FromObject(1.ToString(), "content", + new { Content = "hello world", Type = "type1" }), + ValueSet.FromObject(2.ToString(), "content", + new { Content = "hello something or other", Type = "type1" }), + ValueSet.FromObject(3.ToString(), "content", + new { Content = "hello you guys", Type = "type3" }), + ValueSet.FromObject(4.ToString(), "media", + new { Content = "hello you cruel world", Type = "type2" }), + ValueSet.FromObject(5.ToString(), "media", + new { Content = "hi there, hello world", Type = "type2" }) + }); + + var searcher = indexer.Searcher; + + var tasks = Enumerable.Range(0, 1) + .Select(x => new Task(() => + { + var criteria = searcher.CreateQuery("content", BooleanOperation.And); + IBooleanOperation examineQuery; + examineQuery = criteria + .GroupedOr(new string[] { "Type" }, "type1", "type2") + .And() + .Field("Content", "hel".MultipleCharacterWildcard()); + + var results = examineQuery.Execute(); + + //Assert + Console.WriteLine(results.TotalItemCount + ", Thread: " + Thread.CurrentThread.ManagedThreadId); + Assert.AreEqual(2, results.TotalItemCount); + })) + .ToArray(); + + Parallel.ForEach(tasks, x => x.Start()); + + Task.WaitAll(tasks); + + Assert.IsTrue(tasks.All(x => x.IsCompletedSuccessfully)); + } + } + //[Test] //public void Wildcard_Results_Sorted_By_Score() //{