需求:商品排序,無庫存的商品排在后面(排序)。
搜索:
默認搜索: df:
可以看出左圖第1個、第6個庫存為0.
現在的需求是想將這兩個庫存為0的商品排在最后面。
edismax-》bf:product(map(store,1,9999999,1),100) ,效果如右圖。
store map的規則:
store=0,v(store)=0;
store>0,v(store)=1;(默認store的最大值999999999)
product*100,為了突顯加權的效果。(可忽略)
以上等同於:
q: queryStr_val_:"product(map(store,1,9999999,1),100)"
觀察打分的細節:
<str name="92011786"> 12.634275 = (MATCH) sum of: 2.0679202 = (MATCH) sum of: 1.2457463 = (MATCH) weight(searchField:165 in 18377) [DefaultSimilarity], result of: 1.2457463 = score(doc=18377,freq=2.0 = termFreq=2.0 ), product of: 0.77180904 = queryWeight, product of: 7.3044024 = idf(docFreq=78, maxDocs=43211) 0.105663545 = queryNorm 1.6140602 = fieldWeight in 18377, product of: 1.4142135 = tf(freq=2.0), with freq of: 2.0 = termFreq=2.0 7.3044024 = idf(docFreq=78, maxDocs=43211) 0.15625 = fieldNorm(doc=18377) 0.82217383 = (MATCH) weight(searchField:清爽 in 18377) [DefaultSimilarity], result of: 0.82217383 = score(doc=18377,freq=2.0 = termFreq=2.0 ), product of: 0.6270135 = queryWeight, product of: 5.934057 = idf(docFreq=310, maxDocs=43211) 0.105663545 = queryNorm 1.3112538 = fieldWeight in 18377, product of: 1.4142135 = tf(freq=2.0), with freq of: 2.0 = termFreq=2.0 5.934057 = idf(docFreq=310, maxDocs=43211) 0.15625 = fieldNorm(doc=18377) 10.566355 = (MATCH) FunctionQuery(product(map(int(store),1.0,9999999.0,const(1)),const(100))), product of: 100.0 = product(map(int(store)=10,min=1.0,max=9999999.0,target=const(1)),const(100)) 1.0 = boost 0.105663545 = queryNorm </str>
從上可以大致看出總分12.634275為文本分2.0679202加上庫存加分10.566355。
擴展閱讀:
http://wiki.apache.org/solr/DisMax
DisMax is an abbreviation Disjunction Max, and is a popular query mode with Solr.
Simply put, it's your choice for all user generated queries.
Out of the box, Solr uses the standard Solr query parser which is pretty stupid, understanding only syntactically correct boolean queries like "title:foo OR body:foo", it can only search one field by default, and it may very well throw an exception in your face if you put in some characters it does not like.
Therefore a new, more robust query mode was needed and the DisMax and ExtendedDisMax Query Parsers were born. They are designed to process simple user entered phrases (without heavy syntax) and search for the individual words across several fields using different weighting (boosts) based on the significance of each field, and it should never throw an exception.
Disjunction refers to the fact that your search is executed across multiple fields, e.g. title, body and keywords, with different relevance weights
Max means that if your word "foo" matches both title and body, the max score of these two (probably title match) is added to the score, not the sum of the two as a simple OR query would do. This gives more control over your ranking.
DisMax is usually the short name for the actual query parser, so don't be confused. The old DisMax parser has been around for some time, while the new and more advanced ExtendedDisMax parser was introduced in Solr3.1 as experimental.
There is a Lucid Imagination Blog post that explains the origins and conceptual behavior of dismax functionality.
FunctionQuery:
http://wiki.apache.org/solr/FunctionQuery#map
ExtendedDisMax[edisMax]:
http://wiki.apache.org/solr/ExtendedDisMax