Apache Solr 是一个无模式(スキーマレス)且支持高亮的搜索引擎
有很多关于Solr模式的解释在网上,但是对于搜索各种不同类型的文档文件有些不自然,所以尝试了无模式的操作。现在将记录下无模式和高亮显示的设置方法作为备忘录。虽然不确定是否是正确的设置方法,但将作为未来考虑的参考。
用中文将以下内容转述一遍,只需要一个选项:
将解压缩后的Solr8.1.1文件夹表示为$SOLR_HOME。
使用无模式启动
$SOLR_HOME>bin\solr.cmd start -e schemaless
Creating Solr home directory $SOLR_HOME\example\schemaless\solr
Starting up Solr on port 8983 using command:
"$SOLR_HOME\bin\solr.cmd" start -p 8983 -s "$SOLR_HOME\example\schemaless\solr"
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
Created new core 'gettingstarted'
Solr schemaless example launched successfully. Direct your Web browser to http://localhost:8983/solr to visit the Solr Admin UI
为了修改「solrconfig.xml」文件,需要停止 Solr。
$SOLR_HOME>bin\solr.cmd stop -all
Stopping Solr process 10112 running on port 8983
请编辑$SOLR_HOME\example\schemaless\solr\gettingstarted\conf\solrconfig.xml。
现在删除requestHandler函数
<削除する箇所>
<requestHandler name="/update/extract"
startup="lazy"
class="solr.extraction.ExtractingRequestHandler" >
<lst name="defaults">
<str name="lowernames">true</str>
<str name="fmap.content">_text_</str>
</lst>
</requestHandler>
请在下面添加内容。
<requestHandler name="/update/extract"
startup="lazy"
class="solr.extraction.ExtractingRequestHandler" >
<lst name="defaults">
<str name="xpath">/xhtml:html/xhtml:body/descendant:node()</str>
<str name="capture">content</str>
<str name="fmap.meta">attr_meta_</str>
<str name="uprefix">attr_</str>
<str name="lowernames">true</str>
</lst>
</requestHandler>
重新启动Solr。
$SOLR_HOME>bin\solr.cmd start -e schemaless
Solr home directory $SOLR_HOME\example\schemaless\solr already exists.
Starting up Solr on port 8983 using command:
"$SOLR_HOME\bin\solr.cmd" start -p 8983 -s "$SOLR_HOME\example\schemaless\solr"
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!
WARNING: Core 'gettingstarted' already exists!
Checked core existence using Core API command:
http://localhost:8983/solr/admin/cores?action=STATUS&core=gettingstarted
Solr schemaless example launched successfully. Direct your Web browser to http://localhost:8983/solr to visit the Solr Admin UI
导入文档文件
$SOLR_HOME>java -jar -Dc=gettingstarted -Dauto example\exampledocs\post.jar C:\Users\Documents\*.pdf
※文档文件将根据环境适时进行适当转换。
用带有高亮的方式尝试查询一下。
当打开Solr的管理界面并将http://localhost:8983/solr/gettingstarted/select?fl=id&hl.fl=attr_content&hl=on&q=attr_content%3Asolr作为查询条件时,所期望的响应将会显示出来。
重点在于将查询字段设置为“attr_content”,将高亮字段也设置为“attr_content”。