當前位置: 首頁>>代碼示例>>C#>>正文


C# LuceneSearcher.Search方法代碼示例

本文整理匯總了C#中N2.Persistence.Search.LuceneSearcher.Search方法的典型用法代碼示例。如果您正苦於以下問題:C# LuceneSearcher.Search方法的具體用法?C# LuceneSearcher.Search怎麽用?C# LuceneSearcher.Search使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在N2.Persistence.Search.LuceneSearcher的用法示例。


在下文中一共展示了LuceneSearcher.Search方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Skip

		public void Skip()
		{
			indexer.Update(CreateOneItem<PersistableItem1>(3, "Hello country", root));
			indexer.Update(CreateOneItem<PersistableItem1>(2, "Hello world", root));
			indexer.Update(CreateOneItem<PersistableItem1>(4, "Hello universe", root));

			var searcher = new LuceneSearcher(accessor, persister);
			var hits1 = searcher.Search(Query.For("hello").Take(1));
			var hits2 = searcher.Search(Query.For("hello").Skip(1).Take(1));
			var hits3 = searcher.Search(Query.For("hello").Skip(2).Take(1));

			Assert.That(hits1.Single(), Is.Not.EqualTo(hits2.Single()));
			Assert.That(hits2.Single(), Is.Not.EqualTo(hits3.Single()));
			Assert.That(hits3.Single(), Is.Not.EqualTo(hits1.Single()));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:15,代碼來源:LuceneSearchTests.cs

示例2: Title

		public void Title()
		{
			var item = CreateOneItem<PersistableItem1>(2, "Hello world", root);
			indexer.Update(item);

			var searcher = new LuceneSearcher(accessor, persister);
			var hits = searcher.Search(Query.For("hello"));

			Assert.That(hits.Hits.Count(), Is.EqualTo(1));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:10,代碼來源:LuceneSearchTests.cs

示例3: AuthorizedPages_AreDisplayed_WhenSearching_WithoutSpecifyingRoles

        public void AuthorizedPages_AreDisplayed_WhenSearching_WithoutSpecifyingRoles()
        {
            var item = CreateOneItem<PersistableItem1>(2, "Hello world", root);
            item.AuthorizedRoles.Add(new N2.Security.AuthorizedRole(item, "Members"));
            indexer.Update(item);

            var searcher = new LuceneSearcher(accessor, persister);
            var hits = searcher.Search(Query.For("hello"));

            Assert.That(hits.Hits.Count(), Is.EqualTo(1));
        }
開發者ID:arp51,項目名稱:n2cms,代碼行數:11,代碼來源:LuceneSearchTests.cs

示例4: And_Operator_Multiple

        public void And_Operator_Multiple()
        {
            var page = CreateOneItem<PersistableItem1>(2, "Hello world hunger", root);
            var page2 = CreateOneItem<PersistableItem1>(3, "Hello world fulfillment", root);
            indexer.Update(page);
            indexer.Update(page2);

            var searcher = new LuceneSearcher(accessor, persister);
            var hits = searcher.Search(Query.For("hello") & Query.For("world") & Query.For("hunger"));

            Assert.That(hits.Hits.Count(), Is.EqualTo(1));
            Assert.That(hits.Contains(page));
        }
開發者ID:arp51,項目名稱:n2cms,代碼行數:13,代碼來源:LuceneSearchTests.cs

示例5: And

        public void And()
        {
            var page = CreateOneItem<PersistableItem1>(2, "Hello world", root);
            var page2 = CreateOneItem<PersistableItem1>(3, "Hello region", root);
            indexer.Update(page);
            indexer.Update(page2);

            var searcher = new LuceneSearcher(accessor, persister);
            var hits = searcher.Search(Query.For("hello").And(Query.For("world")));

            Assert.That(hits.Hits.Count(), Is.EqualTo(1));
            Assert.That(hits.Contains(page));
        }
開發者ID:arp51,項目名稱:n2cms,代碼行數:13,代碼來源:LuceneSearchTests.cs

示例6: Multithreading

		public void Multithreading()
		{
			var threads = new List<Thread>();
			var exceptions = new List<Exception>();
			bool loop = true;
			var words = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec sagittis mi. Donec pharetra vestibulum facilisis. Sed sodales risus vel nulla vulputate volutpat. Mauris vel arcu in purus porta dapibus. Aliquam erat volutpat. Maecenas suscipit tincidunt purus porttitor auctor. Quisque eget elit at justo facilisis malesuada sit amet sit amet eros. Duis convallis porta congue. Nulla commodo faucibus diam in mollis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec ut nibh eu sapien ornare consectetur.".Split(' ', '.', ',');
			var indexFunction = new ThreadStart(() =>
			{
				Trace.WriteLine("Index start: " + DateTime.Now);
				int counter = 1;
				while (loop)
				{
					var item = CreateOneItem<PersistableItem1>(0, "Item " + counter++, null);
					item["Text"] = words.OrderBy(w => Guid.NewGuid()).Aggregate(new StringBuilder(), (sb, w) => { if (!string.IsNullOrEmpty(w)) sb.Append(w).Append(" "); return sb; }).ToString();
					try
					{
						indexer.Update(item);
						Console.Write('!');
					}
					catch (Exception ex)
					{
						Trace.WriteLine(ex);
						lock (exceptions)
						{
							exceptions.Add(ex);
						}
					}
				}
				Trace.WriteLine("Index stop: " + DateTime.Now);
			});
			var searcher = new LuceneSearcher(accessor, persister);
			int searchCounter = 1;
			var r = new Random();
			var searchFunction = new ThreadStart(() =>
			{
				int searchIndex = searchCounter++;
				Trace.WriteLine(searchIndex + " Search start: " + DateTime.Now);

				while (loop)
				{
					try
					{
						searcher.Search(Query.For(words[r.Next(words.Length)]));
						Console.Write('?');
					}
					catch (Exception ex)
					{
						Trace.WriteLine(ex);
						lock (exceptions)
						{
							exceptions.Add(ex);
						}
					}
				}

				Trace.WriteLine(searchIndex + " Search1 stop: " + DateTime.Now);
			});
			threads.Add(new Thread(indexFunction));
			threads.Add(new Thread(searchFunction));
			threads.Add(new Thread(searchFunction));
			threads.Add(new Thread(searchFunction));

			foreach (var t in threads)
				t.Start();
			Thread.Sleep(500);
			loop = false;
			foreach (var t in threads)
				t.Join();

			exceptions.Count.ShouldBe(0);
		}
開發者ID:navneetccna,項目名稱:n2cms,代碼行數:71,代碼來源:LuceneSearchTests.cs

示例7: Multithreading

        //[TestCase(8, 2, 5000, 1000, 500, .5)]
        //[TestCase(16, 4, 30 * 1000, 10000, 1000, .5)]
        //[TestCase(8, 2, 300 * 1000, 20000, 2000, .5)]
		public void Multithreading(int readerCount, int indexerCount, int workMilliseconds, int dictionaryCount, int indexedWordsCount, double updateFrequency)
		{
			var threads = new List<Thread>();
			var exceptions = new List<Exception>();
			bool loop = true;
			
            var generator = new SCG.General.MarkovNameGenerator(Words.Thousand, 3, 2);
            var words = Enumerable.Range(0, dictionaryCount).Select(i => generator.NextName).ToArray();

            int idCounter = 1;
            int creates = 0;
            int updates = 0;
			var indexFunction = new ThreadStart(() =>
			{
                var r = new Random();
                Trace.WriteLine(Thread.CurrentThread.ManagedThreadId + " Index start: " + DateTime.Now);
				while (loop)
				{
                    bool isUpdate = r.NextDouble() < updateFrequency && idCounter > 2;
                    int id = (isUpdate) ? r.Next(0, idCounter) : Interlocked.Increment(ref idCounter);

					var item = CreateOneItem<PersistableItem1>(id, "Item " + id, null);
					item.StringProperty = Enumerable.Range(0, indexedWordsCount).Select(i => words[r.Next(0, words.Length)]).Aggregate(new StringBuilder(), (sb, w) => sb.Append(w).Append(" ")).ToString();
					try
					{
						indexer.Update(item);
						Console.Write(isUpdate ? 'U' : 'C');
                        if (isUpdate)
                            Interlocked.Increment(ref updates);
                        else
                            Interlocked.Increment(ref creates);
					}
					catch (Exception ex)
					{
						Trace.WriteLine(ex);
						lock (exceptions)
						{
							exceptions.Add(ex);
						}
					}
				}
				Trace.WriteLine(Thread.CurrentThread.ManagedThreadId + " Index stop: " + DateTime.Now);
			});
			var searcher = new LuceneSearcher(accessor, persister);
            int searches = 0;
			var searchFunction = new ThreadStart(() =>
			{
                Trace.WriteLine(Thread.CurrentThread.ManagedThreadId + " Search start: " + DateTime.Now);
                var r = new Random();

				while (loop)
				{
					try
					{
						var result = searcher.Search(Query.For(words[r.Next(words.Length)]));
                        Interlocked.Increment(ref searches);
						Console.Write('?');
					}
					catch (Exception ex)
					{
						Trace.WriteLine(ex);
						lock (exceptions)
						{
							exceptions.Add(ex);
						}
					}
				}

                Trace.WriteLine(Thread.CurrentThread.ManagedThreadId + " Search stop: " + DateTime.Now);
			});
            for (int i = 0; i < indexerCount; i++)
            {
			threads.Add(new Thread(indexFunction));
            }
            for (int i = 0; i < readerCount; i++)
            {
			threads.Add(new Thread(searchFunction));
            }

			foreach (var t in threads)
				t.Start();
			Thread.Sleep(workMilliseconds);
			loop = false;
			foreach (var t in threads)
				t.Join();

            Trace.WriteLine("Creates: " + creates + ", Updates: " + updates + ", Searches: " + searches + " Exceptions: " + exceptions.Count);

            foreach (var ex in exceptions)
                Trace.WriteLine(ex.Message);

			exceptions.Count.ShouldBe(0);
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:96,代碼來源:LuceneSearchTests.cs

示例8: QueryByExpression_ForVisibleProperty

		public void QueryByExpression_ForVisibleProperty()
		{
			indexer.Update(root);

			var searcher = new LuceneSearcher(accessor, persister);
			var query = Query.For<PersistableItem1>();

			query.Contains(pi => pi.Visible, "true");
			var result = searcher.Search(query);

			Assert.That(result.Hits.Single().Content, Is.EqualTo(root));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:12,代碼來源:LuceneSearchTests.cs

示例9: QueryForBelowOfTypeReadableByExceptType

		public void QueryForBelowOfTypeReadableByExceptType()
		{
			indexer.Update(root);
			var part = CreateOneItem<PersistableItem2>(0, "some other page", root);
			indexer.Update(part);

			var searcher = new LuceneSearcher(accessor, persister);
			var query = Query.For("page")
				.OfType(typeof(IPage))
				.Below(root)
				.ReadableBy("Everyone") // superfluous (everyone by default)
				.Except(Query.For<PersistableItem2>());
			
			var result = searcher.Search(query);

			Assert.That(result.Hits.Single().Content, Is.EqualTo(root));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:17,代碼來源:LuceneSearchTests.cs

示例10: NonDetail_IndexableOnlyGetterProperty_IsIndexed

		public void NonDetail_IndexableOnlyGetterProperty_IsIndexed()
		{
			indexer.Update(root);

			var searcher = new LuceneSearcher(accessor, persister);
			var result = searcher.Search(Query.For("ipsum"));

			Assert.That(result.Hits.Single().Content, Is.EqualTo(root));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:9,代碼來源:LuceneSearchTests.cs

示例11: Language_IncludesLanguageRoot

		public void Language_IncludesLanguageRoot()
		{
			var sv = CreateOneItem<PersistableItem2>(2, "Svenska", root);
			sv.LanguageCode = "sv";
			indexer.Update(sv);

			var en = CreateOneItem<PersistableItem2>(3, "Engelska", root);
			en.LanguageCode = "en";
			indexer.Update(en);

			var svitem = CreateOneItem<PersistableItem1>(4, "Hello världen", sv);
			indexer.Update(svitem);

			var enitem = CreateOneItem<PersistableItem1>(5, "Hello world", en);
			indexer.Update(enitem);

			var searcher = new LuceneSearcher(accessor, persister);
			var result = searcher.Search(Query.For("").Language(sv));

			Assert.That(result.Hits.Count(), Is.EqualTo(2));
			Assert.That(result.Contains(sv));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:22,代碼來源:LuceneSearchTests.cs

示例12: TitleBoost

		public void TitleBoost()
		{
			root.StringProperty = "Hello world";
			indexer.Update(root);

			var item = CreateOneItem<PersistableItem1>(2, root.StringProperty, root);
			item.StringProperty = root.Title;
			indexer.Update(item);

			var searcher = new LuceneSearcher(accessor, persister);

			var hits1 = searcher.Search(Query.For("hello"));
			var hits2 = searcher.Search(Query.For("root"));

			Assert.That(hits1.Hits.Select(h => h.Content).First(), Is.EqualTo(item));
			Assert.That(hits2.Hits.Select(h => h.Content).First(), Is.EqualTo(root));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:17,代碼來源:LuceneSearchTests.cs

示例13: IndexableProperty

		public void IndexableProperty()
		{
			var item = CreateOneItem<PersistableItem1>(2, "Hello world", root);
			item.StringProperty = "Hej Världen";
			indexer.Update(item);

			var searcher = new LuceneSearcher(accessor, persister);
			var hits = searcher.Search(Query.For("världen"));

			Assert.That(hits.Hits.Count(), Is.EqualTo(1));
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:11,代碼來源:LuceneSearchTests.cs

示例14: Search

		private System.Collections.Generic.List<ContentItem> Search(params SortFieldData[] sortFields)
		{
			var searcher = new LuceneSearcher(accessor, persister);
			var query = Query.For<PersistableItem1>();
			Array.ForEach(sortFields, sortField => query.OrderBy(sortField.SortField, sortField.SortDescending));

			var hits = searcher.Search(query).Hits.Select(h => h.Content).ToList();
			return hits;
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:9,代碼來源:LuceneSearchTests.cs

示例15: EditableProperty

        public void EditableProperty()
        {
            var item = CreateOneItem<Definitions.PersistableItem1>(2, "Hello world", root);
            item.IntProperty = 444;
            indexer.Update(item);

            var searcher = new LuceneSearcher(accessor, persister);
            var hits = searcher.Search(Query.For("444"));

            Assert.That(hits.Hits.Count(), Is.EqualTo(1));
        }
開發者ID:arp51,項目名稱:n2cms,代碼行數:11,代碼來源:LuceneSearchTests.cs


注:本文中的N2.Persistence.Search.LuceneSearcher.Search方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。