Hello Solr,
1 Solr 安装
skip2. 启动 测试
[plcm@pdmstest bin]$ ./solr start
Warning: Available entropy is low. As a result, use of the UUIDField, SSL, or any other features that require
RNG might not work properly. To check for the amount of available entropy, use 'cat /proc/sys/kernel/random/entropy_avail'.
Waiting up to 180 seconds to see Solr running on port 8983 [\]
Started Solr server on port 8983 (pid=12173). Happy searching!
3 创建core
[plcm@pdmstest bin]$ ./solr create -c pdmsWARNING: Using _default configset. Data driven schema functionality is enabled by default, which is
NOT RECOMMENDED for production use.
To turn it off:
curl http://localhost:8983/solr/pdms/config -d '{"set-user-property": {"update.autoCreateFields":"false"}}'
Created new core 'pdms'
4. 创建document
[plcm@pdmstest bin]$ ./post -c pdms hellosolr.json
/etc/alternatives/jre/bin/java -classpath /home/plcm/Downloads/solr-7.1.0/dist/solr-core-7.1.0.jar -Dauto=yes -Dc=pdms -Ddata=files org.apache.solr.util.SimplePostTool hellosolr.json
SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/pdms/update...
Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
POSTing file hellosolr.json (application/json) to [base]/json/docs
1 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/pdms/update...
Time spent: 0:00:00.970
内容如下:
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
5. 测试
5.1 q 参数测试
http://localhost:8983/solr/pdms/select?q=*:* q为查询参数,格式为fieldname:value,此处为查询所有的内容"response":{"numFound":53,"start":0,"docs":[
{
"glossary.title":["example glossary"],
"glossary.GlossDiv.title":["S"],
"glossary.GlossDiv.GlossList.GlossEntry.ID":["SGML"],
"glossary.GlossDiv.GlossList.GlossEntry.SortAs":["SGML"],
"glossary.GlossDiv.GlossList.GlossEntry.GlossTerm":["Standard Generalized Markup Language"],
"glossary.GlossDiv.GlossList.GlossEntry.Acronym":["SGML"],
"glossary.GlossDiv.GlossList.GlossEntry.Abbrev":["ISO 8879:1986"],
"glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para":["A meta-markup language, used to create markup languages such as DocBook."],
"glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso":["GML",
"XML"],
"glossary.GlossDiv.GlossList.GlossEntry.GlossSee":["markup"],
"id":"41e48ee2-7d6f-462b-8cab-ac9f9ff55e92",
"glossary.GlossDiv.GlossList.GlossEntry.GlossTerm_str":["Standard Generalized Markup Language"],
"glossary.GlossDiv.GlossList.GlossEntry.SortAs_str":["SGML"],
"glossary.GlossDiv.GlossList.GlossEntry.GlossSee_str":["markup"],
"glossary.GlossDiv.title_str":["S"],
"glossary.GlossDiv.GlossList.GlossEntry.ID_str":["SGML"],
"glossary.GlossDiv.GlossList.GlossEntry.Abbrev_str":["ISO 8879:1986"],
"glossary.GlossDiv.GlossList.GlossEntry.Acronym_str":["SGML"],
"glossary.title_str":["example glossary"],
"glossary.GlossDiv.GlossList.GlossEntry.GlossDef.para_str":["A meta-markup language, used to create markup languages such as DocBook."],
"_version_":1581589565074833408,
"glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso_str":["GML",
"XML"]},
{
"id":"0553573403",
"cat":["book"],
"name":["A Game of Thrones"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":1,
"genre_s":"fantasy",
"name_str":["A Game of Thrones"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155912806400,
"author_str":["George R.R. Martin"]},
{
"id":"0553579908",
"cat":["book"],
"name":["A Clash of Kings"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":2,
"genre_s":"fantasy",
"name_str":["A Clash of Kings"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155932729344,
"author_str":["George R.R. Martin"]},
{
"id":"055357342X",
"cat":["book"],
"name":["A Storm of Swords"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":3,
"genre_s":"fantasy",
"name_str":["A Storm of Swords"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155934826496,
"author_str":["George R.R. Martin"]},
{
"id":"0553293354",
"cat":["book"],
"name":["Foundation"],
"price":[7.99],
"inStock":[true],
"author":["Isaac Asimov"],
"series_t":["Foundation Novels"],
"sequence_i":1,
"genre_s":"scifi",
"name_str":["Foundation"],
"cat_str":["book"],
"series_t_str":["Foundation Novels"],
"_version_":1581590155937972224,
"author_str":["Isaac Asimov"]},
{
"id":"0812521390",
"cat":["book"],
"name":["The Black Company"],
"price":[6.99],
"inStock":[false],
"author":["Glen Cook"],
"series_t":["The Chronicles of The Black Company"],
"sequence_i":1,
"genre_s":"fantasy",
"name_str":["The Black Company"],
"cat_str":["book"],
"series_t_str":["The Chronicles of The Black Company"],
"_version_":1581590155940069376,
"author_str":["Glen Cook"]},
{
"id":"0812550706",
"cat":["book"],
"name":["Ender's Game"],
"price":[6.99],
"inStock":[true],
"author":["Orson Scott Card"],
"series_t":["Ender"],
"sequence_i":1,
"genre_s":"scifi",
"name_str":["Ender's Game"],
"cat_str":["book"],
"series_t_str":["Ender"],
"_version_":1581590155943215104,
"author_str":["Orson Scott Card"]},
{
"id":"0441385532",
"cat":["book"],
"name":["Jhereg"],
"price":[7.95],
"inStock":[false],
"author":["Steven Brust"],
"series_t":["Vlad Taltos"],
"sequence_i":1,
"genre_s":"fantasy",
"name_str":["Jhereg"],
"cat_str":["book"],
"series_t_str":["Vlad Taltos"],
"_version_":1581590155945312256,
"author_str":["Steven Brust"]},
{
"id":"0380014300",
"cat":["book"],
"name":["Nine Princes In Amber"],
"price":[6.99],
"inStock":[true],
"author":["Roger Zelazny"],
"series_t":["the Chronicles of Amber"],
"sequence_i":1,
"genre_s":"fantasy",
"name_str":["Nine Princes In Amber"],
"cat_str":["book"],
"series_t_str":["the Chronicles of Amber"],
"_version_":1581590155948457984,
"author_str":["Roger Zelazny"]},
{
"id":"0805080481",
"cat":["book"],
"name":["The Book of Three"],
"price":[5.99],
"inStock":[true],
"author":["Lloyd Alexander"],
"series_t":["The Chronicles of Prydain"],
"sequence_i":1,
"genre_s":"fantasy",
"name_str":["The Book of Three"],
"cat_str":["book"],
"series_t_str":["The Chronicles of Prydain"],
"_version_":1581590155950555136,
"author_str":["Lloyd Alexander"]}]
}}
field:name 查询条件中,value不是模糊匹配,不区分大小写,此处由于空格,所以kings被分割开了,其实是准确匹配。 测试如下: http://localhost:8983/solr/pdms/select?q=name:kings
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"name:kings"}},
"response":{"numFound":1,"start":0,"docs":[
{
"id":"0553579908",
"cat":["book"],
"name":["A Clash of Kings"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":2,
"genre_s":"fantasy",
"name_str":["A Clash of Kings"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155932729344,
"author_str":["George R.R. Martin"]}]
}}
5.2 fl参数测试
返回指定字段,fl参数可用于在响应中选择有限的字段集。 这将有助于限制通过系统的数据量,并降低I / O成本。测试如下: http://localhost:8983/solr/pdms/select?q=*:*&fl=id,cat,name{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"fl":"id,cat,name"}},
"response":{"numFound":53,"start":0,"docs":[
{
"id":"41e48ee2-7d6f-462b-8cab-ac9f9ff55e92"},
{
"id":"0553573403",
"cat":["book"],
"name":["A Game of Thrones"]},
{
"id":"0553579908",
"cat":["book"],
"name":["A Clash of Kings"]},
{
"id":"055357342X",
"cat":["book"],
"name":["A Storm of Swords"]},
{
"id":"0553293354",
"cat":["book"],
"name":["Foundation"]},
{
"id":"0812521390",
"cat":["book"],
"name":["The Black Company"]},
{
"id":"0812550706",
"cat":["book"],
"name":["Ender's Game"]},
{
"id":"0441385532",
"cat":["book"],
"name":["Jhereg"]},
{
"id":"0380014300",
"cat":["book"],
"name":["Nine Princes In Amber"]},
{
"id":"0805080481",
"cat":["book"],
"name":["The Book of Three"]}]
}}
5.3 Facet功能测试
这个是搜索铁观音这个词,统计了分类和品牌2个侧面(分组),铁观音在生活分类下有64个,茗茶里面48……
上面这个说到底,就是某一类型的标签统计,比如xxx年热词等等,只要有记录,也能统计出来,当然,超大数据量提前优化好solr的性能。
介绍了一下facet之后,来说说怎么实现facet。facet的实现其实很简单,主要在搜索参数上带上就OK。
facet=on/true #代表开启facet
facet.field=cate #代表要统计的面(分组),比如上面的分类,品牌,可以多次出现
facet.limit =20 #每个分组最多返回条数
facet.mincount = 1 #这个表示分组下某一条目的最小数据量
facet.missing = on/true #统计null的值
facet.method = #默认为fc, fc表示Field Cache
http://localhost:8983/solr/pdms/select?q=name:a&facet=true&facet.field=name
返回name中包含a的结果,共计四条,在facet结果中,对name进行了分词,所以出现a的次数为4
{
"responseHeader":{
"status":0,
"QTime":112,
"params":{
"q":"name:a",
"facet.field":"name",
"facet":"true"}},
"response":{"numFound":4,"start":0,"docs":[
{
"id":"0553573403",
"cat":["book"],
"name":["A Game of Thrones"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":1,
"genre_s":"fantasy",
"name_str":["A Game of Thrones"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155912806400,
"author_str":["George R.R. Martin"]},
{
"id":"0553579908",
"cat":["book"],
"name":["A Clash of Kings"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":2,
"genre_s":"fantasy",
"name_str":["A Clash of Kings"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155932729344,
"author_str":["George R.R. Martin"]},
{
"id":"055357342X",
"cat":["book"],
"name":["A Storm of Swords"],
"price":[7.99],
"inStock":[true],
"author":["George R.R. Martin"],
"series_t":["A Song of Ice and Fire"],
"sequence_i":3,
"genre_s":"fantasy",
"name_str":["A Storm of Swords"],
"cat_str":["book"],
"series_t_str":["A Song of Ice and Fire"],
"_version_":1581590155934826496,
"author_str":["George R.R. Martin"]},
{
"id":"VDBDB1A16",
"name":["A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM"],
"manu":["A-DATA Technology Inc."],
"manu_id_s":"corsair",
"cat":["electronics",
"memory"],
"features":["CAS latency 3, 2.7v"],
"popularity":[0],
"inStock":[true],
"store":["45.18414,-93.88141"],
"manufacturedate_dt":"2006-02-13T15:26:37Z",
"payloads":["electronics|0.9 memory|0.1"],
"name_str":["A-DATA V-Series 1GB 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) System Memory - OEM"],
"features_str":["CAS latency 3, 2.7v"],
"store_str":["45.18414,-93.88141"],
"cat_str":["electronics",
"memory"],
"manu_str":["A-DATA Technology Inc."],
"payloads_str":["electronics|0.9 memory|0.1"],
"_version_":1581590156797804544}]
},
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"name":[
"a",4,
"of",3,
"184",1,
"1gb",1,
"3200",1,
"400",1,
"clash",1,
"data",1,
"ddr",1,
"game",1,
"kings",1,
"memory",1,
"oem",1,
"pc",1,
"pin",1,
"sdram",1,
"series",1,
"storm",1,
"swords",1,
"system",1,
"thrones",1,
"unbuffered",1,
"v",1,
"11",0,
"133",0,
"19",0,
"2",0,
"2.0",0,
"250",0,
"256",0,
"2dhtv",0,
"2gb",0,
"300",0,
"3007wfp",0,
"500",0,
"512",0,
"60",0,
"8",0,
"action",0,
"all",0,
"amber",0,
"apple",0,
"asus",0,
"ata",0,
"ati",0,
"belkin",0,
"black",0,
"book",0,
"british",0,
"cable",0,
"canon",0,
"card",0,
"cauldron",0,
"channel",0,
"characters",0,
"company",0,
"cord",0,
"corsair",0,
"dell",0,
"diamondmax",0,
"display",0,
"dock",0,
"dollar",0,
"drive",0,
"dual",0,
"edition",0,
"encoded",0,
"ender's",0,
"enterprise",0,
"euro",0,
"extreme",0,
"falling",0,
"flat",0,
"for",0,
"foundation",0,
"gb",0,
"gb18030",0,
"go",0,
"greek",0,
"hard",0,
"in",0,
"ipod",0,
"jhereg",0,
"kit",0,
"krone",0,
"lightning",0,
"lucene",0,
"maxtor",0,
"mb",0,
"mini",0,
"mobile",0,
"monsters",0,
"mp500",0,
"n7800gtx",0,
"nine",0,
"oh",0,
"one",0,
"p120",0,
"panel",0,
"pcie",0]},
"facet_ranges":{},
"facet_intervals":{},
"facet_heatmaps":{}}}
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。