`
san_yun
  • 浏览: 2596874 次
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

solr的函数查询_FunctionQuery_总结

    博客分类:
  • solr
 
阅读更多

作用

函数查询的作用,是影响计算score的算法,并不替换,只是影响。普通的计算score的方法是lucene本身的算法。

描述如下:

A function query allows you to introduce a component of the score that is computed,
based on a mathematical expression of your choice involving indexed field value(s).
This is not a replacement for Lucene's scoring algorithm, but it basically adds to the
existing score.

 

可见 函数查询 这个名字并不好,如 《Solr 1.4 Enterprise Search Server》中所述:

A bad name for this feature
The name of this feature is poor as it does not reflect what it does.
Perhaps Scoring Function or even Score Query might have been
bette
r. The reason for the name Function Query undoubtedly stems
from the manner in which the feature is implemented. It is implemented
as a Lucene Query type, albeit a very strange one that matches all of the
documents but scores them differently.

 

本质:

增加一个查询字段,值为函数计算所得。

可以简单这么理解 score += 函数计算结果

本来score是lucene根据字段的查询得到的,比如查询字符串 comments:套餐  lucene根据具体索引情况计算得到score值。

现在模拟一个字段,规定叫做_val_,这个字段的值就是跟随的函数计算的结果。

例子 comments:套餐 && _val_:"div(age,status)"

 

用法

用法wiki里有好几种,严格来说4种,详细请看wiki。

现在的刚刚发布solr3.1(同步了lucene的版本),这些功能我并没有用过。但1.4中的有些用法有bug。

可以的用法:

q=comments:套餐 && _val_:"div(age,status)"

注意函数就是一个表达式,所以函数也是可以嵌套的~

 

 

 

 

其他的,不再重复solr的wiki中的内容,仅仅贴出链接。

函数查询的中文翻译版(不太全):http://www.iteye.com/topic/352191

函数查询的wiki版(全而新)      :http://wiki.apache.org/solr/FunctionQuery#Using_FunctionQuery

一个好例子,仔细看哦~~          :http://www.ibm.com/developerworks/cn/java/j-spatial/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics