search
HomeDatabaseMysql TutorialSolr学习(2) Solr4.2.0+IK Analyzer 2012

solr列子下载 Solr学习(二) Solr4.2.0IK Analyzer 2012 开场白: 本章简单讲述如何在solr中配置著名的 IK Analyzer 分词器。 本章建立在Solr学习(一) 基础上进行配置。 通过(一)的介绍,目前已经成功部署好单实例 solrtomcat 声明:描述的比较统繁琐,有偏

solr列子下载

Solr学习(二) Solr4.2.0+IK Analyzer 2012

开场白:

本章简单讲述如何在solr中配置著名的 IK Analyzer 分词器。

本章建立在 Solr学习(一)  基础上进行配置。

通过(一)的介绍,目前已经成功部署好单实例 solr+tomcat 

 

声明:描述的比较笼统繁琐,有偏差的地方请大家毫不留情的拍砖Solr学习(2) Solr4.2.0+IK Analyzer 2012

 

准备工作:

下载 IK Analyzer 2012FF_hf1.zip包。 详见:IK Analyzer中文分词器创始人 林良益 博客 

 

名词解释:

IK源目录:解压缩IK Analyzer 2012FF_hf1.zip后得到的文件夹路径。解压缩后得到下图结构东东


Solr学习(2) Solr4.2.0+IK Analyzer 2012

IK三把刀:上图被选中的3个文件(IKAnalyzer.cfg.xml、IKAnalyzer2012FF_u1.jar、stopword.dic)

Tomcat :以下全部指 tomcat根目录。(例:E:\\apache-tomcat-6.0.35\\)。

 

开始生产

 

    步骤1:将 IK三把刀”放入目录...\Tomcat\webapps\solr\WEB-INF\lib中,(注意!这里此时由于项目原来启动过一次,webapps下的solr.war包已经被成功发布部署成文solr文件夹了。所以这里是在solr文件内打开 WEB-INF\lib目录, 不然WAR包是不允许放入文件到特定目录)。

    

     步骤2:开始设置IK分词器在schema.xml文件中的配置(schema.xml目录位置在 ...\Tomcat\solrapp\solr\collection1\conf此处的 collection1 是默认的文件夹,有些朋友在先前配置时候会去改变此文件夹名称,请注意自行匹配);

打开schema.xml文件(尽量使用UE打开,防止乱码)在中增加如下内容

 

<a target="_blank" href="http://item.taobao.com/item.htm?_u=gl4f5o5c437&id=39393009617"><span style="font-family:SimSun, 宋体, tahoma, arial, helvetica, sans-serif;font-size:14px;"><a target="_blank" href="http://item.taobao.com/item.htm?spm=a1z09.5.0.0.xZsiWo&id=23853332746&_u=tl4f5o5d7e5&qq-pf-to=pcqq.c2c"><fieldtype name="text_ik" class="solr.TextField">  
    <analyzer type="index" ismaxwordlength="false" class="org.wltea.analyzer.lucene.IKAnalyzer"></analyzer>  
    <analyzer type="query" ismaxwordlength="true" class="org.wltea.analyzer.lucene.IKAnalyzer"></analyzer>  
</fieldtype></a></span></a>

 

 

