Home Database Mysql Tutorial Solr学习(2) Solr4.2.0+IK Analyzer 2012

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

Jun 07, 2016 pm 03:27 PM
solr study

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>
Copy after login

 

 

这样就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>
Copy after login

    意思是这里有一个字段标示名字叫做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>
Copy after login

   瞎扯:我想看到这里一些朋友应该就能明白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 of this Website
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

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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1670
14
PHP Tutorial
1274
29
C# Tutorial
1256
24
Learn to completely uninstall pip and use Python more efficiently Learn to completely uninstall pip and use Python more efficiently Jan 16, 2024 am 09:01 AM

No more need for pip? Come and learn how to uninstall pip effectively! Introduction: pip is one of Python's package management tools, which can easily install, upgrade and uninstall Python packages. However, sometimes we may need to uninstall pip, perhaps because we wish to use another package management tool, or because we need to completely clear the Python environment. This article will explain how to uninstall pip efficiently and provide specific code examples. 1. How to uninstall pip The following will introduce two common methods of uninstalling pip.

A deep dive into matplotlib's colormap A deep dive into matplotlib's colormap Jan 09, 2024 pm 03:51 PM

To learn more about the matplotlib color table, you need specific code examples 1. Introduction matplotlib is a powerful Python drawing library. It provides a rich set of drawing functions and tools that can be used to create various types of charts. The colormap (colormap) is an important concept in matplotlib, which determines the color scheme of the chart. In-depth study of the matplotlib color table will help us better master the drawing functions of matplotlib and make drawings more convenient.

Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Getting Started with Pygame: Comprehensive Installation and Configuration Tutorial Feb 19, 2024 pm 10:10 PM

Learn Pygame from scratch: complete installation and configuration tutorial, specific code examples required Introduction: Pygame is an open source game development library developed using the Python programming language. It provides a wealth of functions and tools, allowing developers to easily create a variety of type of game. This article will help you learn Pygame from scratch, and provide a complete installation and configuration tutorial, as well as specific code examples to get you started quickly. Part One: Installing Python and Pygame First, make sure you have

Let's learn how to input the root number in Word together Let's learn how to input the root number in Word together Mar 19, 2024 pm 08:52 PM

When editing text content in Word, you sometimes need to enter formula symbols. Some guys don’t know how to input the root number in Word, so Xiaomian asked me to share with my friends a tutorial on how to input the root number in Word. Hope it helps my friends. First, open the Word software on your computer, then open the file you want to edit, and move the cursor to the location where you need to insert the root sign, refer to the picture example below. 2. Select [Insert], and then select [Formula] in the symbol. As shown in the red circle in the picture below: 3. Then select [Insert New Formula] below. As shown in the red circle in the picture below: 4. Select [Radical Formula], and then select the appropriate root sign. As shown in the red circle in the picture below:

Revealing the appeal of C language: Uncovering the potential of programmers Revealing the appeal of C language: Uncovering the potential of programmers Feb 24, 2024 pm 11:21 PM

The Charm of Learning C Language: Unlocking the Potential of Programmers With the continuous development of technology, computer programming has become a field that has attracted much attention. Among many programming languages, C language has always been loved by programmers. Its simplicity, efficiency and wide application make learning C language the first step for many people to enter the field of programming. This article will discuss the charm of learning C language and how to unlock the potential of programmers by learning C language. First of all, the charm of learning C language lies in its simplicity. Compared with other programming languages, C language

Learn the main function in Go language from scratch Learn the main function in Go language from scratch Mar 27, 2024 pm 05:03 PM

Title: Learn the main function in Go language from scratch. As a simple and efficient programming language, Go language is favored by developers. In the Go language, the main function is an entry function, and every Go program must contain the main function as the entry point of the program. This article will introduce how to learn the main function in Go language from scratch and provide specific code examples. 1. First, we need to install the Go language development environment. You can go to the official website (https://golang.org

Learn the strconv.Atoi function in the Go language documentation to convert strings to integers Learn the strconv.Atoi function in the Go language documentation to convert strings to integers Nov 03, 2023 am 08:55 AM

Learn the strconv.Atoi function in the Go language documentation to convert strings to integers. The Go language is a powerful and flexible programming language. The strconv package in its standard library provides the function of string conversion. In this post, we will learn how to convert string to integer using strconv.Atoi function. First, we need to understand the purpose and declaration of the strconv.Atoi function. The description of the function in the document is as follows: funcAtoi(sstring)(i

Quickly learn pip installation and master the skills from scratch Quickly learn pip installation and master the skills from scratch Jan 16, 2024 am 10:30 AM

Learn pip installation from scratch and quickly master the skills. Specific code examples are required. Overview: pip is a Python package management tool that can easily install, upgrade and manage Python packages. For Python developers, it is very important to master the skills of using pip. This article will introduce the installation method of pip from scratch, and give some practical tips and specific code examples to help readers quickly master the use of pip. 1. Install pip Before using pip, you first need to install pip. pip

See all articles