solr学习笔记

栏目: 后端 · 发布时间: 6年前

内容简介:1 下载地址wgettar -zxvf solr-8.1.0.tgz

1 下载地址 http://lucene.apache.org/solr/

wget https://mirrors.tuna.tsinghua...

tar -zxvf solr-8.1.0.tgz

2 运行 停止

切换到目录(solr-8.1.0/bin) ./solr start -force ./solr start -p 9529 -force

(指定端口) ./solr stop -all 启动错误提示 Your Max Processes Limit is currently

将solr-8.1.0/bin/solr.in.sh文件中,SOLR_ULIMIT_CHECKS设置为false 浏览器输入

http://127.0.0.1 :9529/solr

3 修改时区

修改文件 solr-8.1.0/bin/solr.in.sh

4 创建core实例

首先去目录solr-8.1.0/server/solr/ 创建一个名字为new_core的文件夹(如:fgou)

然后拷贝把目录solr-8.1.0/server/configsets/basic_configs下的conf目录拷贝到fgou目录下

cp -r /usr/local/src/solr-8.1.0/server/solr/configsets/_default/conf

/usr/local/src/solr-8.1.0/server/solr/fgou/ 然后再点击创建即可

solr学习笔记

5 配置中文分词

下载IK分词器 https://pan.baidu.com/s/1fZ52... 提取码:f76c

IKAnalyzer下载后解压会有如下文件

solr学习笔记

把核心jar文件复制到solr WEB应用的lib文件夹下 solr学习笔记

把配置文件和词库等文件复制到WEB应用的classes文件夹下,如果子WEB-INF下没有这个文件夹自己创建即可 solr学习笔记

在配置文件managed-schema中增加如下配置

<fieldType name="fgou_ik" class="solr.TextField">
    <analyzer type="index">
      <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true"/>
    </analyzer>
</fieldType>

重启服务 这样就可以选择到ik分词了,为gname创建个

solr学习笔记

6 导入 MYSQL 数据

首先在D:serversolr-7.4.0dist目录下复制如下的jar包

solr学习笔记

复制到 D:serversolr-7.4.0serversolr-webappwebappWEB-INFlib

再到 https://search.maven.org/sear...

复制到D:serversolr-7.4.0serversolr-webappwebappWEB-INFlib目录下

在D:serversolr-7.4.0serversolrfgouconfsolrconfig.xml配置数据库文件信息

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">

<lst name="defaults">
      <str name="config">fgou-config.xml</str>
  </lst>

</requestHandler>

创建fgou-config.xml文件

<?xml version="1.0" encoding="UTF-8" ?>

<dataConfig>

<dataSource typ="JdbcDataSource"

driver="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://127.0.0.1/fgou?useSSL=true&serverTimezone=UTC&verifyServerCertificate=false&allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8"
user="root"
password="hufeng"

/>

<document>

<entity pk="gid" dataSource="JdbcDataSource" name="goods" query="select gid,gname,group_price,sell_num,status from goods where status=1" 
        deltaQuery="select gid from goods where status = 1 and addtime > '${dataimporter.last_index_time}'" #新增修改索引
        deletedPkQuery="select gid from goods where status != 1 and addtime > '${dataimporter.last_index_time}'" #删除索引             
        deltaImportQuery="select gid,gname,group_price,sell_num,status from goods where gid='${dataimporter.delta.gid}'"
>
    <field column="gid" name="gid"/>
    <field column="gname" name="gname"/>
    <field column="group_price" name="group_price"/>
    <field column="sell_num" name="sell_num"/>
    <field column="status" name="status"/>
</entity>

</document>

</dataConfig>

在managed-schema中配置字段检索使用的分词器

修改:<uniqueKey>gid</uniqueKey>

新增:

<field name="goods" type="fgou_ik" uninvertible="true" indexed="true" stored="true"/>

<field name="gid" type="string" multiValued="false" indexed="true" required="true" stored="true"/>

<field name="gname" type="fgou_ik" indexed="true" stored="true"/>

<field name="group_price" type="pdouble" indexed="true" stored="true"/>

<field name="sell_num" type="pint" indexed="true" stored="true"/>

<field name="status" type="pint" indexed="true" stored="true"/>

重启服务

建立全量索引

solr学习笔记

建立增量索引

solr学习笔记

查询

solr学习笔记

7 php api调用

> //solr 查询 
> public function solrQuery($core='fgou',$fl='gid',$fq='status:1',$q='gid:1',$sort='gid desc,sell desc',$start=0,$rows=10){
>     $fl = urlencode($fl);
>     $fq = urlencode($fq);
>     $q = urlencode($q);
>     $sort = urlencode($sort);
>     $url = 'http://127.0.0.1:9529/solr/'.$core.'/select?fl='.$fl.'&fq='.$fq.'&q='.$q.'&sort='.$sort.'&rows='.$rows.'&start='.$start;
>     $res = file_get_contents($url);
>     $resArr = json_decode($res,true);
>     return $resArr['response']; } 
>    //solr 更新索引 
public function solrIndex($core='fgou'){
>     $url = 'http://127.0.0.1:9529/solr/fgou/dataimport?indent=on&wt=json';
>     $param = [
>         'command'=>'delta-import',
>         'verbose'=>'false',
>         'clean'=>'false',
>         'commit'=>'true',
>         'core'=>$core,
>         'name'=>'dataimport',
>     ];
>     $this->httpCurl($url,$param); }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Programming Rust

Programming Rust

Jim Blandy / O'Reilly Media / 2016-8-25 / GBP 47.99

This practical book introduces systems programmers to Rust, the new and cutting-edge language that’s still in the experimental/lab stage. You’ll learn how Rust offers the rare and valuable combination......一起来看看 《Programming Rust》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具