欢迎投稿

今日深度:

Solr tutorial,

Solr tutorial,


http://lucene.apache.org/solr/tutorial.html

 

solr一些基础的用法

 

启动,使用内嵌的jetty,也可使用容器

java -jar start.jar

启动后访问管理页面http://localhost:8983/solr/admin

Indexing Data

 

使用工具索引文档,  切换到exampledocs目录

java -jar post.jar *.xml

post.jar程序将xml文件提交到solr服务建立索引

看看这些xml文件格式,都是<doc></doc>格式化的描述信息,包括字段名和值,字段名在配置文件schema.xml中有描述

执行完成后,在浏览器中查询

查询关键字video

http://localhost:8983/solr/select/?q=video

在字段name中查询video

http://localhost:8983/solr/select/?q=name:video

http://localhost:8983/solr/select/?q=%2Bvideo+%2Bprice%3A[*+TO+400]

数据导入的方式有几种:

使用Data Import Handler (DIH)从数据库中导入,例子看db

CSV文件导入

JSON文档

使用Solr Cell导入二进制文档(如word, pdf)

使用SolrJ编程实现

 

Updating Data

根据uniqueKey(配置文件中有定义),如果存在则替换之前的数据

重复执行post.jar程序导入xml文件,通过http://localhost:8983/solr/admin/stats.jsp查看numDocs maxDoc统计值

more

 

 

Deleting Data

 

根据id删除索引数据

java -Ddata=args -Dcommit=no -jar post.jar "<delete><id>SP2514N</id></delete>"

参数-Dcommit=no为非自动提交,为提高效率,多次执行操作,最后一次性提交

执行java -jar post.jar会产生提交

根据查询条件删除索引数据

java -Ddata=args -jar post.jar "<delete><query>name:DDR</query></delete>"

 

Querying Data

 

查询结果默认用xml返回,看其格式

  • q=video&fl=name,id查询video,返回字段name,id
  • q=video&fl=name,id,scorescore是相关性分数(relevancy score)
  • q=video&fl=*,score返回所有字段和score
  • q=video&sort=price desc&fl=name,id,priceprice降序
  • q=video&wt=json返回json格式,默认是xml格式
  • q=video&sort=inStock asc, price descinStock升序price降序
  • q=video&sort=score desc使用score降序
  • q=video&sort=inStock asc, score desc
  • q=video&sort=div(popularity,add(price,1)) desc函数结果降序

more

 

 

Highlighting

 

  • q=video card&fl=name,id&hl=true&hl.fl=name,features查询结果中的关键字高亮,看返回的xml中增加了高亮节点

更多

 

Faceted Search

统计查询结果某些字段出现的次数

  • q=*:*&facet=true&facet.field=cat

统计查询结果中字段cat出现的次数

  • q=*:*&facet=true&facet.field=cat&facet.field=inStock

统计查询结果中字段cat和字段inStock出现的次数

  • q=ipod&facet=true&facet.query=price:[0 TO 100]&facet.query=price:[100 TO *]

统计查询结果中字段price在[0-100]和[>100]两个范围出现的次数

  • q=*:*&facet=true&facet.date=manufacturedate_dt&facet.date.start=2004-01-01T00:00:00Z&facet.date.end=2010-01-01T00:00:00Z&facet.date.gap=+1YEAR

统计查询结果中字段“生产日期”,一个时间段内每1年中出现的次数

  • more

 

Search UI

一个查询页面,看看源码?

http://localhost:8983/solr/browse

Text Analysis

分析和具体的语言有关(中文和英语就很不一样),

more

Analysis Debugging

more

Conclusion

文档格式?(字段,值)

 

More

 

distributed search

function queries

numeric field statistics

search results clustering

see Solr Wiki

 

 

 

 

 

www.htsjk.Com true http://www.htsjk.com/solr/34884.html NewsArticle Solr tutorial, http://lucene.apache.org/solr/tutorial.html   solr一些基础的用法   启动,使用内嵌的 jetty, 也可使用容器 java -jar start.jar 启动后访问管理页面 http://localhost:8983/solr/admin Indexing Data  ...
相关文章
    暂无相关文章
评论暂时关闭