《Solr in action》筆記與總結:一

之前沒做過搜索引擎相關的業務,最近口袋的文獻和指南搜索需要進行調整優化,遂入坑solr,出乎意料的是solr的相關資料非常少(更別提中文了),官網的介紹又非常的干,堆砌各種example,剛好發現了一本《solr in action》(以solr4為例講解),讀了幾章后,收獲頗豐,所以這次的雙周分享是摘錄《solr in action》中那些讓我感到醍醐灌頂的話。

Why do I need a search engine?

Search engines like Solr are optimized to handle data exhibiting four main characteristics:

  1. Text-centric(文本為中心)
  2. Read- dominant(以讀為主)
  3. Document- oriented(面向文檔)
  4. Flexible schema(靈活的schema)

Text-centric

We think text-centric is more appropriate for describing the type of data Solr handles.
Of course, a search engine also supports non text data such as dates and numbers, but its primary strength is handling text data based on natural language.

搜索引擎主要是用來處理大段文本的搜索。

Read- dominant

Think of read-dominant as meaning that documents are read far more often than they’re created or updated.
if you must update existing data in a search engine often, that could be an indication that a search engine might not be the best solution for your needs. Another NoSQL technology, like Cassandra, might be a better choice when you need fast random writes to existing data.

搜索引擎以讀為主,如果需要頻繁的更新,那么solr不會是個好選擇。

Document-oriented

Ina search engine, a document is a self-contained collection of fields, in which each field only holds data and doesn’t contain nested fields.
In general, you should store the minimal set of information for each document needed to satisfy search requirements.

在搜索引擎的數據結構中,是面向文檔的,文檔中包含一組fields。

Flexible schema

In a relational database, every row in a table has the same structure. In Solr, documents can have different fields.

文檔是非結構化的,不同的文檔可以由完全不同的fields組成,前提是field在managed-schema中有定義。

Don’t use a search engine to ...

  1. First, search engines are designed to return a small set of documents per query, usually 10 to 100.
    搜索引擎應該只用來返回少量的結果集。如果一次性請求所有大量的結果,索引查詢是會比較快,但是根據index重建大量的document會很慢。
  2. Another use case in which you shouldn’t use a search engine is deep analytic tasks that require access to a large subset of the index.
  3. Also, there’s no direct support in most search engines for document-level security, at least not in Solr.
    solr不支持文檔級別的安全校驗。

What is Solr?

Information retrieval engine

Solr is built on Apache Lucene, a popular, Java-based, open source, information retrieval library.

In a nutshell, Solr uses Lucene to provide the core data structures for indexing documents and executing searches to find documents.
如你所見,solr其實是使用Lucene來實現建立index&執行search等核心操作的。

one key difference between a Lucene query and a database query is that in Lucene results are ranked by their relevance to a query, and database results can only be sorted by one or more of the table columns.
Lucene對搜索結果的排序有一套復雜的公式,被///因素所影響,而數據庫只能根據一列或多列column來簡單的排序。

Map Reduce is a programming model that distributes large-scaled data-processing operations across a cluster of commodity servers by formulating an algorithm into two phases: map and reduce.
MapReduce最早是Google提出的,被用來進行海量網頁的索引和搜索。同樣的,Solr提供了SolrCloud,可以運用MapReduce的思想來處理large-scaled數據的檢索,大大提高的性能及服務的高可用。

With Lucene, you need to write Java code to define fields and how to analyze those fields. Solr adds a simple, declarative way to define the structure of your index and how you want fields to be represented and analyzed: an XML-configuration document named schema.xml. Solr also provides copy and dynamic fields.

ok,既然Solr is built on Lucene,那么兩者有什么區別呢?Lucene其實是用戶不友好的,直接使用Lucene的話,你需要寫繁瑣的java代碼去定義field,而solr提供了簡單的xml文件來配置field,同時solr還提供了copy and dynamic fields。
所謂copy field,提供了一個聯合field,即一個name可以對應多個Field。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,527評論 6 544
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,687評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,640評論 0 383
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,957評論 1 318
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,682評論 6 413
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,011評論 1 329
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,009評論 3 449
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,183評論 0 290
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,714評論 1 336
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,435評論 3 359
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,665評論 1 374
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,148評論 5 365
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,838評論 3 350
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,251評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,588評論 1 295
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,379評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,627評論 2 380

推薦閱讀更多精彩內容