2017-06-30 33 views
2

我正在使用Sitecore 8.1更新1與ContentSearch功能。配置我的指標如下:Sitecore內容搜索(Lucene) - 之間<T>()不工作

(我想通過經緯度搜索經紀人/客戶辦公室)

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)和我的搜索記錄中,也好像方法之間給我正確的日誌,但不知道爲什麼,我什麼也沒得到

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 : 
+0

不確定,但嘗試'-34.000000m'而不是'-34'。 或作爲解決方法,這應該有所幫助: query = query.Where(item =>(item.Latitude> -34.000000m && item.Latitude <-33.000000m)&&(item.Longitude> 149.000000m && item.Longitude <151.000000m )) –

回答

0

時退房Lucene Spatial Search Support module

它將提供:

  • 新的Sitecore字段「谷歌地圖」,無線將存儲lat/long並在內容編輯器中提供一個地圖界面。
  • 索引架構更新來存儲緯度和長度的值。
  • 更新Sitecore ContentSearch以提供地理空間搜索方法。

還有一個module for Solr

+0

感謝Nathan Hase, 但是我也使用Between來搜索範圍內的其他Decimal字段,所以我仍然想修復這個bug以便處理其他情況:) –

+0

好吧,試着看看空間源代碼來看看他們正在做謂詞。我還注意到,您的「示例之間」使用整數,而您的「等於」示例使用小數。 –

+0

再次感謝您, 我會嘗試閱讀該模塊的源代碼。關於我的示例代碼,我在Between語句中嘗試使用decimal,但它不起作用。在我的解決方案中,我傳遞十進制變量,而不是硬編碼常量值 –