6.跟我学solr---请求参数详解

简介

前面我们在讲SolrRequestHandler和QueryResponseWriter的时候提到过两个参数‘qt‘和‘wt",这两个参数是分别用于选择对应的SolrRequestHandler和QueryResponseWriter的。solr定义了很多类似的参数,它们都分别属于某个大类中,例如"qt"和"wt"就属于CoreQueryParameters。下面罗列一下solr的所有参数列表,来源于solr官网。下面笔者会一一给大家讲解这些参数的作用。


parameter


docs


debugQuery


CommonQueryParameters


defType


CommonQueryParameters


echoHandler


CoreQueryParameters


echoParams


CoreQueryParameters


explainOther


CommonQueryParameters


facet.*


SimpleFacetParameters


fl


CommonQueryParameters


fq


CommonQueryParameters


hl.*


HighlightingParameters


mlt.*


MoreLikeThis


omitHeader


CommonQueryParameters


qt


CoreQueryParameters


rows


CommonQueryParameters


sort


CommonQueryParameters


start


CommonQueryParameters


timeAllowed


CommonQueryParameters


wt


CoreQueryParameters

CommonQueryParameters

q

q这个参数所传递的就是我们所查询的内容,例如我们要查询"feature"这个关键字,发起的请求就是

  http://localhost:8080/solr/collection1/select?q=feature&wt=json&indent=true

solr针对q这个参数支持以solr query syntax的方式,就是solr特有的一种查询表达式,具体可参考文档,Solr
query syntax

sort

大家回忆一下,在前面的章节中,我们在讲解添加索引的时候,提到过boost这个属性,这个属性在查询的时候就可以大派用场了,我们可以跟踪需要,对查询结果针对score(boost属性所设置的分值)进行排序。


Examples


sort


Meaning


by default, it is the same as score desc(默认是按分值以降序排列)


score desc


sort from highest score to lowest score(按分值以降序排列)


price asc


sort in ascending order of the "price" field(按价格字段以降序排列)


inStock desc, price asc


sort by "inStock" descending, then "price" ascending(按inStock字段以降序,price以升序排列)


sum(x_f, y_f) desc


sort by the sum of x_f and y_f in a descending order(按x_f和y_f字段相加后降序排列)

注意,并不是所有的field都能排序的。如果schema.xml里面org_name被定义成text型,请问还能sort=org_name desc吗?不能,因为text类型定义的filter已经将org_name进行了切分,一个被切分后的field也就丧失了排序资格。

start and rows

  • start:指定第一条记录在所有记录的位置。
  • rows:一次性取出多少条数据。start和rows一起使用用于分页。eg start=20&rows=10表示取20到30之间的数据,如果每页显示10条数据,那么这个结果就是第二页到第三页的数据了。

fq

过滤查询参数。它和q一起使用。格式1:fq=field:X,eg q=ibm&fq=org_name:ibm,表示org_name或者org_website里面出现ibm并且org_name里面出现ibm的document。格式2:fq=field:[X TO X],区间查询,eg fq=org_id:[100
TO 200],表示org_id为100(包含)到200(包含)的所有document。给大家贴一段代码,你就知道什么类型的field才能进行区间查询。

<!-- numeric field types that store and index the text
         value verbatim (and hence don‘t support range queries, since the
         lexicographic ordering isn‘t equal to the numeric ordering)
-->
    <fieldType name="integer" class="solr.IntField" omitNorms="true"/>
    <fieldType name="long" class="solr.LongField" omitNorms="true"/>
    <fieldType name="float" class="solr.FloatField" omitNorms="true"/>
    <fieldType name="double" class="solr.DoubleField" omitNorms="true"/>

    <!-- Numeric field types that manipulate the value into
         a string value that isn‘t human-readable in its internal form,
         but with a lexicographic ordering the same as the numeric ordering,
         so that range queries work correctly.
-->
    <fieldType name="sint" class="solr.SortableIntField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="slong" class="solr.SortableLongField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="sfloat" class="solr.SortableFloatField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="sdouble" class="solr.SortableDoubleField" sortMissingLast="true" omitNorms="true"/>

fl

这个参数用来选择哪些字段内容需要被返回,具体效果大家参照下面的例子试一下就知道了,这个和sql语句的返回指定字段是一样的。

Examples


Field List


Meaning


id name price


Only return the "id", "name", and "price" fields(只返回id,name,price三个字段)


