solr查询

 

对数据库getgrid_portal数据表pro_service_item指定条件查询

实现功能:不指定字段和关键字,则默认全部查询。指定关键字,不指定字段,默认对所有字段进行匹配,得出结果。指定一个或者多个字段的关键字,支持模糊查询,得到符合该要求的结果。

下面为查询的几种常见写法:

1.查询全部信息

对数据库中表中全部内容进行搜索,并返回json格式的内容

q=*:* 查找全部信息

http://ip/solr/design/select?q=*:*&wt=json&indent=true

2不指定字段,只指定关键字

http://ip:8983/solr/design/select?q=电池&wt=json&indent=true

3.添加起始行并限定返回数据条数

start=10 从第10行开始,如果从第一行开始,start=n可省略

rows=20 每次返回20条记录

http://ip:8983/solr/design/select?q=*:*&start:10&rows:20

&wt=json&indent=true

4.单条件搜索

搜索出category_id=135的所有数据

http://ip:8983/solr/design/select?q=category_id:135&wt=json&indent=true

5.多条件查询

q 是查询,后面放关键词参数

fq是辅助查询,后面放过滤参数,提供一个可选的筛选器查询。查询结果被限制为仅搜索筛选器查询返回的结果。筛选过的查询由 Solr 进行缓存。它们对提高复杂查询的速度非常有用。

查询结果首先要满足q中条件,然后在前面的查询结果中找出满足一个或者多个fq条件

查询category_id=135 并且筛选出description=电池、address=江苏的结果

http://ip:8983/solr/design/select?q=category_id:135&fq=description:电池&fq=address:江苏&wt=json&indent=true

6.查询搜索结果不是某一条件时

q=-category_id:135

在搜索条件字段名称前加-,代表搜索 category_id不等于135的结果

http://ip:8983/solr/design/select?q=-category_id:135&wt=json&indent=true

7.对double类型字段限定搜索范围

希望搜索结果被限制在某一区间之内。比如查询价格在10到50之间的商品。过滤条件可以写成price:[10 TO 50],(price是double类型)其中字段名后必须有方括号包裹数值,单词TO必须是大写,且前后有空格

http://ip:8983/solr/design/select?q=*:*&fq=price:[10 TO 50] &wt=json&indent=true

8.对datatime类型的数据限定搜索范围

搜索create_time字段某一个时间段中的结果使用create_time:[starttime TO entime]

http://ip:8983/solr/design/select?q=*:*&fq=create_time:[2017-01-09T15:24:59Z TO 2017-01-13T09:23:23Z]&wt=json&indent=true

原文地址:https://www.cnblogs.com/zy900406/p/6378671.html