solr使用curl查询结果

1,使用curl查询结果,并转成csv保存 

Java代码 复制代码  收藏代码
  1. curl http://localhost:8983/solr/company/query -d '  
  2. q=*:*&  
  3. start=500&  
  4. rows=300&  
  5. sort=modifyTime asc&  
  6. fl=cpyName&  
  7. wt=csv'  | sed '1d' >> csv  
curl http://localhost:8983/solr/company/query -d '
q=*:*&
start=500&
rows=300&
sort=modifyTime asc&
fl=cpyName&
wt=csv'  | sed '1d' >> csv



2,使用curl查询一个关键词

Java代码 复制代码  收藏代码
  1. curl -s  http://localhost:8983/solr/company/query -d '  
  2. q=sname:'$1'&  
  3. rows=0'  
curl -s  http://localhost:8983/solr/company/query -d '
q=sname:'$1'&
rows=0'


3,添加一个文档doc:

Java代码 复制代码  收藏代码
  1. curl http://localhost:8983/solr/demo/update -d '  
  2. [  
  3.  {"id" : "book1",  
  4.   "title_t" : "The Way of Kings",  
  5.   "author_s" : "Brandon Sanderson"  
  6.  }  
  7. ]'  
curl http://localhost:8983/solr/demo/update -d '
[
 {"id" : "book1",
  "title_t" : "The Way of Kings",
  "author_s" : "Brandon Sanderson"
 }
]'


4,获取一个文档:

Java代码 复制代码  收藏代码
  1. curl http://localhost:8983/solr/demo/get?id=book1  
  2. {  
  3.   "doc": {  
  4.     "id" : "book1",  
  5.     "author_s""Brandon Sanderson",  
  6.     "title_t" : "The Way of Kings",  
  7.     "_version_"1410390803582287872  
  8.   }  
  9. }  
curl http://localhost:8983/solr/demo/get?id=book1
{
  "doc": {
    "id" : "book1",
    "author_s": "Brandon Sanderson",
    "title_t" : "The Way of Kings",
    "_version_": 1410390803582287872
  }
}


5,更新一个文档:

Java代码 复制代码  收藏代码
  1. curl http://localhost:8983/solr/demo/update -d '  
  2. [  
  3.  {"id"         : "book1",  
  4.   "cat_s"      : { "add" : "fantasy" },  
  5.   "pubyear_i"  : { "add" : 2010 },  
  6.   "ISBN_s"     : { "add" : "978-0-7653-2635-5" }  
  7.  }  
  8. ]'  
curl http://localhost:8983/solr/demo/update -d '
[
 {"id"         : "book1",
  "cat_s"      : { "add" : "fantasy" },
  "pubyear_i"  : { "add" : 2010 },
  "ISBN_s"     : { "add" : "978-0-7653-2635-5" }
 }
]'



6,以CSV形式,添加一批文档:

Java代码 复制代码  收藏代码
  1. $ curl http://localhost:8983/solr/demo/update?commitWithin=5000 -H 'Content-type:text/csv' -d '  
  2. id,cat_s,pubyear_i,title_t,author_s,series_s,sequence_i,publisher_s  
  3. book1,fantasy,2010,The Way of Kings,Brandon Sanderson,The Stormlight Archive,1,Tor  
  4. book2,fantasy,1996,A Game of Thrones,George R.R. Martin,A Song of Ice and Fire,1,Bantam  
  5. book3,fantasy,1999,A Clash of Kings,George R.R. Martin,A Song of Ice and Fire,2,Bantam  
  6. book4,sci-fi,1951,Foundation,Isaac Asimov,Foundation Series,1,Bantam  
  7. book5,sci-fi,1952,Foundation and Empire,Isaac Asimov,Foundation Series,2,Bantam  
  8. book6,sci-fi,1992,Snow Crash,Neal Stephenson,Snow Crash,,Bantam  
  9. book7,sci-fi,1984,Neuromancer,William Gibson,Sprawl trilogy,1,Ace  
  10. book8,fantasy,1985,The Black Company,Glen Cook,The Black Company,1,Tor  
  11. book9,fantasy,1965,The Black Cauldron,Lloyd Alexander,The Chronicles of Prydain,2,Square Fish  
  12. book10,fantasy,2001,American Gods,Neil Gaiman,,,Harper'  
$ curl http://localhost:8983/solr/demo/update?commitWithin=5000 -H 'Content-type:text/csv' -d '
id,cat_s,pubyear_i,title_t,author_s,series_s,sequence_i,publisher_s
book1,fantasy,2010,The Way of Kings,Brandon Sanderson,The Stormlight Archive,1,Tor
book2,fantasy,1996,A Game of Thrones,George R.R. Martin,A Song of Ice and Fire,1,Bantam
book3,fantasy,1999,A Clash of Kings,George R.R. Martin,A Song of Ice and Fire,2,Bantam
book4,sci-fi,1951,Foundation,Isaac Asimov,Foundation Series,1,Bantam
book5,sci-fi,1952,Foundation and Empire,Isaac Asimov,Foundation Series,2,Bantam
book6,sci-fi,1992,Snow Crash,Neal Stephenson,Snow Crash,,Bantam
book7,sci-fi,1984,Neuromancer,William Gibson,Sprawl trilogy,1,Ace
book8,fantasy,1985,The Black Company,Glen Cook,The Black Company,1,Tor
book9,fantasy,1965,The Black Cauldron,Lloyd Alexander,The Chronicles of Prydain,2,Square Fish
book10,fantasy,2001,American Gods,Neil Gaiman,,,Harper'



7,查询一批数据,返回每行数据的:关键词,查询耗时,命中数量,示例数据如下:

Java代码 复制代码  收藏代码
  1. "连云港通裕天然气有限公司"  
  2. "连云港市天缘食品有限公司"  
  3. "重庆市涪陵国有资产投资经营集团有限公司"   
"连云港通裕天然气有限公司"
"连云港市天缘食品有限公司"
"重庆市涪陵国有资产投资经营集团有限公司" 



查询脚本如下:

Java代码 复制代码  收藏代码
  1. curl -s  http://localhost:8983/solr/webpage/query -d '  
  2. q=content:'$1'&  
  3. rows=0'  
curl -s  http://localhost:8983/solr/webpage/query -d '
q=content:'$1'&
rows=0'


批处理脚本如下:

Java代码 复制代码  收藏代码
  1. 执行这个批处理的查询脚本,测下平均耗时:  
  2. #for line in `cat csv | head -n 3`  
  3. for line in `cat csv`  
  4. do  
  5. echo $line  `sh kw_query.sh  $line   |   tr -d '\r\n' | gawk -F, '{print $2,$5}' | gawk -F: '{print $2,$4 }' | gawk -F" " '{print $1,$3}'`  
  6. done  
执行这个批处理的查询脚本,测下平均耗时:
#for line in `cat csv | head -n 3`
for line in `cat csv`
do
echo $line  `sh kw_query.sh  $line   |   tr -d '\r\n' | gawk -F, '{print $2,$5}' | gawk -F: '{print $2,$4 }' | gawk -F" " '{print $1,$3}'`
done


结果如下:

Java代码 复制代码  收藏代码
  1. "连云港通裕天然气有限公司" 283 7  
  2. "连云港市天缘食品有限公司" 137 2  
  3. "重庆市涪陵国有资产投资经营集团有限公司" 15 8  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值