Install
- install jdk1.8, source profile
- install solr7.5, tar -zxvf package
- try to start solr
./bin/solr start
if using root user try./bin/solr start -force
then ip + port can used to visit solr’s administration user interface.
Add core
in administration user interface create a core will warning create error.
copy official config file into new core, create core in interface again.1
2
3cd /usr/solr-7.5.0/server/solr
mkdir demo
cp -r configsets/_default/conf/ demo
or use command create:1
./bin/solr create -c demo
Data import
db configuration
Create file data.xml
in solr-7.5.0/server/solr/demo/conf
column
in field represent filed in DBname
in field represent unique filed in solr1
2
3
4
5
6
7
8
9
10
11
12
13
14<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/demo"
user="demo"
password="demo"/>
<document>
<entity name="demo" query="select * from demo" >
<field column="Name" name="Name"/>
<field column="Age" name="Age"/>
<field column="Price" name="Price"/>
</entity>
</document>
</dataConfig>
modfiy solrconfig
modify solrconfig.xml
add datasource option1
2
3
4
5<requestHandler name="/dataimport" class="solr.DataImportHandler">
<lst name="defaults">
<str name="config">data.xml</str>
</lst>
</requestHandler>
modify managed-schema
modify managed-schema
add data field in searching1
2
3<field name="Name" type="string" indexed="true" stored="true"/>
<field name="Age" type="pint" indexed="false" stored="true"/>
<field name="Price" type="pdouble" indexed="false" stored="true"/>
add jar
1 | cd /usr/solr-7.5.0 |
restart solr ./bin/solr restart -force
in admin interface import data
chinese word segmentation
https://search.maven.org/search?q=g:com.github.magese1
2curl -O https://search.maven.org/remotecontent?filepath=com/github/magese/ik-analyzer/7.5.0/ik-analyzer-7.5.0.jar
cd /usr/solr-7.5.0/server/solr/demo/conf
modify managed-schema
again1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18+++++++++++++
<fieldType name="text_ik" class="solr.TextField">
<analyzer type="index">
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="false" conf="ik.conf"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="org.wltea.analyzer.lucene.IKTokenizerFactory" useSmart="true" conf="ik.conf"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<field name="Name" type="text_ik" indexed="true" stored="true" multiValued="true" />
+++++++++++++
-------------
<field name="Name" type="string" indexed="true" stored="true"/>
-------------
restart solr , then name field can be splited.
Delete data
delete in interface
In admin interface core’s document, use xml document type1
2
3<delete><query>id:1</query></delete>
<delete><query>*:*</query></delete>
<commit/>
delete in get
http://localhost:8080/solr/update/?stream.body=
http://localhost:8080/solr/update/?stream.body=
delete in post
1 | curl http://localhost:8080/update --data-binary "<delete><query>title:abc</query></delete>" -H 'Content- type :text/xml; charset=utf-8' |
Operation in java
1 | public class SolrUtils { |
https://blog.csdn.net/bljbljbljbljblj/article/details/83023125
https://blog.csdn.net/yuanlaijike/article/details/79886025
https://blog.csdn.net/m0_37595732/article/details/72830122
https://blog.csdn.net/long530439142/article/details/79353845
http://lucene.apache.org/solr/guide/7_5/query-screen.html
http://lucene.apache.org/solr/guide/7_5/the-standard-query-parser.html#the-standard-query-parser