已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SOLR使用手册1. SolrCloud安装和使用SolrCloud安装1、首先解压solr-4.4.0压缩文件,复制solr.war到tomcat的webapps下。2、启动tomcat,用来解压solr.war文件,然后关闭tomcat。3、拷贝solr-4.4.0examplelibext下的jar到webappssolrWEB-INFOlib下。webappssolrWEB-INFO下新建classes文件夹,将solr-4.4.0exampleresources的perties拷贝到classes下。4、在webappssolr下新建solr_home文件夹,把solr-4.4.0examplesolr下的所有内容拷贝到solr_home下。为了理解的方便,可以把webappssolrsolr_homecollection1conf移到webappssolrsolr_home下。5、修改webappssolrWEB-INFOweb.xml文件。添加如下内容。solr/home D:/java/apache-tomcat-6.0.32/webapps/solr/solr_homejava.lang.String6、上传solr配置文件 java -classpath d:lib*;d:libapache-solr-solrj-4.0.0.jar org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost :2181,07:2181,08:2181 -confdir E:tomcatclustercollection1conf -confname testconfclasspath:参数总是报错找不到solrj.jar,干脆把其加入classpath中;lib目录中包含solr.war中的lib包所有内容zkhost:zookeeper的服务器地址列表;confdir:solr的配置文件目录,包含schema,solrconfig等文件;confname:起个名,下面有用单机例子:java -classpath D:javaapache-tomcat-6.0.32webappssolrWEB-INFlib*;D:javaapache-tomcat-6.0.32webappssolrWEB-INFlibsolr-solrj-4.6.1.jar org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost :2181 -confdir D:javaapache-tomcat-6.0.32webappssolrsolr_homeconf -confname testconfjava -classpath D:javaapache-tomcat-6.0.32webappssolrWEB-INFlib*;D:javaapache-tomcat-6.0.32webappssolrWEB-INFlibsolr-solrj-4.4.0.jar org.apache.solr.cloud.ZkCLI -cmd upconfig -zkhost :2181 -confdir D:javaapache-tomcat-6.0.32webappssolrsolr_homeconf -confname testconf7、将上传的配置文件和collection联系起来 java -classpath d:lib*;d:libapache-solr-solrj-4.0.0.jar org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection europe-collection -confname testconf -zkhost :2181,07:2181,08:2181collection:collection的名字,后面有用,要记住单机例子:java -classpath D:javaapache-tomcat-6.0.32webappssolrWEB-INFlib*;D:javaapache-tomcat-6.0.32webappssolrWEB-INFlibsolr-solrj-4.6.1.jar org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection mycollection -confname testconf -zkhost :2181java -classpath D:javaapache-tomcat-6.0.32webappssolrWEB-INFlib*;D:javaapache-tomcat-6.0.32webappssolrWEB-INFlibsolr-solrj-4.4.0.jar org.apache.solr.cloud.ZkCLI -cmd linkconfig -collection mycollection -confname testconf -zkhost :21818、Solrcloud和zookeeper启动时绑定1、tomcatbin下新建一个setenv.bat文件,配置启动项第一台服务器:set JAVA_OPTS=-Dbootstrap_confdir=./webapps/solr/solr_home/conf -Dcollection.configName=testconf -Dhost=localhost -Djetty.port=8080 -DzkHost=localhost:2181 -DnumShards=2 -Xms512m -Xmx1024mecho %JAVA_OPTS%后续tomcat服务器:export JAVA_OPTS=-Dhost=95 -Dport=28080 -Dcollection.configName=collection1 -DzkHost=95:2181添加中文分词。IKAnalyzer2012FF_u1.jar文件拷贝到webappssolrWEB-INFlib下,IKAnalyzer.cfg.xml和stopword.dic拷贝到webappssolrWEB-INFclasses下。Schema.xml中添加如下内容: SolrCloud使用SolrCloud的集合(SolrCores)管理API添加集合 http:/localhost:8080/solr/admin/collections?action=CREATE&name=mycollection&numShards=1&replicationFactor=4 http:/localhost:8080/solr/admin/collections?action=CREATE&name=collection3&numShards=1&replicationFactor=3&maxShardsPerNode=1 参数名 说明Name 要创建的集合名称numShards 指定集合Shard的数量replicationFactor 指定每个Shard副本数量maxShardsPerNode 每个Solr服务器节点上最大Shard数量createNodeSet 还不明白什么用collection.configName 配置的名称(必须已存储在ZooKeeper)使用这个新的集合。如果没有提供创建操作将默认配置名称的集合名称。删除集合 http:/localhost:8080/solr/admin/collections?action=DELETE&name=mycollection 重新加载 http:/localhost:8080/solr/admin/collections?action=RELOAD&name=mycollection 动态添加SolrCore示例在服务运行时新添加的MyCore分布在3个Shared上面每个两个节点 http:/localhost:8080/solr/admin/collections?action=CREATE&name=MyCore&numShards=3&replicationFactor=22. Solr查询Solr常用查询参数说明1、常用查询参数说明 q - 查询字符串,必须的。 fl - 指定返回那些字段内容,用逗号或空格分隔多个。 start - 返回第一条记录在完整找到结果中的偏移位置,0开始,一般分页用。 rows - 指定返回结果最多有多少条记录,配合start来实现分页。 sort - 排序,格式:sort=+,+ 。示例:(inStock desc, price asc)表示先 “inStock” 降序, 再 “price” 升序,默认是相关性降序。 wt - (writer type)指定输出格式,可以有 xml, json, php, phps, 后面 solr 1.3增加的,要用通知我们,因为默认没有打开。 fq - (filter query)过虑查询,作用:在q查询符合结果中同时是fq查询符合的,例如:q=mm&fq=date_time:20081001 TO 20091031,找关键字mm,并且date_time是20081001到20091031之间的。官方文档:/solr/CommonQueryParameters 不常用 q.op - 覆盖schema.xml的defaultOperator(有空格时用AND还是用OR操作逻辑),一般默认指定 “OR” df - 默认的查询字段,一般默认指定 qt - (query type)指定那个类型来处理查询请求,一般不用指定,默认是standard。 其它 indent - 返回的结果是否缩进,默认关闭,用 indent=true|on 开启,一般调试json,php,phps,ruby输出才有必要用这个参数。 version - 查询语法的版本,建议不使用它,由服务器指定默认值。solrconfig.xml的配置实例查询配置(以上参数项都可以配置到该配置文件) explicit 10 edismax /使用的是solr 扩展的查询解析器 *:* sell_price:1 TO * true room_name sum(product(termfreq(room_status,dzz),1.2),1) /额外的评分字段,这个是可以影响score的打分的 /要查询的字段 room_name house_code room_code zr_house_code hire_commissioner_name broker_name rating_address resblock_name district_name subway_station_name subway_line_name /各自段分配的权重 room_name5 house_code room_code zr_house_code hire_commissioner_name broker_name rating_address resblock_name2 district_name subway_station_name subway_line_name 另外schema.xml的defaultOperator参数是个很重要的参数,默认是“OR”,意思是要查询的关键词做完分词后的词做 “OR”连接,然后再做查询,而“AND”呢,要至少全包含要搜索的关键词才行。2、Solr的检索运算符 “:” 指定字段查指定值,如返回所有值*:* “?”表示单个任意字符的通配 “*” 表示多个任意字符的通配(不能在检索的项开始使用*或者?符号) “”表示模糊检索,如检索拼写类似于”roam”的项这样写:roam将找到形如foam和roams的单词;roam0.8,检索返回相似度在0.8以上的记录。 邻近检索,如检索相隔10个单词的”apache”和”jakarta”,”jakarta apache”10 “”控制相关度检索,如检索jakarta apache,同时希望去让”jakarta”的相关度更加好,那么在其后加上”符号和增量值,即jakarta4 apache 布尔操作符AND、| 布尔操作符OR、& 布尔操作符NOT、!、-(排除操作符不能单独与项使用构成查询) “+” 存在操作符,要求符号”+”后的项必须在文档相应的域中存在 ( ) 用于构成子查询 包含范围检索,如检索某时间段记录,包含头尾,date:200707 TO 200710 不包含范围检索,如检索某时间段记录,不包含头尾 date:200707 TO 200710 转义操作符,特殊字符包括+ - & | ! ( ) ” * ? : 非空数据的查询 比如:fq=fcode: TO * 查询fcode非空的数据取反实例:fq=!fstate:13、facet查询分类统计 facet 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 * /区间统计 价格在0-100 和100-无穷大的-solr的分组查询(facet)http:/IP:port/solr/room/select?rows=0&q=bizcircle_code:XXXXXX&facet=on&facet.field=resblock_id&facet.field=resblock_name&facet.limit=3 /同一个bizcircle_code下的 前三个resblock 各自的文档数量facet使用的参考例子查询例子1、bf,tf,idf使用http:/localhost:8080/solr/collection2/select?indent=on&defType=edismax&bf=recip(rord(publishTime),1,1000,1000)1.2&sort=score%20desc&fl=title,norm(text),tf(title,%22%E9%93%B6%E8%A1%8C%22),tf(text,%27%E9%93%B6%E8%A1%8C%27),idf(text,%27%E9%93%B6%E8%A1%8C%27),publishTime,mainText,daily,score&hl=true&hl.fl=title,mainText&facet=true&facet.field=weekly&facet.mincount=1&wt=xml&q=%E9%93%B6%E8%A1%8C2、查询http:/localhost:8080/solr/ebusiness_shard1_replica1/select?q=title:%E6%89%8B%E6%9C%BA10&wt=xml&fl=*,score&hl=true&hl.fl=title&indent=true&sort=score%20desc,good%20desc,averageScore%20deschttp:/localhost:8080/solr/ebusiness_shard1_replica1/select?q=title:%E6%89%8B%E6%9C%BA&wt=xml&fl=*,score&hl=true&hl.fl=title&indent=true&defType=edismax&bq=good:1&bq=popularity:11、查询结果http:/localhost:8080/solr/collection2/select?q=title:%E4%BF%A1%E6%81%AF%20and%20(title:%E5%B7%A5%E5%95%86%20or%20title:%E9%93%B6%E8%A1%8C)&indent=on&hl=true&hl.fl=title,mainText&facet=true&facet.field=yearly&facet.field=monthly&facet.field=monthly&facet.field=daily&facet.mincount=1&wt=xml查询一个shardhttp:/localhost:8080/solr/collection2_shard1_replica1/select?q=%E4%BF%A1%E6%81%AF%E9%93%B6%E8%A1%8C&indent=on&hl=true&hl.fl=title,mainText&facet=true&facet.field=yearly&facet.field=monthly&facet.mincount=1&wt=json查询指定的Shardshttp:/localhost:8080/solr/collection3/select?q=%E4%BF%A1%E6%81%AF%E9%93%B6%E8%A1%8C&indent=on&hl=true&hl.fl=title,mainText&facet=true&facet.field=yearly&facet.field=monthly&facet.mincount=1&wt=xml&shards=localhost:8080/solr/collection1_shard1_replica2,localhost:8080/solr/collection1_shard1_replica3查询整个collectionhttp:/localhost:8080/solr/collection2/select?q=%E4%BF%A1%E6%81%AF%E9%93%B6%E8%A1%8C&indent=on&hl=true&hl.fl=title,mainText&facet=true&facet.field=yearly&facet.field=monthly&facet.mincount=1&wt=json2、core上的字段http:/localhost:8080/solr/collection2_shard1_replica1/schema/fields3、core的schemahttp:/localhost:8080/solr/collection2/schemahttp:/localhost:8080/solr/collection2_shard1_replica1/schema/collection /schema: retrieve the entire schema/collection /schema/fields: retrieve information about all defined fields, or create new fields with optional copyField directives/collection /schema/fields/name: retrieve information about a named field, or create a new named field with optional copyField directives/collection /schema/dynamicfields: retrieve information about dynamic field rules/collection /schema/dynamicfields/name: retrieve information about a named dynamic rule/collection /schema/fieldtypes: retrieve information about field types/collection /schema/fieldtypes/name: retrieve information about a named field type/collection /schema/copyfields: retrieve information about copy fields, or create new copyField directives/collection /schema/name: retrieve the schema name/collection /schema/version: retrieve the schema version/collection /schema/uniquekey: retrieve the defined uniqueKey/collection /schema/similarity: retrieve the global similarity definition/collection /schema/solrqueryparser/defaultoperator: retrieve the default operator4、SolrCloud的操作http:/localhost:8080/solr/admin/collections?action=SPLITSHARD&collection=collection1&shard=shard2http:/localhost:8080/solr/admin/collections?action=DELETESHARD&collection=collection1&shard=shard2API Entry Points/admin/collections?action=CREATE: create a collection/admin/collections?action=RELOAD: reload a collection/admin/collections?action=SPLITSHARD: split a shard into two new shards/admin/collections?action=CREATESHARD: create create a new shard/admin/collections?action=DELETESHARD: delete an inactive shard/admin/collections?action=CREATEALIAS: create or modify an alias for a collection/admin/collections?action=DELETEALIAS: delete an alias for a collection/admin/collections?action=DELETE: delete a collection/admin/collections?action=DELETEREPLICA: delete a replica5、两个RequestHandler: /browse /select6、切面搜索字段http:/localhost:8080/solr/collection2_shard1_replica1/select?q=title:%E4%BF%A1%E6%81%AF%20or%20title:%E5%B7%A5%E5%95%86&indent=on&hl=true&hl.fl=title,mainText&facet=true&facet.field=yearly&facet.field=monthly&facet.mincount=1&wt=xml&facet.query=publishTime:2013-01-01T0:0:0Z%20TO%202014-01-01T0:0:0Z&facet.query=publishTime:2012-01-01T0:0:0Z%20TO%202013-01-01T0:0:0Z3. Solr添加和更新索引XML Messages for Updating a Solr IndexSolr accepts POSTed XML messages that Add/Replace, Commit, Delete, and Delete by query, using the url/update(there is also aCSVinterface). Here is the XML syntax that Solr expects to see:Contents1. XML Messages for Updating a Solr Index1. The Update Schema1. add/replace documents1. Optional attributes for add2. Optional attributes on doc3. Optional attributes for field4. Examples of adding docs with various optional attributes2. commit and optimize1. Optional attributes for commit and optimize2. Optional attributes for commit3. Optional attributes for optimize4. Example of commit and optimize with optional attributes3. Passing commit and commitWithin parameters as part of the URL4. delete documents by ID and by Query1. Optional attributes for delete5. rollback6. prepareCommit7. Updating a Data Record via curl8. Updating via GET9. Add and delete in a single batchThe Update Schema(Not to be confused withschema.xml.)add/replace documentsSimple Example: 05991 Bridgewater Perl Java . . Subversion contains manycomplex examples of document messages.Note: multiple documents may be specified in a singlecommand.Optional attributes for add overwrite=true|false default is true, meaning newer documents will replace previously added documents with the same uniqueKey. commitWithin=(milliseconds)if the commitWithin attribute is present, the document will be added within that time.Solr1.4. SeeCommitWithin (removed inSolr4.0- use overwrite)allowDups=true|false default is false (removed inSolr4.0- use overwrite)overwritePending=true|false default is negation of allowDups (removed inSolr4.0- use overwrite)overwriteCommitted=true|false default is negation of allowDupsOptional attributes on doc boost= default is 1.0o This is a convinience mechanism equivilent to specifying aboostattribute on each of the individual fields that support norms (see below)Optional attributes for field update=add|set|inc foratomic updating and adding of fieldsSolr4.0 boost= default is 1.0 (SeeSolrRelevancyFAQ)o NOTE: make sure norms are enabled (omitNorms=false in the schema.xml) for any fields where the index-time boost should be stored.Examples of adding docs with various optional attributesExample of add with optionalboostattribute: 05991 Bridgewater Example of add with optionalupdateattribute: 05991 Walla Walla Python Example of add with optionalupdateattribute to set multiple values on a multi-valued field: 05991 Python Java Jython Example of add with optionalupdateattribute to set a field to null (i.e. delete a field): 05991 commit and optimizeA commit operation makes index changes visible to new search requests.Ahard commitalso calls fsync on the index files to ensure they have been flushed to stable storage and no data loss will result from a power failure.Asoft commitis much faster since it only makes index changes visible and does not fsync index files or write a new index descriptor. If the JVM crashes or there is a loss of power, changes that occurred after the lasthard commitwill be lost. Search collections that have near-real-time requirements (that want index changes to be quickly visible to searches) will want to soft commit often but hard commit less frequently.Anoptimizeis like ahard commitexcept that it forces all of the index segments to be merged into a single segment first. Depending on the use cases, this operation should be performed infrequently (like nightly), if at all, since it is very expensive and involves reading and re-writing theentireindex. Segments are normally merged over time anyway (as determined by the merge policy), and optimize just forces these merges to occur immediately.Example: Optional attributes for commit and optimize waitFlush=true|false default is true block until index changes are flushed to diskSolr1.4At least in Solr 1.4 and later (perhap
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中考物理复习专题1物理学史估测题课件
- 冀少版八年级生物上册第三单元第一节种子萌发的过程课件
- 幼儿印染课件教学课件
- 第四节区域经济联系教案
- 《建筑材料》教案
- 住宅小区电梯安装招标细则须知
- 绵阳市羽毛球馆租赁合同
- 印刷厂操作员聘用协议
- 教育资源共享办法
- 福州市停车场突发事件应急预案
- 知道网课智慧树《文化考察(西安工程大学)》章节测试答案
- 大数据处理和分析服务合同
- 生物制剂在肾病综合征中的应用和思考
- 2024中煤电力限公司面向中煤集团内部招聘15人重点基础提升难、易点模拟试题(共500题)附带答案详解
- 心肺复苏+AED技术
- (高清版)JTGT 3374-2020 公路瓦斯隧道设计与施工技术规范
- 2023年部编人教版五年级语文上册五单元测试卷【带答案】
- DL-T 1476-2023 电力安全工器具预防性试验规程
- 《糖尿病》“课程思政”教学设计案例
- 2022年苏教版九年级物理上册期末考试题带答案
- 电子计算机房设计规范
评论
0/150
提交评论