Document

Document是Solr索引(动词,indexing)和搜索的最基本单元,它类似于关系数据库表中的一条记录,可以包含一个或多个字段(Field),每个字段包含一个name和文本值。字段在被索引的同时可以存储在索引中,搜索时就能返回该字段的值,通常文档都应该包含一个能唯一表示该文档的id字段。例如:

1
2
3
4
5
6
7
8
<doc>
    <field name="id">company123</field>
    <field name="companycity">Atlanta</field>
    <field name="companystate">Georgia</field>
    <field name="companyname">Code Monkeys R Us, LLC</field>
    <field name="companydescription">we write lots of code</field>
    <field name="lastmodified">2013-06-01T15:26:37Z</field>
</doc>

Schema

Solr中的Schema类似于关系数据库中的表结构,它以schema.xml的文本形式存在在conf目录下,在添加文当到索引中时需要指定Schema,Schema文件主要包含三部分:字段(Field)、字段类型(FieldType)、唯一键(uniqueKey)

  • 字段类型(FieldType):用来定义添加到索引中的xml文件字段(Field)中的类型,如:int,String,date,
  • 字段(Field):添加到索引文件中时的字段名称
  • 唯一键(uniqueKey):uniqueKey是用来标识文档唯一性的一个字段(Feild),在更新和删除时用到

例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<schema name="example" version="1.5">
    <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
    <field name="title" type="text_general" indexed="true" stored="true" multiValued="true"/>
 
    <uniqueKey>id</uniqueKey>
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" />
    <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
          <analyzer type="index">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <!-- in this example, we will only use synonyms at query time
            <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
            -->
            <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
          <analyzer type="query">
            <tokenizer class="solr.StandardTokenizerFactory"/>
            <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
            <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
            <filter class="solr.LowerCaseFilterFactory"/>
          </analyzer>
    </fieldType>
</schema>

Field

在Solr中,字段(Field)是构成Document的基本单元。对应于数据库表中的某一列。字段是包括了名称,类型以及对字段对应的值如何处理的一种元数据。比如:

<field name="name" type="text_general" indexed="true" stored="true"/>
  • Indexed:Indexed=true时,表示字段会加被Sorl处理加入到索引中,只有被索引的字段才能被搜索到。
  • Stored:Stored=true,字段值会以保存一份原始内容在在索引中,可以被搜索组件组件返回,考虑到性能问题,对于长文本就不适合存储在索引中。

Field Type

Solr中每个字段都有一个对应的字段类型,比如:float、long、double、date、text,Solr提供了丰富字段类型,同时,我们还可以自定义适合自己的数据类型,例如:

1
2
3
4
5
6
7
8
9
10
<!-- Ik 分词器 -->
 <fieldType name="text_cn_stopword" class="solr.TextField">
     <analyzer type="index">
         <tokenizer class="org.wltea.analyzer.lucene.IKAnalyzerSolrFactory" useSmart="false"/>
     </analyzer>
     <analyzer type="query">
         <tokenizer class="org.wltea.analyzer.lucene.IKAnalyzerSolrFactory" useSmart="true"/>
     </analyzer>
 </fieldType>
 <!-- Ik 分词器 -->

Solrconfig:

如果把Schema定义为Solr的Model的话,那么Solrconfig就是Solr的Configuration,它定义Solr如果处理索引、高亮、搜索等很多请求,同时还指定了缓存策略,用的比较多的元素包括:

  • 指定索引数据路径
1
2
3
4
5
6
<!--
Used to specify an alternate directory to hold all index data
other than the default ./data under the Solr home.
If replication is in use, this should match the replication configuration.
-->
<dataDir>${solr.data.dir:./solr/data}</dataDir>
  • 缓存参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<filterCache
  class="solr.FastLRUCache"
  size="512"
  initialSize="512"
  autowarmCount="0"/>
 
<!-- queryResultCache caches results of searches - ordered lists of
     document ids (DocList) based on a query, a sort, and the range
     of documents requested.  -->
 <queryResultCache
  class="solr.LRUCache"
  size="512"
  initialSize="512"
  autowarmCount="0"/>
 
 <!-- documentCache caches Lucene Document objects (the stored fields for each document).
   Since Lucene internal document ids are transient, this cache will not be autowarmed.  -->
 <documentCache
  class="solr.LRUCache"
  size="512"
  initialSize="512"
  autowarmCount="0"/>
  • 请求处理器
    请求处理器用于接收HTTP请求,处理搜索后,返回响应结果的处理器。比如:query请求:
1
2
3
4
5
6
7
8
9
<!-- A request handler that returns indented JSON by default -->
<requestHandler name="/query" class="solr.SearchHandler">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <str name="wt">json</str>
       <str name="indent">true</str>
       <str name="df">text</str>
     </lst>
