日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

全文检索引擎Solr系列——Solr核心概念、配置文件

發布時間:2025/3/19 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 全文检索引擎Solr系列——Solr核心概念、配置文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

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等等。

轉載于:https://my.oschina.net/u/2929819/blog/760871

總結

以上是生活随笔為你收集整理的全文检索引擎Solr系列——Solr核心概念、配置文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。