私の前の質問の隣に。今すぐ lucene クエリ検索を実行したいです。
ここに私のモデルがあります:
public class User
{
public string Id { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
public class Book
{
public string Id { get; set; }
public string Title { get; set; }
}
public class BookFavorite
{
public string Id { get; set; }
public string UserId { get; set; }
public string BookId { get; set; }
}
だから、本のフィールド「タイトル」で検索したいのですが、お気に入りにある本だけです。そのため、Book と BookFavorite を結合し、Title フィールドにインデックスを付ける必要があります。
MultiMap Index を試してみましたが、うまく動作しませんでした。
助けはありますか?ありがとう。
編集: MultiMap インデックス
public class BookFavoriteSearchIndex : AbstractMultiMapIndexCreationTask<BookFavoriteSearchIndex.ReduceResult>
{
public class ReduceResult
{
public string BookId { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Abstract { get; set; }
public string Tag { get; set; }
}
public BookFavoriteSearchIndex()
{
AddMap<Book>(books => from book in books
from tag in book.Tags
select new
{
BookId = book.Id,
Title = book.Title,
Description = book.Description,
Abstract = book.Abstract,
Tag = tag
});
AddMap<BookFavorite>(bfs => from bf in bfs
select new
{
BookId = bf.BookId,
Title = (string)null,
Description = (string)null,
Abstract = (string)null,
Tag = (string)null
});
Reduce = results => from result in results
group result by result.BookId
into g
select new
{
BookId = g.Key,
Title = g.Select(x => x.Title).FirstOrDefault(x => x != null),
Description = g.Select(x => x.Description).FirstOrDefault(x => x != null),
Abstract = g.Select(x => x.Abstract).FirstOrDefault(x => x != null),
Tag = g.Select(x => x.Tag).FirstOrDefault(x => x != null),
};
}
}