- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 223字
- 2021-07-09 19:57:23
Comparing strings
After taking a brief look at the stemming process, it is time to figure out how a stemmed text can be compared to a user query. The following code snippet checks for wanted:
test=# SELECT to_tsvector('english', 'A car, I want a car. I would not even mind having many cars') @@ to_tsquery('english', 'wanted');
?column?
----------
t
(1 row)
Note that wanted does not actually show up in the original text. Still, PostgreSQL will return true. The reason is that want and wanted are both transformed to the same lexeme so the result is true. Practically, this makes a lot of sense. Imagine you are looking for car on Google. If you find pages selling cars, this is totally fine. Finding common lexemes is therefore an intelligent idea.
Sometimes, people are not only looking for a single word but want to find a set of words. With to_tsquery, this is possible as shown in the next example:
test=# SELECT to_tsvector('english', 'A car, I want a car. I would not even mind having many cars') @@ to_tsquery('english', 'wanted & bmw');
?column?
----------
f
(1 row)
In this case, false is returned because bmw cannot be found in our input string. In the to_tsquery function, & means and and | means or. It is therefore easily possible to build complex search strings.
- Dreamweaver CS3 Ajax網(wǎng)頁設(shè)計(jì)入門與實(shí)例詳解
- 機(jī)器學(xué)習(xí)實(shí)戰(zhàn):基于Sophon平臺的機(jī)器學(xué)習(xí)理論與實(shí)踐
- Learning Microsoft Azure Storage
- JBoss ESB Beginner’s Guide
- 自動生產(chǎn)線的拆裝與調(diào)試
- 21天學(xué)通Java
- 影視后期編輯與合成
- 從零開始學(xué)C++
- Dreamweaver CS6中文版多功能教材
- 納米集成電路制造工藝(第2版)
- Generative Adversarial Networks Projects
- 超好玩的Python少兒編程
- Arduino創(chuàng)意機(jī)器人入門:基于Mind+
- 探索中國物聯(lián)網(wǎng)之路
- Ubuntu 9 Linux應(yīng)用基礎(chǔ)