RavenDB麻烦添加到空间交叉查询

时间:2015-02-04 21:16:20

标签: ravendb spatial

我有一个对象合作伙伴,如下所示:

public class Partner
{
    public double Latitude { get; set; }

    public double Longitude { get; set; }

    public string ServiceKeyIds { get; set; }

    public double WorkingRadius { get; set; }

    public float Rating { get; set; }
}

然后我有一个投影 LocalPartner ,如下所示:

public class LocalPartner : Partner
{
    public string WorkingRadiusShape { get; set; }
}

我的索引 PartnersByLocation 如下所示:

public class PartnersByLocation : AbstractIndexCreationTask<Partner,LocalPartner>
{
    public PartnersByLocation()
    {
        Map = partners => from doc in partners
                            where doc.ServiceKeyIds != null
                            select new
                            {
                                doc.ServiceKeyIds,
                                WorkingRadiusShape = string.Format("Circle({0},{1}, d={2})", doc.Latitude, doc.Longitude, doc.WorkingRadius)
                            }.Boost((float)doc.Rating);

        Spatial(x => x.WorkingRadiusShape, options => options.Geography.Default());
        Index(x => x.ServiceKeyIds, FieldIndexing.NotAnalyzed);
    }
}

我尝试按如下方式查询索引:

public LocalPartnerList GetNearbyPartners(double lat, double lng, string serviceIds, double rad = 25, int page = 0, int resultsPerPage = 10)
    {
        RavenQueryStatistics stats;

        var point = string.Format(CultureInfo.InvariantCulture, "POINT ({0} {1})", lng, lat);
        var query = session.Advanced.LuceneQuery<LocalPartner, PartnersByLocation>().Statistics(out stats).Spatial(x => x.WorkingRadiusShape, c => c.Intersects(point));

        if (serviceIds != null && serviceIds.Any())
        {
            query = query.AndAlso().WhereIn("ServiceKeyIds", serviceIds.SafeSplit());
        }

        var raw = query.ToString();

        query = query.Skip(page * resultsPerPage).Take(resultsPerPage);

        var result = new LocalPartnerList();
        result.LocalPartners = query.SelectFields<LocalPartner>().ToList();
        result.Results = stats.TotalResults;
        result.Page = page;
        result.NumberPages = (int)Math.Ceiling((double)result.Results / (double)resultsPerPage);
        result.Radius = (int)rad;
        return result;
    }

如果我调用方法并且serciceIds为null,则此查询有效。它返回预期的结果,但是一旦我应用.AndAlso()。WhereIn()子句,查询就会返回一个空集。

我确信有匹配的记录。我应该注意,Partner的ServiceKeyIds属性包含一串逗号分隔的字符串,传递给该方法的serviceId是相同的,而SafeSplit()是一个返回字符串数组的扩展方法。

0 个答案:

没有答案