【发布时间】:2017-12-04 12:44:37
【问题描述】:
我正在使用具有 ContentSearch 功能的 Sitecore 8.1 update 1。我将我的索引配置如下:
(我想通过纬度和经度搜索经纪人/客户办公室)
1) 在 index.config 中
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldNames hint="raw:AddFieldByFieldName">
<field fieldName="latitude" storageType="NO" indexType="UNTOKENIZED" vectorType="NO" boost="1f" type="System.Decimal" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
</field>
<field fieldName="longitude" storageType="NO" indexType="UNTOKENIZED" vectorType="NO" boost="1f" type="System.Decimal" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
</field>
2) 好的,现在使用 Luke.net 工具检查它的值
3) 我的 SearchResultItem 类:
[IndexField("latitude")]
public decimal Latitude { get; set; }
[IndexField("longitude")]
public decimal Longitude { get; set; }
4) 在我的服务类中,我想尝试在范围内搜索纬度/经度之间的方法,但它不起作用。我尝试相等(==)方法并且它有效。我认为我的索引没问题,但我的搜索语法可能有问题。你能帮忙吗?
//TODO: Testing -----------------
var query = searchContext.GetQueryable<BrokerSearchIndexItem>();
// IF i use this line (BETWEEN) --> NOT work ??
query = query.Where(item => (item.Latitude.Between(-34, -33, Inclusion.Both)
&& item.Longitude.Between(149, 151, Inclusion.Both)));
// If I use this line (EQUAL) --> work !
//query = query.Where(item => item.Latitude == -33.737643m && item.Longitude == 150.856664m);
var searchResult = query.GetResults();
5) 我已经阅读了本教程 (link) 和我的搜索日志,似乎 Between 方法给了我正确的日志,但不知道为什么我什么也得不到
9636 21:10:03 INFO ExecuteQueryAgainstLucene (steadfast_broker_location): +latitude:[-34 TO -33] +longitude:[149 TO 151] - Filter :
9636 21:10:03 INFO ExecuteQueryAgainstLucene (steadfast_broker_location): +latitude:[-34 TO -33] +longitude:[149 TO 151] - Filter :
9636 21:10:03 INFO ExecuteQueryAgainstLucene (steadfast_broker_location): +latitude:[-34 TO -33] +longitude:[149 TO 151] - Filter :
【问题讨论】:
-
不确定,但尝试“-34.000000m”而不是“-34”。或者作为解决方法,这应该会有所帮助: query = query.Where(item => (item.Latitude > -34.000000m && item.Latitude 149.000000m && item.Longitude
标签: solr lucene sitecore lucene.net