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


C# Search.LuceneSearcher類代碼示例

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


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

示例1: 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

示例2: 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

示例3: Take

		public void Take()
		{
			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));

			Assert.That(hits1.Count, Is.EqualTo(1));
		}
開發者ID:navneetccna,項目名稱: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: SetUp

		public override void SetUp()
		{
			base.SetUp();

			var definitions = TestSupport.SetupDefinitions(typeof(PersistableItem1), typeof(PersistableItem2), typeof(PersistablePart1));

			accessor = new LuceneAccesor(new ThreadContext(), new DatabaseSection());
			indexer = new LuceneIndexer(accessor, new TextExtractor(new IndexableDefinitionExtractor(definitions)));
			searcher = new LuceneSearcher(accessor, persister);
			worker = new AsyncWorker();
			asyncIndexer = new AsyncIndexer(indexer, persister, worker, Rhino.Mocks.MockRepository.GenerateStub<IErrorNotifier>(), new DatabaseSection());
			tracker = new ContentChangeTracker(asyncIndexer, persister, new N2.Plugin.ConnectionMonitor(), new DatabaseSection());

			accessor.LockTimeout = 1L;
			indexer.Clear();
			root = CreateOneItem<PersistableItem1>(1, "The Root Page", null);
		}
開發者ID:rohancragg,項目名稱:n2cms,代碼行數:17,代碼來源:AsyncIndexerTests.cs

示例7: 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

示例8: Tags_are_searchable_by_property

		public void Tags_are_searchable_by_property()
		{
			var page = CreateOneItem<PersistableItem1>(1, "page", null);
			page.Tags = new[] { "Hello", "World" };
			indexer.Update(page);

			var page2 = CreateOneItem<PersistableItem1>(2, "page2", null);
			page2.Tags = new[] { "Howdy", "Universe" };
			indexer.Update(page2);

			var searcher = new LuceneSearcher(accessor, persister);
			var result = searcher.Search(Query.For<PersistableItem1>().Property("Tags", "Hello"));

			result.Single().ShouldBe(page);
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:15,代碼來源:LuceneSearchTests.cs

示例9: OrOr_And

		public void OrOr_And()
		{
			indexer.Update(root);
			var first = CreateOneItem<PersistableItem2>(0, "some other page", root);
			indexer.Update(first);
			var second = CreateOneItem<PersistableItem2>(0, "some other stuff", root);
			indexer.Update(second);

			var searcher = new LuceneSearcher(accessor, persister);
			// TODO: support this
			//var query = (Query.For("some") | Query.For("other"))
			//    .Below(first);
			var query = new Query { Ancestor = first, Intersection = Query.For("some") | Query.For("other") };

			var result = searcher.Search(query);

			result.Hits.Count().ShouldBe(1);
			result.Hits.Any(h => h.Content == second).ShouldBe(false);
		}
開發者ID:davethieben,項目名稱:n2cms,代碼行數:19,代碼來源:LuceneSearchTests.cs

示例10: QueryByExpression_ForDetail

        public void QueryByExpression_ForDetail()
        {
            root.StringProperty = "This is a very special string";
            indexer.Update(root);

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

            query.Contains(pi => pi.StringProperty, "special");
            var result = searcher.Search(query);

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

示例11: 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

示例12: 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

示例13: Total_IsNumberOfItemsInIndex

		public void Total_IsNumberOfItemsInIndex()
		{
			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 hits = searcher.Search(Query.For("hello").Take(2));

			Assert.That(hits.Total, Is.EqualTo(3));
		}
開發者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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。