RavenDB:如何将查询转换为Lucene查询? [英] RavenDB: how to transform a query into a lucene query?

查看:93
本文介绍了RavenDB:如何将查询转换为Lucene查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

public class Continent
{
    public string Name { get; set; }
    public List<Country> Countries{ get; set; }
}

public class Countries
{
   public string Name { get; set; }
   public List<Province> Provinces{ get; set; }
}

public class Province
{
    public string Name { get; set; }
    public List<Province> Cities { get; set; }
}

public class City
{
    public string Name { get; set; }
    public string Address   { get; set; }
}

我想将以下查询转换为lucene查询(例如,Where,Any),以便我得到Aloma和Hemane都在同一个省(而不是不同省)内的大洲,并具有各自的地址123和435:

I want to transform the following query into a lucene query(e.g., Where, Any), so that I get the continents where both Aloma and Hemane are within the same province (and not in distinct provinces) with the respective addresses 123 and 435:

 var queryResults = from continent in session
                              .Advanced.DocumentQuery<Continent>()
                               from country in continent.Countries
                               from prov in country.Provinces
                               let cities_ = prov.Cities
                               let fi = cities_.Where(fp => fp.Name == "Aloma" && fp.Address == "123").FirstOrDefault()
                               let fj = cities_.Where(fk => fk.Name == "Hemane" && fk.Address == "435").FirstOrDefault()
                               where fi != null && fj != null
                               select continent;

我最初尝试了以下方法,但是当Aloma和Hemane在同一个省(我想要的),但是当Aloma和Hemane在不同的省(我不想的)时,它返回结果:

I originally tried the following, but it returns results when Aloma and Hemane are in the same province (what I want), but also when Aloma and Hemane are in distinct provinces (what I don't want):

var queryResultsLucene = session.Advanced.DocumentQuery<Continent>()
                                 .Where("Countries,Provinces,Cities,Name:Aloma")
                                 .AndAlso()
                                 .Where("Countries,Provinces,Cities,Address:123")
                                 .Intersect()
                                  .Where("Countries,Provinces,Cities,Name:Hemane")
                                 .AndAlso()
                                 .Where("Countries,Provinces,Cities,Address:435")
                                 .OfType<Topic>()
                                 .ToList();

你能帮我吗? 预先感谢

Can you please help me? Thanks in advance

推荐答案

您可以使用以下查询:

var queryResults = session.Advanced.DocumentQuery<Continent>()
                    .OpenSubClause()
                        .WhereEquals("Countries,Provinces,Cities.Name", "Aloma")
                        .AndAlso()
                        .WhereEquals("Countries,Provinces,Cities.Address", "123")
                    .CloseSubClause()
                    .AndAlso()
                    .OpenSubClause()
                        .WhereEquals("Countries,Provinces,Cities.Name", "Hemane")
                        .AndAlso()
                        .WhereEquals("Countries,Provinces,Cities.Address", "Hemane")
                    .CloseSubClause()
                    .ToList();

这篇关于RavenDB:如何将查询转换为Lucene查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