本文整理汇总了C#中N2.Persistence.Search.LuceneSearcher类的典型用法代码示例。如果您正苦于以下问题:C# LuceneSearcher类的具体用法?C# LuceneSearcher怎么用?C# LuceneSearcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LuceneSearcher类属于N2.Persistence.Search命名空间,在下文中一共展示了LuceneSearcher类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: PagesCanBeFound_ByObjectType
public void PagesCanBeFound_ByObjectType()
{
var page = CreateOneItem<PersistableItem1>(2, "Hello world", root);
var part = CreateOneItem<PersistablePart1>(3, "Hello region", root);
indexer.Update(page);
indexer.Update(part);
var searcher = new LuceneSearcher(accessor, persister);
var hits = searcher.Search(Query.For("hello").OfType(typeof(object)));
Assert.That(hits.Hits.Count(), Is.EqualTo(2));
Assert.That(hits.Hits.Select(h => h.Content).Contains(part));
Assert.That(hits.Hits.Select(h => h.Content).Contains(page));
}
开发者ID:davethieben,项目名称:n2cms,代码行数:14,代码来源:LuceneSearchTests.cs
示例17: Except_Operator_Multiple
public void Except_Operator_Multiple()
{
var page = CreateOneItem<PersistableItem1>(2, "Hello world", root);
var part = CreateOneItem<PersistablePart1>(3, "Hello world", root);
var part2 = CreateOneItem<PersistablePart1>(4, "Hello region", root);
indexer.Update(page);
indexer.Update(part);
indexer.Update(part2);
var searcher = new LuceneSearcher(accessor, persister);
var hits = searcher.Search(Query.For("hello") - Query.For(typeof(IPage)) - Query.For("region"));
Assert.That(hits.Hits.Count(), Is.EqualTo(1));
Assert.That(hits.Hits.Select(h => h.Content).Contains(part));
}
开发者ID:davethieben,项目名称:n2cms,代码行数:15,代码来源:LuceneSearchTests.cs
示例18: 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
示例19: Or_Operator_Multiple
public void Or_Operator_Multiple()
{
var page = CreateOneItem<PersistableItem1>(2, "Hello world", root);
var page2 = CreateOneItem<PersistableItem1>(3, "Hello region", root);
var page3 = CreateOneItem<PersistableItem1>(4, "Hello universe", root);
indexer.Update(page);
indexer.Update(page2);
indexer.Update(page3);
var searcher = new LuceneSearcher(accessor, persister);
var hits = searcher.Search(Query.For("region") | Query.For("world") | Query.For("universe"));
Assert.That(hits.Hits.Count(), Is.EqualTo(3));
Assert.That(hits.Contains(page));
Assert.That(hits.Contains(page2));
Assert.That(hits.Contains(page3));
}
开发者ID:davethieben,项目名称:n2cms,代码行数:17,代码来源:LuceneSearchTests.cs
示例20: 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
注:本文中的N2.Persistence.Search.LuceneSearcher类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论