全文索引—CONTAINS文法_PHP教程

來源:互聯網
上載者:User
全文索引——CONTAINS 文法
我們通常在 WHERE 子句中使用 CONTAINS ,就象這樣:SELECT * FROM table_name WHERE CONTAINS(fullText_column,'search contents')。
 
我們通過例子來學習,假設有表 students,其中的 address 是全文本檢索的列。
1. 查詢住址在北京的學生
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, 'beijing' )
remark: beijing是一個單詞,要用單引號括起來。
2. 查詢住址在河北省的學生
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, '"HEIBEI province"' )
remark: HEBEI province是一個片語,在單引號裡還要用雙引號括起來。
3. 查詢住址在河北省或北京的學生
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, '"HEIBEI province" OR beijing' )
remark: 可以指定邏輯操作符(包括 AND ,AND NOT,OR )。
4. 查詢有 '南京路' 字樣的地址
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, 'nanjing NEAR road' )
remark: 上面的查詢將返回包含 'nanjing road','nanjing east road','nanjing west road' 等字樣的地址。
A NEAR B,就表示條件: A 靠近 B。
5. 查詢以 '湖' 開頭的地址
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, '"hu*"' )
remark: 上面的查詢將返回包含 'hubei','hunan' 等字樣的地址。
記住是 *,不是 %。
6. 類似加權的查詢
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, 'ISABOUT (city weight (.8), county wright (.4))' )
remark: ISABOUT 是這種查詢的關鍵字,weight 指定了一個介於 0~1之間的數,類似係數(我的理解)。表示不同條件有不同的側重。
7. 單詞的多態查詢
SELECT student_id,student_name
FROM students
WHERE CONTAINS( address, 'FORMSOF (INFLECTIONAL,street)' )
remark: 查詢將返回包含 'street','streets'等字樣的地址。
對於動詞將返回它的不同的時態,如:dry,將返回 dry,dried,drying 等等。
以上例子都使用英文,不使用中文是因為有的查詢方式中文不支援,而且我的電腦是英文系統。


http://www.bkjia.com/PHPjc/631072.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631072.htmlTechArticle全文索引——CONTAINS 文法 我們通常在 WHERE 子句中使用 CONTAINS ,就象這樣:SELECT * FROM table_name WHERE CONTAINS(fullText_column,'search contents')。 我們...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.