solr_排序、高亮、删除数据
一、排序
Solr提供排序的功能,通过参数sort来指定,它支持正序、倒序,或者多个字段排序
q=video&sort=price desc
q=video&sort=price asc
q=video&sort=inStock asc, price desc
默认条件下,Solr根据socre 倒序排列,socre是一条搜索记录根据相关度计算出来的一个分数。
在页面中,如:
二、高亮
网页搜索中,为了突出搜索结果,可能会对匹配的关键字高亮出来,Solr提供了很好的支持,只要指定参数:
hl=true #开启高亮功能
hl.fl=name #指定需要高亮的字段
测试方法一:直接在http参数中输入:
http://localhost:8983/solr/collection1/select?q=Search&wt=json&indent=true&hl=true&hl.fl=features
返回的内容中包含:
"highlighting":{
"SOLR1000":{
"features":["Advanced Full-Text <em>Search</em> Capabilities using Lucene"]
}
}
测试方法二,在solr页面中执行execute query按钮:
在页面中钩选hl后,会多出一些选项:
执行完查询后,右侧的结果最后多了如下标签:
其中
三、删除数据
通过id删除指定的文档
java -Ddata=args -jar post.jar "<delete><id>SOLR1000</id></delete>"
通过一个查询来删除匹配的文档
java -Ddata=args -jar post.jar "<delete><query>name:DDR</query></delete>"
此时solr.xml文档从索引中删除了,再次搜”solr”时不再返回结果。当然solr也有数据库中的事务,执行删除命令的时候事务自动提交了,文档就会立即从索引中删除。你也可以把commit设置为false,手动提交事务。
java -Ddata=args -Dcommit=false -jar post.jar "<delete><id>3007WFP</id></delete>"
执行完上面的命令时文档并没有真正删除,还是可以继续搜索相关结果,最后可以通过命令:
java -jar post.jar -
提交事务,文档就彻底删除了。现在把刚刚删除的文件重新导入Solr中来,继续我们的学习。
删除所有数据:
http://localhost:8983/solr/collection1/update?stream.body=<delete><query>*:*</query></delete>&commit=true
删除指定数据
http://localhost:8983/solr/collection1/update?stream.body=<delete><query>title:abc</query></delete>&commit=true
多条件删除
http://localhost:8983/solr/collection1/update?stream.body=<delete><query>title:abc AND name:zhang</query></delete>&commit=true
<delete>
<query>id:"0001"</query>
</delete>
<commit></commit>