- Mastering PostgreSQL 10
- Hans Jürgen Sch?nig
- 244字
- 2021-06-30 19:03:59
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 the word 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 a 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.
- Ansible Configuration Management
- 玩轉(zhuǎn)智能機(jī)器人程小奔
- 現(xiàn)代測(cè)控電子技術(shù)
- 手把手教你學(xué)AutoCAD 2010
- ROS機(jī)器人編程與SLAM算法解析指南
- 自動(dòng)檢測(cè)與轉(zhuǎn)換技術(shù)
- 21天學(xué)通C#
- Photoshop CS3圖像處理融會(huì)貫通
- 新手學(xué)電腦快速入門
- 網(wǎng)絡(luò)綜合布線設(shè)計(jì)與施工技術(shù)
- 網(wǎng)絡(luò)安全與防護(hù)
- Learn QGIS
- 與人共融機(jī)器人的關(guān)節(jié)力矩測(cè)量技術(shù)
- 筆記本電腦使用與維護(hù)
- Linux常用命令簡(jiǎn)明手冊(cè)