1,使用curl查询结果,并转成csv保存
- curl http://localhost:8983/solr/company/query -d '
- q=*:*&
- start=500&
- rows=300&
- sort=modifyTime asc&
- fl=cpyName&
- 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查询一个关键词
- curl -s http://localhost:8983/solr/company/query -d '
- q=sname:'$1'&
- rows=0'
curl -s http://localhost:8983/solr/company/query -d ' q=sname:'$1'& rows=0'
3,添加一个文档doc:
- curl http://localhost:8983/solr/demo/update -d '
- [
- {"id" : "book1",
- "title_t" : "The Way of Kings",
- "author_s" : "Brandon Sanderson"
- }
- ]'
curl http://localhost:8983/solr/demo/update -d ' [ {"id" : "book1", "title_t" : "The Way of Kings", "author_s" : "Brandon Sanderson" } ]'
4,获取一个文档:
- curl http://localhost:8983/solr/demo/get?id=book1
- {
- "doc": {
- "id" : "book1",
- "author_s": "Brandon Sanderson",
- "title_t" : "The Way of Kings",
- "_version_": 1410390803582287872
- }
- }
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,更新一个文档:
- 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" }
- }
- ]'
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形式,添加一批文档:
- $ 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'
$ 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,查询一批数据,返回每行数据的:关键词,查询耗时,命中数量,示例数据如下:
- "连云港通裕天然气有限公司"
- "连云港市天缘食品有限公司"
- "重庆市涪陵国有资产投资经营集团有限公司"
"连云港通裕天然气有限公司" "连云港市天缘食品有限公司" "重庆市涪陵国有资产投资经营集团有限公司"
查询脚本如下:
- curl -s http://localhost:8983/solr/webpage/query -d '
- q=content:'$1'&
- rows=0'
curl -s http://localhost:8983/solr/webpage/query -d ' q=content:'$1'& rows=0'
批处理脚本如下:
- 执行这个批处理的查询脚本,测下平均耗时:
- #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
执行这个批处理的查询脚本,测下平均耗时: #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
结果如下:
- "连云港通裕天然气有限公司" 283 7
- "连云港市天缘食品有限公司" 137 2
- "重庆市涪陵国有资产投资经营集团有限公司" 15 8