2015-10-18 28 views
0

我使用3 appIndexer搜索使用SearchManager的API kademi內容: 1.簡介appsIndexer 2.內容appsIndexer 3.博客appsIndexer如何使用kademi search manager API從搜索結果中排除學習模塊,課程等並測試頁面?

這是我的js代碼:

keyword = params['q']; 

var json = { 
     "query": { 

      "match": {"_all":keyword} 
     }, 

     "highlight": { 
      "fields" : { 
       "*" : {}, 
       "content" : { 
        "type" : "plain" 
       } 
      } 
     } 
    }; 

var sm = applications.search.searchManager; 

var indexers = sm.appIndexers; 
var profileIndexer = indexers.profile; 
var contentIndexer = indexers.content; 
var blogIndexer = indexers.blogs; 

var builder = sm.prepareSearch(profileIndexer, contentIndexer, blogIndexer); 
builder.setSource(JSON.stringify(json)); 
builder.setTypes("profile", "html"); 

var result = builder.execute().actionGet(); 

http.request.attributes.searchResults = result; 
return views.templateView("/theme/debugging.html"); 

如果您請參閱我的自定義搜索頁面http://oceanyouthplatform.olhub.com/profileSearch?q=oy+hood,我的搜索結果仍包含學習內容。見下面我的截圖:

search result contain learning content

如何排除學習模塊,課程等,並從搜索結果頁面測試使用kademi的搜索管理API?

回答

0

您應該使用itemType屬性來指定要包含哪些項目,或指定要排除哪些項目。

最簡單的就是排除電子學習項目。這需要排除模塊,但也需要模塊頁面,課程和程序,因爲它們都是單獨的項目類型。

但是,您可能會發現您要明確指出要包含哪些項目。項目類型可以在其屬性選項卡上的任何內容項目上設置。

不過濾: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-not-filter.html

條款過濾器: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html

要排除的項目類型的模塊和modulePage使用:

var searchConfig = { 
    "query": { 
     "filtered": { 
      "query": { 
       "match": {"_all":keyword} 
      }, 
      "filter": { 
       "not" : { 
        "terms" : { "itemType" : ["program", "course", "module", "modulePage"]} 
       } 
      } 
     } 
    } 
}; 
+0

我下面的堆棧溢出的答案,但我仍然在我的搜索結果上獲得程序頁面。這是我的搜索網址http://oceanyouthplatform.olhub.com/oySearch?q=oy+hood 請點擊'預編程評估(html)'或'後期評估(html)'搜索結果。 –

+0

請檢查正在返回的內容項目的itemType。我想你會發現它不在排除列表中。請注意,可以在**每個**項目上設置itemType,這會覆蓋默認值 – brad