`

solr

 
阅读更多



The begining

There is one thing that you must know – Suggest component is not available in Solr version 1.4.1 and below. To start using this component you need to download 3_x or trunk version from Lucene/Solr SVN.

Configuration
Before we get into the index configuration we need to define an search component. So let’s do it:

view sourceprint?
1.
<searchComponent name="suggest" class="solr.SpellCheckComponent">
2.
<lst name="spellchecker">
3.
<str name="name">suggest</str>
4.
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
5.
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
6.
<str name="field">name_autocomplete</str>
7.
</lst>
8.
</searchComponent>
It is worth mentioning that suggest component is based on solr.SpellCheckComponent and that’s why we can use the above configuration. We have three important attributes in the configuration:

name - name of the component.
lookupImpl – an object that will handle the search. At this point we have two possibilities to use – JasperLookup or TSTLookup. This second one characterizes greater efficiency.
field – the field on the basis of which suggestions are generated.
Now let’s add the appropriate handler:

view sourceprint?
01.
<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
02.
<lst name="defaults">
03.
<str name="spellcheck">true</str>
04.
<str name="spellcheck.dictionary">suggest</str>
05.
<str name="spellcheck.count">10</str>
06.
</lst>
07.
<arr name="components">
08.
<str>suggest</str>
09.
</arr>
10.
</requestHandler>
Quite simple configuration, which defines a handler with an additional search component and tell Solr that the maximum number of suggestions returned is 10, this it should use dictionary named suggest (which is actually a Suggest component) which is exactly the same as our defined component.

Index
Let us assume that our document consists of three fields: id, name and description. We want to generate suggestions on the field that hold the name of the product. Our index could look like this:

view sourceprint?
1.
<field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true"/>
2.
<field name="name" type="text" indexed="true" stored="true" multiValued="false" />
3.
<field name="name_autocomplete" type="text_auto" indexed="true" stored="true" multiValued="false" />
4.
<field name="description" type="text" indexed="true" stored="true" multiValued="false" />
In addition, there is the following copy field definition:

view sourceprint?
1.
<copyField source="name" dest="name_autocomplete" />
Suggesting single words
In order to achieve individual words suggestions text_autocomplete type should be defined as follows:

view sourceprint?
1.
<fieldType class="solr.TextField" name="text_auto" positionIncrementGap="100">
2.
<analyzer>
3.
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
4.
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
5.
<filter class="solr.LowerCaseFilterFactory"/>
6.
</analyzer>
7.
</fieldType>
Suggesting phrases
To implement the entire phrase suggestions our text_autocomplete type should be defined as follows:

view sourceprint?
1.
<fieldType class="solr.TextField" name="text_auto">
2.
<analyzer>
3.
<tokenizer class="solr.KeywordTokenizerFactory"/>
4.
<filter class="solr.LowerCaseFilterFactory"/>
5.
</analyzer>
6.
</fieldType>
If you want to use phrases you may want to define your own query converter.

Dictionary building
Before we start using the component, we need to build its index. To this send the following command to Solr:

view sourceprint?
1.
/suggest?spellcheck.build=true
Queries
Now we come to use of the component. In order to show how the use the component, I decided suggest whole phrases. The example query could look like that:

view sourceprint?
1.
/suggest?q=har
After running that query I got the following suggestions:

view sourceprint?
01.
<?xml version="1.0" encoding="UTF-8"?>
02.
<response>
03.
<lst name="responseHeader">
04.
<int name="status">0</int>
05.
<int name="QTime">0</int>
06.
</lst>
07.
<lst name="spellcheck">
08.
<lst name="suggestions">
09.
<lst name="dys">
10.
<int name="numFound">4</int>
11.
<int name="startOffset">0</int>
12.
<int name="endOffset">3</int>
13.
<arr name="suggestion">
14.
<str>hard drive</str>
15.
<str>hard drive samsung</str>
16.
<str>hard drive seagate</str>
17.
<str>hard drive toshiba</str>
18.
</arr>
19.
</lst>
20.
</lst>
21.
</lst>
22.
</response>
The end
In the next part of the autocomplete functionality I’ll show how to modify its configuration to use static dictionary into the mechanism and how this can helk you get better suggestions. The last part of the series will be a performance comparison of each method in which I’ll try to diagnose which method is the fastest one in various situations.
分享到:
评论

相关推荐

    Apache Solr(solr-8.11.1.tgz)

    Apache Solr 是一个开源的全文搜索引擎,由Apache软件基金会维护,是Lucene项目的一部分。它提供了高效、可扩展的搜索和导航功能,广泛应用于企业级的搜索应用中。Solr-8.11.1是该软件的一个特定版本,包含了最新的...

    solr(solr-9.0.0-src.tgz)源码

    Solr是Apache软件基金会的一个开源项目,它是基于Java的全文搜索服务器,被广泛应用于企业级搜索引擎的构建。源码分析是深入理解一个软件系统工作原理的重要途径,对于Solr这样的复杂系统尤其如此。这里我们将围绕...

    ikanalyzer-solr8.4.0_solr8_solr_ikanalyzer_中文分词_

    Solr8.4.0 是 Apache Solr 的一个版本,这是一个高度可配置、高性能的全文搜索和分析引擎,广泛用于构建企业级搜索应用。 在 Solr 中,ikanalyzer 是一个重要的组件,它通过自定义Analyzer来实现中文的分词处理。...

    Linux上Solr的启动方式

    使用Solr内置的Jetty服务器启动Solr (1)借助X Shell上传solr的安装包到/usr/local/目录下,使用 tar -zxvf命令进行解压.  (2)使用内置的Jetty来启动Solr服务器只需要在example目录下,执行start.jar程序即可,...

    solr4.7服务搭建

    ### Solr 4.7 服务搭建详细指南 #### 一、环境准备 为了搭建 Solr 4.7 服务,我们需要确保以下环境已经准备好: 1. **Java Development Kit (JDK) 1.7**:Solr 需要 Java 运行环境支持,这里我们选择 JDK 1.7 ...

    solr增量更新架包apache-solr-dataimportscheduler.jar

    Apache Solr 是一个开源的全文搜索引擎,广泛应用于各种企业级数据搜索和分析场景。增量更新是Solr的一个关键特性,它允许系统仅处理自上次完整索引以来发生更改的数据,从而提高了性能并降低了资源消耗。"apache-...

    apache-solr-dataimportscheduler-1.0.zip_official54l_solr 5.x定时生成

    Apache Solr是一个流行的开源搜索引擎,它提供全文搜索、命中高亮、拼写建议等功能,广泛应用于网站内容管理和企业级信息检索。在Solr 5.x版本中,为了实现数据的定时更新,用户需要借助特定的扩展来实现定时生成...

    solr-7.4.0.zip

    Solr,全称为Apache Solr,是一款开源的企业级全文搜索引擎,由Apache软件基金会开发并维护。它是基于Java的,因此在使用Solr之前,确保你的系统已经安装了Java 8或更高版本是至关重要的。标题"solr-7.4.0.zip"表明...

    solr-6.2.0源码

    Solr是Apache软件基金会开发的一款开源全文搜索引擎,它基于Java平台,是Lucene的一个扩展,提供了更为方便和强大的搜索功能。在Solr 6.2.0版本中,这个强大的分布式搜索引擎引入了许多新特性和改进,使其在处理大...

    solr ik分词器

    Solr是中国最流行的开源搜索引擎平台之一,而IK Analyzer是一款针对中文的高性能分词器,尤其在处理现代汉语的复杂情况时表现出色。本教程将详细解释如何在Solr中安装和使用IK分词器。 首先,让我们理解一下什么是...

    解决solr启动404问题

    Solr是Apache Lucene项目的一个子项目,是一个高性能、基于Java的企业级全文搜索引擎服务器。当你在尝试启动Solr时遇到404错误,这通常意味着Solr服务没有正确地启动或者配置文件设置不正确。404错误表示“未找到”...

    solr-dataimport-scheduler.jar 可使用于solr7.x版本

    Solr 数据导入调度器(solr-dataimport-scheduler.jar)是一个专门为Apache Solr 7.x版本设计的组件,用于实现数据的定期索引更新。在理解这个知识点之前,我们需要先了解Solr的基本概念以及数据导入处理...

    solr-4.10.3.rar

    Solr 是一个开源的企业级搜索平台,由Apache软件基金会维护,是Lucene项目的一部分。它提供了全文检索、命中高亮、拼写检查、缓存、近实时搜索等特性,广泛应用于网站内容搜索、电子商务产品搜索等领域。本次分享的...

    solr定时自动同步数据库需要用到的apache-solr-dataimportscheduler.jar包

    Apache Solr是一款强大的开源搜索引擎,它能够高效地处理和索引大量数据,提供快速的全文检索、 faceting、高亮显示等高级功能。在实际应用中,为了保持搜索结果的实时性,我们往往需要将数据库中的数据实时或定时...

    支持solr5.5 solr6.0中IK分词需要的资料

    Solr是中国最流行的全文搜索引擎框架Apache Lucene的一个扩展,它提供了高级的搜索功能,并且能够进行复杂的全文检索、分布式搜索和处理大量数据。在Solr中,分词器(Tokenizer)是文本分析的重要组成部分,它负责将...

    solr.war包solr.war包solr.war包solr.war包solr.war包

    solr.warsolr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包...

    Solr(Cloudera)使用手册

    ### Solr(Cloudera)使用手册 #### 一、创建Collection与管理实例 在使用Solr(Cloudera)时,创建Collection是基本的操作之一。Collection是Solr中的数据存储单元,相当于关系数据库中的表。 ##### 创建路径与实例 ...

    最新版windows solr-8.8.2.zip

    Solr是Apache软件基金会的一个开源项目,是一款强大的全文搜索引擎服务器,它提供了分布式、可扩展、高可用性的搜索和分析服务。此压缩包“最新版windows solr-8.8.2.zip”包含了Windows环境下Solr的最新版本8.8.2的...

    最新版linux solr-8.8.2.tgz

    Linux Solr 8.8.2 是一个针对大型文本数据集进行高效全文搜索和处理的开源平台。Solr 是由 Apache 软件基金会维护的一个项目,它基于 Java 并可部署在各种操作系统上,包括 Linux。这个最新的版本 8.8.2 带来了若干...

    solr_solr_

    Solr,全称为Apache Solr,是一款开源的企业级搜索平台,由Apache软件基金会维护。它基于Java,并且是Lucene库的一个高级搜索应用。Solr主要用于处理和索引大量文本数据,提供高效的全文检索、拼写检查、命中高亮、...

Global site tag (gtag.js) - Google Analytics