インデックスから最新の10件の結果(日付による順序)を取得しようとすると、古いドキュメントが表示されます。クエリが10個の古いアイテムを取得し、並べ替えているようです。クエリに多くの結果がある場合、この問題が発生します。
これが私のインデックス定義です:
public class Home_ByCategoryTagAndLocation : AbstractIndexCreationTask<Home>
{
public Home_ByCategoryTagAndLocation()
{
Map = home => from n in home
from t in n.Source.CategoryTag
from c in n.Locations
select new { CategoryTag = t, n.DatePublished, _ = SpatialIndex.Generate(c.Latitude, c.Longitude) };
}
}
このコードを使用してインデックスを呼び出します。
public static List<Home> GetLatestHomeNear(IDocumentStore store, CityLocation location, int maxResults = 15)
{
if (location != null)
{
using (IDocumentSession session = store.OpenSession())
{
return session.Advanced.LuceneQuery<Home>("Home/ByCategoryTagAndLocation")
.WithinRadiusOf(radius: location.DefaultRadius, latitude: location.Latitude, longitude: location.Longitude)
.OrderByDescending(n => n.DatePublished)
.Take(maxResults)
.ToList();
}
}
return new List<Home>();
}