Raven-Studio Index正在向C#LINQ Query返回不同的结果 [英] Raven-Studio Index is returning different results to C# LINQ Query
问题描述
我是从的开始乌鸦2.x的和我发现,乌鸦工作室没有正确的过滤。
我有城市的表在我的数据库,存储其人口,位置等等。我已经在代码中添加一个索引,使用这样的:
<预类=郎-C#prettyprint-覆盖>
公开类Cities_ByPopulation:AbstractIndexCreationTask<城市>
{
公共Cities_ByPopulation()
{
this.Map =城市=>从市城市
选择新{人口= city.Population};
//生成,因为这在RDBMS
// docs.Cities.Select(市=>新建{
//人口= city.Population
/ /})
}
}
和使用<$ C对其进行注册。$ C> IndexCreation.CreateIndex(typeof运算(Cities_ByPopulation).Assembly,文档库)代码
问题1 - 乌鸦Studio未如预期过滤
现在该指数被添加到RavenDB,和我乌鸦运行过滤器人口[长]
字段工作室,200,000和500,000之间的过滤。
正如你所看到的,其拉回值完全超出了范围。我也试图与人口:[Lx200000 TO Lx500000]
但没有结果出现
要验证这一点我。创建一个动态指数,但有同样的问题:
问题2 - LINQ完全不按预期过滤
除了这个,我发现,即使原始LINQ查询,没有数据都回来了!
// RavenStore存储单身,
//这样我就可以使用跨控制台应用程序分享这一解决方案
(VAR店= RavenStore.GetDocumentStore())
$ { b $ b IndexCreation.CreateIndexes(typeof运算(Cities_ByPopulation).Assembly,存储);
常量长MinRange = 200000;
常量长MaxRange = 300000;
Debug.Assert的(MinRange< MaxRange,范围需要交换的圆!);
//使用索引
使用Get城市(VAR会话= store.OpenSession())
{
变种城市=
session.Query<市>(城市/ ByPopulation)
.Customize(X => x.WaitForNonStaleResults())
。凡(X => x.Population> MinRange和放大器;&安培; x.Population < MaxRange);
Console.WriteLine(人口范围内正常的城市数量:{0},cities.Count());
}
//使用Get从原材料查询
城市(VAR会话= store.OpenSession())
{
VAR城市= session.Query< ;市>(),其中(X => x.Population> MinRange和放大器;&安培; x.Population< MaxRange)。
Console.WriteLine(人口范围内正常的城市数量:{0},cities.Count());
}
//输出:
//人口范围内正常的城市数量:0
//人口范围内正常的城市数量:0
}
这个查询的记录如下:
请求#275:GET - 1毫秒 - <系统> - 200 - /文档/掠夺/数据库/世界
请求#276:HEAD - 0毫秒 - 世界 - 200 - /指数/城市/ ByPopulation
请求#277:PUT - 2毫秒 - 世界 - 201 - /指数/城市/ ByPopulation
请求#278:GET - 0毫秒 - 世界 - 404 - /文档/掠夺/复制/目的地
请求#279:GET - 6毫秒 - 世界 - 200 - /指数/城市/ ByPopulation&安培;查询= Population_Range%3A%7BLx200000%20TO%20Lx300000%7D和放大器;的pageSize = 0&安培; operationHeadersHash = 1690003523
查询:Population_Range:{Lx200000 TO Lx300000}
时间:6毫秒
指数:城市/ ByPopulation
结果:0返回了0共有。
请求#280:GET - 7毫秒 - 世界 - 200 - /索引/动态/城市和放大器;查询= Population_Range%3A%7BLx200000%20TO%20Lx300000%7D和放大器;的pageSize = 0&安培; operationHeadersHash = 1690003523
查询:Population_Range:{Lx200000 TO Lx300000}
时间:6毫秒
指数:城市/ ByPopulation
结果:0返回了0共有。
一些额外的信息,可以帮助排除故障。
- 中的数据是通过CSV进口商进口的。
- 没有对象已经从存储的一个.NET应用程序,只读。
这可能意味着该模式不同步,或DB是不能确定的数据类型然而,作为元数据是 {}
下面是生成的JSON从文档:
[城市/ 1989]
{
名:亚琛
COUNTRYCODE:D,
省:北威州,
人口:247113,
CountryId:国家/ 1009
}
和C#类:
<预类=郎-C#prettyprint-覆盖>
公共类城市
{
公共字符串ID {搞定;组; }
公共字符串名称{;组; }
公共字符串COUNTRYCODE {搞定;组; }
众长人口{搞定;组; }
公共字符串省{搞定;组; }
公共字符串CountryId {搞定;组; }
}
}
另一个更新
我手工修补与
收集这个[' @metadata'] ['乌鸦-CLR类型'] =Domain.City,域
但这并没有帮助串行两种。
您必须告诉乌鸦,人口是多少,因为所有的值存储为文本。
所以在你的指数构造函数写类似
排序(X => x.Population,SortOptions.Long );
I am learning RavenDB (Build 2851, Version 2.5.0 / 6dce79a) from Beginning Raven 2.x and am finding that the Raven-Studio is not filtering correctly.
I have a table of cities in my database, storing their populations, locations etc. I have added an index in the code, using this:
public class Cities_ByPopulation : AbstractIndexCreationTask<City>
{
public Cities_ByPopulation()
{
this.Map = cities => from city in cities
select new { Population = city.Population };
// Generates as this in the RDBMS
// docs.Cities.Select(city => new {
// Population = city.Population
// })
}
}
And registering it with the IndexCreation.CreateIndex(typeof(Cities_ByPopulation).Assembly, documentStore)
code.
Problem 1 - Raven Studio is not filtering as expected
Now the index is added to RavenDB, and I run a filter the Population [long]
field on the Raven Studio, filtering between 200'000 and 500'000.
As you can see, its pulling back values completely out of the range. I have also tried with Population: [Lx200000 TO Lx500000]
but then no results appear.
To verify this I created a dynamic index, but have the same problem:
Problem 2 - LINQ is not filtering at all as expected
In addition to this, I'm finding that even with a raw LINQ query, no data is returned at all!
// RavenStore stores a singleton,
// so I can share across console apps in this solution
using (var store = RavenStore.GetDocumentStore())
{
IndexCreation.CreateIndexes(typeof(Cities_ByPopulation).Assembly, store);
const long MinRange = 200000;
const long MaxRange = 300000;
Debug.Assert(MinRange < MaxRange, "Ranges need swapping round!");
// Get cities using the index
using (var session = store.OpenSession())
{
var cities =
session.Query<City>("Cities/ByPopulation")
.Customize(x => x.WaitForNonStaleResults())
.Where(x => x.Population > MinRange && x.Population < MaxRange);
Console.WriteLine("Number of normal cities within population range: {0}", cities.Count());
}
// Get cities from raw query
using (var session = store.OpenSession())
{
var cities = session.Query<City>().Where(x => x.Population > MinRange && x.Population < MaxRange);
Console.WriteLine("Number of normal cities within population range: {0}", cities.Count());
}
// Output :
// Number of normal cities within population range: 0
// Number of normal cities within population range: 0
}
The logging for this query is as follows
Request # 275: GET - 1 ms - <system> - 200 - /docs/Raven/Databases/World
Request # 276: HEAD - 0 ms - World - 200 - /indexes/Cities/ByPopulation
Request # 277: PUT - 2 ms - World - 201 - /indexes/Cities/ByPopulation
Request # 278: GET - 0 ms - World - 404 - /docs/Raven/Replication/Destinations
Request # 279: GET - 6 ms - World - 200 - /indexes/Cities/ByPopulation?&query=Population_Range%3A%7BLx200000%20TO%20Lx300000%7D&pageSize=0&operationHeadersHash=1690003523
Query: Population_Range:{Lx200000 TO Lx300000}
Time: 6 ms
Index: Cities/ByPopulation
Results: 0 returned out of 0 total.
Request # 280: GET - 7 ms - World - 200 - /indexes/dynamic/Cities?&query=Population_Range%3A%7BLx200000%20TO%20Lx300000%7D&pageSize=0&operationHeadersHash=1690003523
Query: Population_Range:{Lx200000 TO Lx300000}
Time: 6 ms
Index: Cities/ByPopulation
Results: 0 returned out of 0 total.
Some additional info that may help troubleshooting
- The data was imported via the CSV importer.
- No objects have been stored from a .NET application, only read.
This may imply that the schemas are not in sync, or the DB isn't sure of the data types yet, as the metadata is {}
Here is the resulting JSON from a document:
[city/1989]
{
"Name": "Aachen",
"CountryCode": "D",
"Province": "Nordrhein Westfalen",
"Population": 247113,
"CountryId": "country/1009"
}
and C# class:
public class City
{
public string Id { get; set; }
public string Name { get; set; }
public string CountryCode { get; set; }
public long Population { get; set; }
public string Province { get; set; }
public string CountryId { get; set; }
}
}
Another update
I've manually patched the collection with
this['@metadata']['Raven-Clr-Type'] = "Domain.City, Domain"
but this hasn't helped the serializer either.
You have to tell Raven, that Population is a number, because all values are stored as text. So in your index-constructor write something like
Sort(x => x.Population , SortOptions.Long);
这篇关于Raven-Studio Index正在向C#LINQ Query返回不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!