public class Projects_Search : AbstractIndexCreationTask<Project>
{
public Projects_Search()
{
Map = projects => from p in projects
let portfolio = LoadDocument<Portfolio>(p.SiteId + "/portfolio")
let category = LoadDocument<PortfolioCategory>(p.CategoryId)
select new
{
SiteId = p.SiteId,
Slug = p.Slug,
Tags_Slugs = p.Tags.Select(t => t.Slug),
Deleted = p.Deleted,
CategoryId = p.CategoryId,
CategorySlug = category.Slug,
Published = p.Published,
Terms = new object[]
{
p.Title,
p.Summary,
category.Title,
p.Tags.Select(t => t.ToString()),
p.Content
},
PortfolioIndex = portfolio.Projects.IndexOf(p.Id)
};
Index("Terms", Raven.Abstractions.Indexing.FieldIndexing.Analyzed);
}
}
--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
using NUnit.Framework;using Raven.Client.Indexes;using Raven.Tests.Helpers;using System.Collections.Generic;using System.Linq;
namespace RavenTests{ [TestFixture] public class IndexOfTest : RavenTestBase { [Test] public void Can_use_index_of() { using (var store = NewDocumentStore()) { new ProjectsIndex().Execute(store); using (var session = store.OpenSession()) { var portfolio = new Portfolio { Id = "sites/1/portfolio" }; var p1 = new Project { Title = "Project 1", SiteId = "sites/1" }; var p2 = new Project { Title = "Project 2", SiteId = "sites/1" };
session.Store(p1); session.Store(p2); portfolio.Projects.AddRange(new[] { p2.Id, p1.Id }); session.Store(portfolio);
session.SaveChanges(); }
WaitForIndexing(store);
using (var session = store.OpenSession()) { var results = session.Advanced.LuceneQuery<Project, ProjectsIndex>() .OrderBy("PortfolioIndex") .ToList(); Assert.AreEqual("Project 2", results.First().Title); } } } }
public class Project { public string Id { get; set; } public string SiteId { get; set; } public string Title { get; set; } }
public class Portfolio { public string Id {get;set; } public List<string> Projects { get; set; } public Portfolio() { Projects = new List<string>(); } }
public class ProjectsIndex : AbstractIndexCreationTask<Project> { public ProjectsIndex()
{ Map = projects => from p in projects let portfolio = LoadDocument<Portfolio>(p.SiteId + "/portfolio")
select new { Id = p.Id, Title = p.Title, SiteId = p.SiteId, PortfolioIndex = portfolio.Projects.IndexOf(p.Id) }; } }}
public class ProjectsIndex : AbstractIndexCreationTask<Project> { public ProjectsIndex() {
Map = projects => from p in projects let portfolio = LoadDocument<Portfolio>(p.SiteId + "/portfolio")
let ids = portfolio.Projects.ToList()
select new { Id = p.Id, Title = p.Title, SiteId = p.SiteId,
PortfolioIndex = ids.IndexOf(p.Id) }; } }
In our scenario projects will never be null but can see how this could be an issue.
You received this message because you are subscribed to a topic in the Google Groups "ravendb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/6HhKcTeZo5Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.
Thanks, good to know. Will look out for it in the next release.
You received this message because you are subscribed to a topic in the Google Groups "ravendb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/6HhKcTeZo5Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.