【发布时间】:2018-02-05 17:17:03
【问题描述】:
我使用的是 RavenDB 3.5.35183。我有一个类型:
import com.mysema.query.annotations.QueryEntity;
@QueryEntity
public class CountryLayerCount
{
public String countryName;
public int layerCount;
}
以及以下查询:
private int getCountryLayerCount(String countryName, IDocumentSession currentSession)
{
QCountryLayerCount countryLayerCountSurrogate = QCountryLayerCount.countryLayerCount;
IRavenQueryable<CountryLayerCount> levelDepthQuery = currentSession.query(CountryLayerCount.class, "CountryLayerCount/ByName").where(countryLayerCountSurrogate.countryName.eq(countryName));
CountryLayerCount countryLayerCount = new CountryLayerCount();
try (CloseableIterator<StreamResult<CountryLayerCount>> results = currentSession.advanced().stream(levelDepthQuery))
{
while(results.hasNext())
{
StreamResult<CountryLayerCount> srclc = results.next();
System.out.println(srclc.getKey());
CountryLayerCount clc = srclc.getDocument();
countryLayerCount = clc;
break;
}
}
catch(Exception e)
{
}
return countryLayerCount.layerCount;
}
查询成功执行,并显示我正在检索的文档的正确 ID(例如“CountryLayerCount/123”),但其数据成员均为空。 where 子句也可以正常工作,国家名称用于检索各个国家/地区。这很简单,但我看不出我哪里出错了。 StreamResult 包含正确的键,但 getDocument() 不起作用 - 或者更确切地说,它不包含对象。该集合具有字符串 ID。
在 db 记录器中,我可以看到进来的请求:
Receive Request # 29: GET - geodata - http://localhost:8888/databases/geodata/streams/query/CountryLayerCount/ByName?&query=CountryName:Germany
Request # 29: GET - 22 ms - geodata - 200 - http://localhost:8888/databases/geodata/streams/query/CountryLayerCount/ByName?&query=CountryName:Germany
当插入浏览器时,它会正确地给我:
{"Results":[{"countryName":"Germany","layerCount":5,"@metadata":{"Raven-Entity-Name":"CountryLayerCounts","Raven-Clr-Type":"DbUtilityFunctions.CountryLayerCount, DbUtilityFunctions","@id":"CountryLayerCounts/212","Temp-Index-Score":0.0,"Last-Modified":"2018-02-03T09:41:36.3165473Z","Raven-Last-Modified":"2018-02-03T09:41:36.3165473","@etag":"01000000-0000-008B-0000-0000000000D7","SerializedSizeOnDisk":164}}
]}
索引定义:
from country in docs.CountryLayerCounts
select new {
CountryName = country.countryName
}
AFAIK,不必索引对象的所有字段即可完整检索它,对吗?换句话说,我只需要索引字段来查找对象,而不是我想要检索的所有字段;至少这是我的理解……
谢谢!
【问题讨论】:
-
CountryLayerCount/ByName长什么样子? -
@Ayende:更新了问题