Solr 搜索的过程和所须要的參数

一个典型的搜索处理过程,以及所须要的參数例如以下:
  1. qt:指定一个RequestHandler,即/select。缺省是使用DisMax RequestHandler
  2. defType:选择一个query parser。缺省是RequestHandler中配置的那个
  3. qf:指定须要搜索的field。假设不指定就搜索全部的field
  4. start, rows:指明分页參数
  5. fq:指明须要怎样过滤搜索结果。以及缓存搜索结果
  6. wt:指定搜索结果的格式,比方json或xml

搜索所须要的參数基本上能够分为三类:
  • 须要搜索的字符串
  • 调整搜索的參数(指定被搜索的field、为某些field添加权值、等等)
  • 搜索结果展示的參数(排序、结果过滤、分页、高亮显示、等等)

搜索请求參数:
參数
说明
q
Query,要搜索的内容。
  • 假设要搜索一个句子,用引號引起来:q="Hello wolrd"
  • 假设指定搜索某个域:q=field_name:content
  • 假设是中文,用引號引起来,就是全内容匹配才返回,如:q="笔记"
  • 假设要搜索多个单词、句子,使用加号(+):q="笔记"+"配置"
  • 假设要排除含有某个keyword的,使用减号(-):q="笔记"-"配置"
fq
Filter Query。搜索结果过滤(结果会被缓存起来):
  • fq=popularity:[10 to *]:仅仅返回popularity大于10的结果
  • 须要同一时候满足两个条件的情况:fq=popularity:[10 TO *]&fq=section:0
  • 上面这样的也能够写成:fq=popularity:[10 TO *]+fq=section:0
后两种的不同点:前一种:搜索结果分开存在缓存中,然后取交集。后一种:搜索结果存在一个缓存中
sort
指定搜索结果依照某个域来排序。样例:
  • score desc(缺省):依照搜索分数降序排序
  • price asc:依照“price”域升序排序
  • nStock desc, price asc:先依照nStock降序,再依照price升序
start, rows
返回第start条開始。一共rows条记录。样例:
  • start=11&rows=100
  • 缺省:start=0, rows=10
fl
Field List,要返回的域。比方“id”、*,假设有多个,用逗号(,)或空格分开。还能够返回score。样例:
  • fl=id,name
  • fl=id,score
  • fl=*,score
df
Default Field,默认的查询字段,又一次指定并覆盖schema.xml中的default field
wt
Writer,指定一个writer以返回不同的格式,比方:json, xml...
facet
统计查询结果:
按某个域统计:facet=true&facet.field=author(依照“author”这个域统计)
defType
指定一个Request Handler,然后使用它所配置的parser,比方dismax, edismax来运行搜索。缺省是dismax。即"lucene" parser。dismax、edismax支持为每一个被搜索的域指定权值。以影响score。

dismax 是 Maximum Disjunction 的缩写。

qf
Query Field。指定要搜索的域,覆盖df,同一时候能够为某个域设置权值,须要配合defType=dismax或defType=edismax,样例:
  • defType=dismax&qf=author^10
  • defType=dismax&qf=author^10+name^2+content


注:关于Maximum Disjunction的定义:
A query that generates the union of documents produced by its subqueries, and that scores each document with the maximum score for that document as produced by any subquery, plus a tie breaking increment for any additional matching subqueries.
大概就是:一个查询由若干个子查询组成,每一个子查询都有一个得分,总分=最大分+其它子查询的分数×tieBreakerMultiplier。






原文地址:https://www.cnblogs.com/yxysuanfa/p/7083224.html