Solr部署配置(三)实时检索接口
来源:互联网 发布:手机免费听歌软件 编辑:程序博客网 时间:2024/04/18 02:29
Solr是一个拥有象WebService一样接口的独立运行的搜索服务器。它基于restful风格,并且扩展了Lucene.能够通过HTTP协议以XML格式将文档放入搜索服务器(索引),你能够通过HTTP协议的GET来查询搜索服务器并且得到XML格式的结果。
REST并不是一个协议或技术;它是一种体系结构风格。
REST 是 SOAP 的轻量型替代品,它是面向资源的,而不是面向操作的。它常常被归结为远程过程使用 HTTP 调用 GET、POST、PUT 和 DELETE 语句。
REST比较简单朴素,在安全性,可靠消息传输,或标准化的业务过程自动化上还没有定义。
一、通过http传递xml格式数据
<add> <doc> <field name="employeeId">05991</field> <field name="office">Bridgewater</field> <field name="skills">Perl</field> <field name="skills">Java</field> </doc> [<doc> ... </doc>[<doc> ... </doc>]]</add><delete><id>05991</id></delete><delete><query>office:Bridgewater</query></delete>
http://localhost:8983/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<add><doc><field name="id">testdoc</field></doc></add>'
http://localhost:8081/solr/update/?stream.body=<add><doc><field name="id">1</field><field name="author">bbb</field></doc></add>&commit=true
二、通过http传递json格式数据
{ add: { "doc": { "id": "DOC1", "my_boosted_field": { /* use a map with boost/value for a boosted field */ "boost": 2.3, "value": "test" }, "my_multivalued_field": [ "aaa", "bbb" ] /* use an array for a multi-valued field */ }},add: { "commitWithin": 5000, /* commit this document within 5 seconds */ "overwrite": false, /* don't check for existing documents with the same uniqueKey */ "boost": 3.45, /* a document boost */ "doc": { "f1": "v1", "f1": "v2" }},delete: { "id":"ID" }, /* delete by ID */delete: { "query":"QUERY" } /* delete by query */delete: { "query":"QUERY", 'commitWithin':'500' } /* delete by query, commit within 500ms */}
http://localhost:8983/solr/update -H 'Content-type:application/json' -d '
{
"id" : "TestDoc1",
"title" : {"set":"test1"},
"revision" : {"inc":3},
"publisher" : {"add":"TestPublisher"}
}'
http://localhost:8081/solr/update/?stream.body={"add": {"doc":{"id":1, "author":"ccc"}}}&commit=true
查询
http://localhost:8983/solr/select?q=name:monsters&wt=json&indent=true
{ "responseHeader":{ "status":0, "QTime":2, "params":{ "indent":"true", "wt":"json", "q":"title:monsters"}}, "response":{"numFound":1,"start":0,"docs":[ { "id":"978-1423103349", "author":"Rick Riordan", "series_t":"Percy Jackson and the Olympians", "sequence_i":2, "genre_s":"fantasy", "inStock":true, "price":6.49, "pages_i":304, "name":[ "The Sea of Monsters"], "cat":["book","paperback"]}] }}
三、通过java API(Solrj)访问
1、建立与Solr服务的连接
String url = "http://localhost:8983/solr"; CommonsHttpSolrServer server = new CommonsHttpSolrServer(url); server.setSoTimeout(3000); // socket read timeout server.setConnectionTimeout(1000); server.setDefaultMaxConnectionsPerHost(1000); server.setMaxTotalConnections(10); server.setFollowRedirects(false); // defaults to false server.setAllowCompression(true); server.setMaxRetries(1);
2、搜索条件的设置
SolrQuery query = new SolrQuery();query.setQuery("tags:t5 AND t7");query.setStart(0);query.setRows(4);query.addSortField("auction_id", SolrQuery.ORDER.desc);query.addSortField("auction_point", SolrQuery.ORDER.asc);
3、结果集的获取
Solrj提供的注解的方式,注入pojo
import org.apache.solr.client.solrj.beans.Field; public class Item { @Field String id; @Field("tags") String[] tag; @Field List<String> features; }
调用
查询 QueryResponse qrsp = solrServer.query(query); List<Item> productIds = qrsp.getBeans(Item.class);更新索引solrServer.addBean(obj);
PS. 内容不记得从哪里拷的了~~
- Solr部署配置(三)实时检索接口
- solr-用mmseg4j配置同义词索引和检索(IKanlyzer需要修改源码适应solr接口才能使用同义词功能)
- 全文检索技术 solr(三)solr安装、启动
- Solr检索配置
- Solr基础(三) Solr常用检索语法
- Solr部署配置(一)运行
- Solr部署与配置
- solr solrcloud 检索 搜索 zookeeper 分布式 部署
- 全文检索引擎 Solr 部署与基本原理
- 配置solr使其支持中文检索
- solr中文同义词检索的配置讲解
- Solr(三)——单机部署SolrCloud
- solr集群配置与部署
- Solr集群配置以及部署
- linux集群系列(三):Solr全文搜索服务器部署(Solr-5.2.1)
- Solr部署配置(二)中文分词设置
- Solr部署配置(四)批量导入数据
- 配置solr服务(默认使用jetty部署)
- 13周项目4
- C++ primer 第二章习题
- jquery的动画
- DNS解析过程详解
- 名称相似匹配度算法
- Solr部署配置(三)实时检索接口
- ntp服务器配置for linux
- oracle学习笔记2
- poj2449-A*算法+优先队列+第k最短路
- 众数问题分析
- JSTL JSP标准标签库(四)
- 关于l ibrary not found for -lz.1.2.3 编译错误
- bzip2压缩实例
- 媒体查询:支持不同的视口