Is Boosting whole documents supported in an AbstractMultiMapIndexCreationTask<T> that utilizes the Reduce feature?

家住魔仙堡 提交于 2019-12-11 15:24:22

问题


I'm trying to boost documents based on how recent they were posted as discussed in this answer.

The following index definition works fine creating an index that is populated with Article and Recipe entities.

public class TestIndex : AbstractMultiMapIndexCreationTask<Result>
{
    public TestIndex()
    {
        AddMap<Article>(docs => from doc in docs
                                where !doc.IsDeleted
                                select new Result
                                {
                                    Id            = doc.Id,
                                    Title         = doc.Title,
                                    DatePublished = doc.DatePublished
                                }.Boost(doc.DatePublished.Ticks / 1000000f));

        AddMap<Recipe>(docs => from doc in docs
                               where !doc.IsDeleted
                               select new Result
                               {
                                   Id            = doc.Id,
                                   Title         = doc.Title,
                                   DatePublished = doc.DatePublished
                               }.Boost(doc.DatePublished.Ticks / 100000f));
    }

    public override string IndexName
    {
        get { return "Tests/WithBoost"; }
    }
}

When I try to add a Reduce to store the documents as a Result item the index ceases to generate any results.

public class TestIndex : AbstractMultiMapIndexCreationTask<Result>
{
    public TestIndex()
    {
        AddMap<Article>(docs => from doc in docs
                                where !doc.IsDeleted
                                select new Result
                                {
                                    Id            = doc.Id,
                                    Title         = doc.Title,
                                    DatePublished = doc.DatePublished
                                }.Boost(doc.DatePublished.Ticks / 100000f));

        AddMap<Recipe>(docs => from doc in docs
                               where !doc.IsDeleted
                               select new Result
                               {
                                   Id            = doc.Id,
                                   Title         = doc.Title,
                                   DatePublished = doc.DatePublished
                               }.Boost(doc.DatePublished.Ticks / 100000f));

        Reduce = docs => from doc in docs
                         group doc by doc.Id into g
                         select new Result
                         {
                             Id            = g.First().Id,
                             Title         = g.First().Title,
                             DatePublished = g.First().DatePublished
                         };
    }

    public override string IndexName
    {
        get { return "Tests/WithBoost"; }
    }
}

Is boosting documents supported when using the Reduce feature of AbstractMultiMapIndexCreationTask<T>?

A thought I'm having is that Boost() returns a BoostedValue, so is the collection being passed to the Reduce expression actually IEnumerable<BoostedValue> instead of IEnumerable<Result>, and therefore the Reduce expression cannot be compiled against the input?


回答1:


(This answer carried over from the comments in the original post)

If you just want to sort by date published, don't use boost - use .OrderByDescending(x=> x.DatePublished).

If you're just wanting to know how to query on a combined multimap result, you can do that easily like this:

var results = session.Query<Result, TestIndex>()
                     .Search(x=> x.Title, "whatever")
                     .As<object>()
                     .ToList();

var articles = results.OfType<Article>();
var recipies = results.OfType<Recipe>();

I'm assuming you want to search, since you are boosting. You should also be marking the searchable fields as analyzed, as documented here.

I'm also assuming you want articles and recipes separated into separate lists. If you don't, then you can just use the object list directly. Or if you have some base class or interface that they both use, then you can use that instead of object, as in .As<IWhatever>().



来源:https://stackoverflow.com/questions/14100518/is-boosting-whole-documents-supported-in-an-abstractmultimapindexcreationtaskt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!