</requestHandler>
每个请求处理器包括一系列可配置的搜索参数,例如:wt,indent,df等等。

全文检索引擎Solr系列——Solr核心概念、配置文件的更多相关文章

  1. 全文检索引擎Solr系列——solr入门

    下载4.8.0版本,下载地址:http://archive.apache.org/dist/lucene/solr/4.8.0/ 解压后,得到文件夹视图如下: 解压缩solr,在example目录有s ...

  2. 搜索引擎solr系列---solr分词配置

    分词我理解的是,输入的一句话,按照它自己定义的规则分为常用词语. 首先,Solr有自己基本的类型,string.int.date.long等等.   对于string类型,比如在你的core/conf ...

  3. Storm概念学习系列之核心概念(Tuple、Spout、Blot、Stream、Stream Grouping、Worker、Task、Executor、Topology)(博主推荐)

    不多说,直接上干货! 以下都是非常重要的storm概念知识. (Tuple元组数据载体 .Spout数据源.Blot消息处理者.Stream消息流 和 Stream Grouping 消息流组.Wor ...

  4. [摘]全文检索引擎Solr系列—–全文检索基本原理

    原文链接--http://www.importnew.com/12707.html 全文检索引擎Solr系列—–全文检索基本原理 2014/08/18 | 分类: 基础技术, 教程 | 2 条评论 | ...

  5. 全文检索引擎 Solr 部署与基本原理

    全文检索引擎 Solr 部署与基本原理 搜索引擎Solr环境搭建实例 关于 solr , schema.xml 的配置说明 全文检索引擎Solr系列-–全文检索基本原理 一.搜索引擎Solr环境搭建实 ...

  6. 全文检索引擎Solr 指南

    全文检索引擎Solr系列:第一篇:http://t.cn/RP004gl.第二篇:http://t.cn/RPHDjk7 .第三篇:http://t.cn/RPuJt3T

  7. 全文检索引擎及工具 Lucene Solr

    全文检索引擎及工具 lucence lucence是一个全文检索引擎. lucence代码级别的使用步骤大致如下: 创建文档(org.apache.lucene.document.Document), ...

  8. 全文检索引擎Solr的配置

    描述: 在Linux环境下实现高速的全文检索 一.当前环境: CentOS (Linux) 6.3 64 bit 二.所需软件 1.Java的JDK Java jdk 1.7.0[注意:solr5.x ...

  9. Solr全文检索引擎配置及使用方法

    介绍 Solr是一款开源的全文检索引擎,基于lucene.拥有完善的可配置功能界面.具有丰富的查询语言,可扩展,可优化. 下载安装 进入solr官网下载包(这里我使用的版本是8.0) http://w ...

随机推荐

  1. python 图像库PIL详解

    PIL详细文档 The most important class in the Python Imaging Library is the Image class, defined in the mo ...

  2. ie7 动态改变select option时,宽度自动变短解决方法

    <html> <head> <title>JQuery</title> <meta http-equiv="pragma" c ...

  3. Ubuntu 18.04 编译 ijkplayer

    Ubuntu 18.04 编译 ijkplayer 1. 配置安装源 https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu 2. 配置好安装源后,安装一些组 ...

  4. 51nod 1287 线段树

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1287 简单的线段树题目,直接写个二分查找大于等于x的最小位置就好了. # ...

  5. Python之virtualenv沙盒环境

    在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时开发多个应用程序,那这 ...

  6. 双系统在Linux下查看win的硬盘(Ubuntu 16.04 挂载Windows的 硬盘)

    一般情况下,Linux的桌面系统能够直接查看到计算机各个硬盘的文件情况 但是,当我们想通过命令行查看Windows下的硬盘的时候,会发现在 /media/ (一般Windows下的盘会挂载到这里)文件 ...

  7. [转载]Java动态填充word文档并上传到服务器

    一. 需求背景 在一些特殊应用场合,客户希望在服务器上生成文档的同时并填充数据,客户端的页面不显示打开文档,但是服务器上生成文档对服务器压力很大,目前服务器上生成文档第一种就是方式是jacob, 但是 ...

  8. eclipse 远程调试tomcat6

    一.tomcat6配置 1.修改tomcat\bin目录下的startup.bat如下,红色部分是新增的,修改后另存为jpda.bat set JPDA_ADDRESS=8114set JPDA_TR ...

  9. New Concept English three (45)

    31w/m 65error In democratic countries any efforts to restrict the freedom of the press are rightly c ...

  10. 2017.11.6对比Gerber差异+确认元器件方向,封装

    1比对新旧版本的gerber差异      导入两个版本.其中主要的是bot(底层),Smt(元器件),sst(丝印层),top(顶层) 底层和顶层可以看出走线layout的差别,这点很重要,上次客户 ...