这样就OK了。 增加了用 IK分词算法提供的字段类型。 (IK分词算法的其他扩展配置请自行参考IK算法的配置说明文档。在“IK三把刀”目录里头的PDF文件里有。

 

测试阶段

 

 可能一些朋友会想看看效果,确认一下IK分词器成功配置,接下来我们来尝试测试一下IK分词效果吧。  

(看到此处的朋友,其实可以跳到看 schema.xml的具体字段说明文章去。 大概了解一下schema.xml是干嘛用的,不过不看也无妨,我们只是为了证明IK配置成功。)

 

    我们在 schema.xml 文件里头。找到如下代码片段。(schema.xml文件在哪里?看步骤2 ...

<a target="_blank" href="http://item.taobao.com/item.htm?_u=gl4f5o5c437&id=39393009617"></a><a target="_blank" href="http://item.taobao.com/item.htm?spm=a1z09.5.0.0.xZsiWo&id=23853332746&_u=tl4f5o5d7e5&qq-pf-to=pcqq.c2c"><field name="name" type="text_general" indexed="true" stored="true"></field></a>

    意思是这里有一个字段标示名字叫做name,类型text_general,这个时候我们把类型改变成刚刚添加的IK类型text_ik; 变成:

 

<a target="_blank" href="http://item.taobao.com/item.htm?_u=gl4f5o5c437&id=39393009617"></a><a target="_blank" href="http://item.taobao.com/item.htm?spm=a1z09.5.0.0.xZsiWo&id=23853332746&_u=tl4f5o5d7e5&qq-pf-to=pcqq.c2c"><field name="name" type="text_ik" indexed="true" stored="true"></field> </a>

   瞎扯:我想看到这里一些朋友应该就能明白schema.xml干嘛的吧。Schema.xml 就像一张很大很大的描述索引样子的表。里头有很多字段field,然后要定义字段的类型fieldType。在在field里头引用fieldType(有点springIOC的味道 - -..)。 

 

 

启动tomcat ..

进入solr界面 http://localhost:8080/solr 

 

新手可能对solr的界面还不熟悉。我这里截图说明下。

选择core (这里没有默认配置。要去选一个);我们这里选 collection1


Solr学习(2) Solr4.2.0+IK Analyzer 2012
 

 然后再选择 analysis 

 

 
Solr学习(2) Solr4.2.0+IK Analyzer 2012
这个是分词界面。

选择刚刚我们针对配置的 name 字段。 然后输入要分词的词语 魔兽世界 ,点按钮 analyse values会发现出现了分词为  “魔兽”“世界”


Solr学习(2) Solr4.2.0+IK Analyzer 2012
 
我们再试试其他没有引用分词器的字段的分词效果。 我选择了 “content” 字段,出现的结果就是全字分词了(solr默认的一种分词方式)。


Solr学习(2) Solr4.2.0+IK Analyzer 2012
 
结束!!!  

这里分词的多样化根据分词器来设定。。   个人喜欢使用IK Analyzer分词器;而且配置SOLR比较方便。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are some tools you can use to monitor MySQL performance?What are some tools you can use to monitor MySQL performance?Apr 23, 2025 am 12:21 AM

How to effectively monitor MySQL performance? Use tools such as mysqladmin, SHOWGLOBALSTATUS, PerconaMonitoring and Management (PMM), and MySQL EnterpriseMonitor. 1. Use mysqladmin to view the number of connections. 2. Use SHOWGLOBALSTATUS to view the query number. 3.PMM provides detailed performance data and graphical interface. 4.MySQLEnterpriseMonitor provides rich monitoring functions and alarm mechanisms.

How does MySQL differ from SQL Server?How does MySQL differ from SQL Server?Apr 23, 2025 am 12:20 AM

The difference between MySQL and SQLServer is: 1) MySQL is open source and suitable for web and embedded systems, 2) SQLServer is a commercial product of Microsoft and is suitable for enterprise-level applications. There are significant differences between the two in storage engine, performance optimization and application scenarios. When choosing, you need to consider project size and future scalability.

In what scenarios might you choose SQL Server over MySQL?In what scenarios might you choose SQL Server over MySQL?Apr 23, 2025 am 12:20 AM

In enterprise-level application scenarios that require high availability, advanced security and good integration, SQLServer should be chosen instead of MySQL. 1) SQLServer provides enterprise-level features such as high availability and advanced security. 2) It is closely integrated with Microsoft ecosystems such as VisualStudio and PowerBI. 3) SQLServer performs excellent in performance optimization and supports memory-optimized tables and column storage indexes.

How does MySQL handle character sets and collations?How does MySQL handle character sets and collations?Apr 23, 2025 am 12:19 AM

MySQLmanagescharactersetsandcollationsbyusingUTF-8asthedefault,allowingconfigurationatdatabase,table,andcolumnlevels,andrequiringcarefulalignmenttoavoidmismatches.1)Setdefaultcharactersetandcollationforadatabase.2)Configurecharactersetandcollationfor

What are triggers in MySQL?What are triggers in MySQL?Apr 23, 2025 am 12:11 AM

A MySQL trigger is an automatically executed stored procedure associated with a table that is used to perform a series of operations when a specific data operation is performed. 1) Trigger definition and function: used for data verification, logging, etc. 2) Working principle: It is divided into BEFORE and AFTER, and supports row-level triggering. 3) Example of use: Can be used to record salary changes or update inventory. 4) Debugging skills: Use SHOWTRIGGERS and SHOWCREATETRIGGER commands. 5) Performance optimization: Avoid complex operations, use indexes, and manage transactions.

How do you create and manage user accounts in MySQL?How do you create and manage user accounts in MySQL?Apr 22, 2025 pm 06:05 PM

The steps to create and manage user accounts in MySQL are as follows: 1. Create a user: Use CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password'; 2. Assign permissions: Use GRANTSELECT, INSERT, UPDATEONmydatabase.TO'newuser'@'localhost'; 3. Fix permission error: Use REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost'; then reassign permissions; 4. Optimization permissions: Use SHOWGRA

How does MySQL differ from Oracle?How does MySQL differ from Oracle?Apr 22, 2025 pm 05:57 PM

MySQL is suitable for rapid development and small and medium-sized applications, while Oracle is suitable for large enterprises and high availability needs. 1) MySQL is open source and easy to use, suitable for web applications and small and medium-sized enterprises. 2) Oracle is powerful and suitable for large enterprises and government agencies. 3) MySQL supports a variety of storage engines, and Oracle provides rich enterprise-level functions.

What are the disadvantages of using MySQL compared to other relational databases?What are the disadvantages of using MySQL compared to other relational databases?Apr 22, 2025 pm 05:49 PM

The disadvantages of MySQL compared to other relational databases include: 1. Performance issues: You may encounter bottlenecks when processing large-scale data, and PostgreSQL performs better in complex queries and big data processing. 2. Scalability: The horizontal scaling ability is not as good as Google Spanner and Amazon Aurora. 3. Functional limitations: Not as good as PostgreSQL and Oracle in advanced functions, some functions require more custom code and maintenance.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function