From 3bd6acbb5d950a154e4c2dc9b957331d9605bb4c Mon Sep 17 00:00:00 2001 From: Ayende Rahien Date: Fri, 11 May 2012 11:07:33 +0100 Subject: [PATCH] Fixing listener signature --- ...keThis_should_support_MapReduce_indexes.cs | 276 +++++++++--------- .../UniqueConstraintsStoreListener.cs | 2 +- 2 files changed, 140 insertions(+), 138 deletions(-) diff --git a/Bundles/Raven.Bundles.Tests/MoreLikeThis/MoreLikeThis_should_support_MapReduce_indexes.cs b/Bundles/Raven.Bundles.Tests/MoreLikeThis/MoreLikeThis_should_support_MapReduce_indexes.cs index 67113b80702a..bb6799b385bc 100644 --- a/Bundles/Raven.Bundles.Tests/MoreLikeThis/MoreLikeThis_should_support_MapReduce_indexes.cs +++ b/Bundles/Raven.Bundles.Tests/MoreLikeThis/MoreLikeThis_should_support_MapReduce_indexes.cs @@ -17,147 +17,149 @@ namespace Raven.Bundles.Tests.MoreLikeThis { - public class MoreLikeThis_should_support_MapReduce_indexes : TestWithInMemoryDatabase - { - public string JavascriptBookId; - public string PhpBookId; - public string EclipseBookId; - - public MoreLikeThis_should_support_MapReduce_indexes() : - base(config => - { - config.Catalog.Catalogs.Add(new AssemblyCatalog(typeof(MoreLikeThisResponder).Assembly)); - }) - { - using(var session = documentStore.OpenSession()) - { - var javascriptBook = new Book() { Title = "Javascript: The Good Parts" }; - var phpBook = new Book() { Title = "PHP: The Good Parts" }; - var eclipseBook = new Book() { Title = "Zend Studio for Eclipse Developer's Guide" }; - - session.Store(javascriptBook); - session.Store(phpBook); - session.Store(eclipseBook); - session.SaveChanges(); - - JavascriptBookId = javascriptBook.Id; - PhpBookId = phpBook.Id; - EclipseBookId = eclipseBook.Id; - - session.Store(new Author() { BookId = javascriptBook.Id, Name = "Douglas Crockford" }); - session.Store(new Author() { BookId = phpBook.Id, Name = "Peter MacIntyre" }); - session.Store(new Author() { BookId = eclipseBook.Id, Name = "Peter MacIntyre" }); - session.Store(new Book() { Title = "Unrelated" }); - session.SaveChanges(); - - new MapReduceIndex().Execute(documentStore); - - var results = session.Query().Customize(x => x.WaitForNonStaleResults()).Count(); - - Assert.Equal(4, results); - - Assert.Empty(documentStore.DatabaseCommands.GetStatistics().Errors); - } - } - - [Fact] - public void Can_find_book_with_similar_name() - { - using (var session = documentStore.OpenSession()) - { - var list = session.Advanced.MoreLikeThis( - new MoreLikeThisQueryParameters - { - MapGroupFields = new NameValueCollection() + public class MoreLikeThis_should_support_MapReduce_indexes : TestWithInMemoryDatabase + { + public string JavascriptBookId; + public string PhpBookId; + public string EclipseBookId; + + public MoreLikeThis_should_support_MapReduce_indexes() : + base(config => + { + config.Catalog.Catalogs.Add(new AssemblyCatalog(typeof(MoreLikeThisResponder).Assembly)); + }) + { + using (var session = documentStore.OpenSession()) + { + var javascriptBook = new Book() { Title = "Javascript: The Good Parts" }; + var phpBook = new Book() { Title = "PHP: The Good Parts" }; + var eclipseBook = new Book() { Title = "Zend Studio for Eclipse Developer's Guide" }; + + session.Store(javascriptBook); + session.Store(phpBook); + session.Store(eclipseBook); + session.SaveChanges(); + + JavascriptBookId = javascriptBook.Id; + PhpBookId = phpBook.Id; + EclipseBookId = eclipseBook.Id; + + session.Store(new Author() { BookId = javascriptBook.Id, Name = "Douglas Crockford" }); + session.Store(new Author() { BookId = phpBook.Id, Name = "Peter MacIntyre" }); + session.Store(new Author() { BookId = eclipseBook.Id, Name = "Peter MacIntyre" }); + session.Store(new Book() { Title = "Unrelated" }); + session.SaveChanges(); + + new MapReduceIndex().Execute(documentStore); + + var results = session.Query().Customize(x => x.WaitForNonStaleResults()).Count(); + + Assert.Equal(4, results); + + Assert.Empty(documentStore.DatabaseCommands.GetStatistics().Errors); + } + } + + [Fact] + public void Can_find_book_with_similar_name() + { + using (var session = documentStore.OpenSession()) + { + var list = session.Advanced.MoreLikeThis( + new MoreLikeThisQueryParameters + { + MapGroupFields = new NameValueCollection() { {"BookId", JavascriptBookId} }, - MinimumTermFrequency = 1, - MinimumDocumentFrequency = 1 - }); - - Assert.Equal(1, list.Count()); - Assert.Contains("PHP: The Good Parts", list.Single().Text); - } - } - - - [Fact] - public void Can_find_book_with_similar_author() - { - using (var session = documentStore.OpenSession()) - { - var list = session.Advanced.MoreLikeThis( - new MoreLikeThisQueryParameters - { - MapGroupFields = new NameValueCollection() + MinimumTermFrequency = 1, + MinimumDocumentFrequency = 1 + }); + + Assert.Equal(1, list.Count()); + Assert.Contains("PHP: The Good Parts", list.Single().Text); + } + } + + + [Fact] + public void Can_find_book_with_similar_author() + { + using (var session = documentStore.OpenSession()) + { + var list = session.Advanced.MoreLikeThis( + new MoreLikeThisQueryParameters + { + MapGroupFields = new NameValueCollection() { {"BookId", EclipseBookId} }, - MinimumTermFrequency = 1, - MinimumDocumentFrequency = 1 - }); - - Assert.Equal(1, list.Count()); - Assert.Contains("PHP: The Good Parts", list.Single().Text); - } - } - - public class Book - { - public string Id { get; set; } - public string Title; - } - - public class Author - { - public string BookId; - public string Name; - } - - public class IndexDocument - { - public string BookId; - public string Text; - } - - - public class MapReduceIndex : AbstractMultiMapIndexCreationTask - { - public override string IndexName - { - get - { - return "MapReduceIndex"; - } - } - - public MapReduceIndex() - { - this.AddMap(things => from thing in things select new IndexDocument() - { - BookId = thing.Id, - Text = thing.Title - }); - - this.AddMap(opinions => from opinion in opinions select new IndexDocument() - { - BookId = opinion.BookId, - Text = opinion.Name - }); - - this.Reduce = documents => from doc in documents - group doc by doc.BookId into g - select new IndexDocument() - { - BookId = g.Key, - Text = string.Join(" ", g.Select(d => d.Text)) - }; - - - Index(x => x.Text, FieldIndexing.Analyzed); - Index(x => x.BookId, FieldIndexing.NotAnalyzed); - } - } - } + MinimumTermFrequency = 1, + MinimumDocumentFrequency = 1 + }); + + Assert.Equal(1, list.Count()); + Assert.Contains("PHP: The Good Parts", list.Single().Text); + } + } + + public class Book + { + public string Id { get; set; } + public string Title; + } + + public class Author + { + public string BookId; + public string Name; + } + + public class IndexDocument + { + public string BookId; + public string Text; + } + + + public class MapReduceIndex : AbstractMultiMapIndexCreationTask + { + public override string IndexName + { + get + { + return "MapReduceIndex"; + } + } + + public MapReduceIndex() + { + this.AddMap(things => from thing in things + select new IndexDocument() + { + BookId = thing.Id, + Text = thing.Title + }); + + this.AddMap(opinions => from opinion in opinions + select new IndexDocument() + { + BookId = opinion.BookId, + Text = opinion.Name + }); + + this.Reduce = documents => from doc in documents + group doc by doc.BookId into g + select new IndexDocument() + { + BookId = g.Key, + Text = string.Join(" ", g.Select(d => d.Text)) + }; + + + Index(x => x.Text, FieldIndexing.Analyzed); + Index(x => x.BookId, FieldIndexing.NotAnalyzed); + } + } + } } diff --git a/Bundles/Raven.Client.UniqueConstraints/UniqueConstraintsStoreListener.cs b/Bundles/Raven.Client.UniqueConstraints/UniqueConstraintsStoreListener.cs index 95a79401611f..d834f38ee068 100644 --- a/Bundles/Raven.Client.UniqueConstraints/UniqueConstraintsStoreListener.cs +++ b/Bundles/Raven.Client.UniqueConstraints/UniqueConstraintsStoreListener.cs @@ -10,7 +10,7 @@ public class UniqueConstraintsStoreListener : IDocumentStoreListener { - public bool BeforeStore(string key, object entityInstance, RavenJObject metadata) + public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original) { if (metadata[Constants.EnsureUniqueConstraints] != null) {