【问题标题】:Sitecore Content Search (Lucene) - Between<T>() not workSitecore 内容搜索 (Lucene) - Between<T>() 不起作用
【发布时间】: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 工具检查它的值

image in Luke.net tool

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


【解决方案1】:

查看Lucene Spatial Search Support module

它将提供:

  • 新的 Sitecore 字段“Google 地图”将存储纬度/经度并在内容编辑器中提供地图界面。
  • 索引架构更新以存储 lat 和 long 值。
  • 更新了 Sitecore ContentSearch 以提供地理空间搜索方法。

还有一个module for Solr

【讨论】:

  • 感谢 Nathan Hase,但我也使用 Between 来搜索范围内的其他小数字段,所以我仍然想为其他情况修复此错误 :)
  • 好的,试着看看空间源代码,看看他们对谓词做了什么。我还注意到您的 Between 示例使用整数,而 Equals 示例使用小数。
  • 再次感谢您,我将尝试阅读该模块的源代码。关于我的示例代码,我确实尝试在 Between 语句中使用小数,但它不起作用。在我的解决方案中,我传递十进制变量,而不是硬编码常量值
  • 对,只是要检查的事情 :) 您还可以查看正在运行的 Lucene 查询,并使用 Luke 对其进行测试以获得更多视角。查询记录在 /data/logs/search.log
猜你喜欢
  • 1970-01-01
  • 2016-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多