2015-04-01 49 views
-2

我正在做一個網站,後端使用MySQL和Ruby gem Sinatra。MySQL是否有文字搜索,似乎像谷歌的工作?

我的MySQL表有LONGTEXT列,其索引爲FULLTEXT

我寫了一個MySQL查詢這基本上是這樣的:

SELECT Plot 
FROM myTable 
WHERE MATCH(Plot) AGAINST('time travel robot') 

的第一個結果:

Man on the Moon is a biographical movie on the late comedian Andy Kaufman. Kaufman, along with his role on Taxi (1978), was famous for being the self-declared Intergender Wrestling Champion of the world. After beating women time and time again, Jerry Lawler (who plays himself in the movie), a professional wrestler, got tired of seeing all of this and decided to challenge Kaufman to a match. In most of the matches the two had, Lawler prevailed with the piledriver, which is a move by spiking an opponent head-first into the mat. One of the most famous moments in this feud was in the early 80s when Kaufman threw coffee on Lawler on Late Night with David Letterman (1982), got into fisticuffs with Lawler, and proceeded to sue NBC.

雖然我很喜歡這部電影,它無關,與時間旅行或機器人。

我不知道Google的搜索算法,但是我想知道MySQL是否具有搜索功能,可以根據輸入的單詞有多緊密排列結果。

在我的情況下,我希望最相關的結果有儘可能相近的詞「時間」,「旅行」和「機器人」。

如果我的夢想功能也可以在單詞上有變化,比如「旅行」或「機器人」,那將會很好。

這對MySQL有多大可能?還是用Ruby?

或者我應該去完全不同的東西?

回答

1

Google通過使用solr(lucene)對大n-gram數據執行索引來進行搜索。 see

在ruby中使用mysql你可以做到這一點,但是對大數據來說它不會那麼快速和有效。但對於小數據,您會很高興看到結果。

A database index是一種數據結構,以額外的寫入和存儲空間爲代價來提高數據庫表上數據檢索操作的速度,以維護索引數據結構。請參閱indexing

存在各種用於此索引目的的數據結構技術。那些你也可以在Ruby上應用ruby。爲了獲得基本的想法檢查這個tutorial

所以,如果你有大量的數據集,這些數據thta執行一些索引技術,現在當您對索引數據的查詢time travel robot搜索,它會自動顯示最相關的結果。