id,name,price


Same as above(和上面一样)


id name, price


Same as above(和上面一样)


id score


Return the "id" field and the score(返回id和分值)


*


Return all fields the each document has(返回所有字段)


* score


Return all fields each document has, along with the score(返回所有字段和分值)

其它

defType: 指定query parser,常用defType=lucene,defType=dismax,defType=edismax

timeAllowed: 指定需要在规定时间内查询半壁,单位是毫秒。

CoreQueryParameters

coreQueryParameters除了"wt"和"qt"这两个参数以外,还有两个用于输出调试信息的参数。

echoHandeler:输入选择的handler信息。

echoParams:输入提交参数。

今天先讲CommonQueryParameters和CoreQueryParameters这两类参数,明天笔者继续为大家讲解查询查询相关的知识。

6.跟我学solr---请求参数详解,布布扣,bubuko.com

时间: 2024-08-03 15:34:53

6.跟我学solr---请求参数详解的相关文章

jquery ajax 方法及各参数详解

jquery ajax 方法及各参数详解 1.$.ajax() 只有一个参数:参数 key/value 对象,包含各配置及回调函数信息. 参数列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ("POST" 或 "GET"), 默认为 "GET".注意:其它 HTTP 请求方法,如 PUT 和 DELETE 也可以使用,但仅部分

Nginx内置变量以及日志格式变量参数详解

Nginx内置变量以及日志格式变量参数详解 $args #请求中的参数值 $query_string #同 $args $arg_NAME #GET请求中NAME的值 $is_args #如果请求中有参数,值为"?",否则为空字符串 $uri #请求中的当前URI(不带请求参数,参数位于$args),可以不同于浏览器传递的$request_uri的值,它可以通过内部重定向,或者使用index指令进行修改,$uri不包含主机名,如"/foo/bar.html". $d

MySQL配置文件mysql.ini参数详解、MySQL性能优化

MySQL配置文件mysql.ini参数详解.MySQL性能优化 my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section.   Client Section用来配置MySQL客户端参数.   要查看配置参数可以用下面的命令: show variables like '%innodb%'; # 查看innodb相关配置参数 show status like

JQuery中$.ajax()方法参数详解

url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 delete也可以使用,但仅部分浏览器支持. timeout: 要求为Number类型的参数,设置请求超时时间(毫秒).此设置将覆盖$.ajaxSetup()方法的全局设 置. async:要求为Boolean类型的参数,默认设置为true,所有请求均为异步请求. 如果需要发送同步请求,请将此选项

day01_linux中与Oracle有关的内核参数详解

linux中与Oracle有关的内核参数详解 在安装Oracle的时候需要调整linux的内核参数,但是各参数代表什么含义呢,下面做详细解析. Linux安装文档中给出的最小值: fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 4294967295 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip

httpUrlConnection的参数详解

post方式的的请求过程: // 设置是否向httpUrlConnection输出,因为这个是post请求,参数要放在 // http正文内,因此需要设为true, 默认情况下是false; httpUrlConnection.setDoOutput(true); // 设置是否从httpUrlConnection读入,默认情况下是true; httpUrlConnection.setDoInput(true); // Post 请求不能使用缓存 httpUrlConnection.setUse

PHP CURL参数详解

PHP CURL参数详解 curl用法:cookie及post一.cookie用法 <?php $cookie_jar = tempnam('./tmp','cookie'); // login $c=curl_init('http://login_url?username=... curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar); curl_exec($c); 

HTTP请求方法详解

HTTP请求方法详解 请求方法:指定了客户端想对指定的资源/服务器作何种操作 下面我们介绍HTTP/1.1中可用的请求方法: [GET:获取资源]     GET方法用来请求已被URI识别的资源.指定的资源经服务器端解析后返回响应内容(也就是说,如果请求的资源是文本,那就保持原样返回:如果是CGI[通用网关接口]那样的程序,则返回经过执行后的输出结果).     最常用于向服务器查询某些信息.必要时,可以将查询字符串参数追加到URL末尾,以便将信息发送给服务器.     使用GET请求时经常会发

nginx配置参数详解

配置参数详解 user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CPU. error_log  logs/error.log;  error_log  logs/error.log  notice;  error_log  logs/error.log  info;  错误日志:存放路径. pid logs/nginx.pid; pid(进程标识符):存放路径