Full-text search technology solr (brief)

Read, read this blog suddenly finding is not good writing, solr projects should be combined in order to write easy to understand, but a bad project on this blog, so I will briefly introduce.

solr Overview

For the vast majority of projects are inseparable from the function of search, the search function is often the problem is the huge consumption of resources and their heavy loads and slow down the performance of database applications, Apache Solr can solve the above problems, Solr is a high performance, using Java5 development, while its expanded full-text search server based on Lucene, offers a much richer than Lucene query language, while achieving a configurable, scalable and optimized query performance, and provides a full-featured management interface, is a very good full-text search engine.

solr works

solr works is the use of XML documents via Http applied to a set of search queries through the collection also receive a http XML / JSON response to achieve its main features include: efficient, flexible caching capabilities, vertical search function, highlight search results to improve availability through replication index, providing a powerful Data Schema to define fields, types, and set the text analysis, Web-based management interface. to sum it up is that users can request to the search engine server via http xml format to submit certain documents to generate the index, you can also put forward by http get requests query operation to get xml / json format returns the result.

solr installation

solr need to be deployed to the server, assuming that deployed to Tomcat, first copy the dist directory under the solr solr-4.10.3.war to the next Tomcat \ webapps (can be removed for easy access to the version number), and then start automatically unpacked Tomcat war package, all the jar packages under example / lib under then solr / ext directory, solr added to the project (\ WEB-INF \ lib directory). then create a solrhome, / example / solr solr directory under is a solrhome (create solrhome position can be placed directly under the root directory). solr association and solrhome, need to modify the web.xml file solr project, the value of the label attribute specifies the location solrhome Finally start Tomcat, visit solr.

Chinese analyzer IK Analyzer

Because of the special nature of our Chinese, the word can use this word breaker, IK Analyzer is an open source, lightweight kit is based on word of java development of Chinese language.
Its use configuration is as follows:
1, to add IKAnalyzer2012FF_u1.jar lib directory solr project
2. create WEB-INF / classes folder extended dictionary, stop word dictionary, the configuration file into the WEB-INF / classes directory under project solr
3, modifying the file Solrhome schema.xml, configuration a FieldType, using IKAnalyzer



configuration domain:
a domain corresponding to fields of the database table, storing user data, the user according to the service needs to define the relevant field (domain), in general, each corresponding to a data, on the same user the same kinds of data operations.
common property domain:
name: Specifies the name of the domain
type: Specifies the domain of
indexed: whether the index
stored: whether to store
required: must
multiValued: whether the multi-valued
then there are the replication domain (the one field data in a copy to another domain), dynamic domain (we need to dynamically expand the field, we need to use Domain state) and the like.

Spring Data Solr Profile

In a real project we generally use a spring frame, then solr can also be integrated into the spring, it is the use of spring data solr.
Use steps: The first step is to introduce jar package dependencies;
then create a profile, the following key elements:

<!--url应根据自己实际项目的地址填写-->
<solr:solr-server id="solrServer" url="http://localhost:8080/solr" />
<!-- solr 模板,使用 solr 模板可对索引库进行 CRUD 的操作 -->
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
<constructor-arg ref="solrServer" />
</bean>

Our project entity class attributes using annotations @Field identity, if the domain name attributes defined in the configuration file called inconsistent, you need to specify the domain name in the comment.
Will be able to perform CRUD operations when the bean object solrTemplate of dependency injection.

These are the basic introduction solr using solr in the actual project is very complex, because of my limited ability coupled with constraints can only be written in this way, if you want to learn more please access to information on their own.

Guess you like

Origin blog.csdn.net/keyto1/article/details/88959562