edismax支持boost函數與score相乘作為,而dismax只能使用bf作用效果是相加,所以在處理多個維度排序時,score其實也應該是其中一個維度 ,用相加的方式處理調整麻煩。
而dismax的實現代碼邏輯比較簡單,看起來比較易理解,edismax是它的加強版,其實是改變了不少。。比如在以下:
先看看dismax的解析主要實現思路:
首先取出搜索字段名qf
將最終解析成一個BooleanQuery
先解析主mainQuery:
- 用戶主要是搜索串的解析
- altQuery解析處理,看是否使用用戶定義的後備搜索串
- PhraseQuery解析組裝
再解析bq查詢,主要是額外加分的查詢,不會影響搜索結果數,只會影響排序
再則是bf解析,函數搜索最後會以加的方式作用於文檔評分
看主要代碼更清晰:
- @Override
- public Query parse() throws ParseException {
- SolrParams solrParams = SolrParams.wrapDefaults(localParams, params);
-
- queryFields = SolrPluginUtils.parseFieldBoosts(solrParams.getParams(DisMaxParams.QF));
- if (0 == queryFields.size()) {
- queryFields.put(req.getSchema().getDefaultSearchFieldName(), 1.0f);
- }
-
- /* the main query we will execute. we disable the coord because
- * this query is an artificial construct
- */
- BooleanQuery query = new BooleanQuery(true);
-
- boolean notBlank = addMainQuery(query, solrParams);
- if (!notBlank)
- return null;
- addBoostQuery(query, solrParams);
- addBoostFunctions(query, solrParams);
-
- return query;
- }