- 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網(wǎng)頁制作融會貫通
- Visual Basic從初學到精通
- AWS Certified SysOps Administrator:Associate Guide
- Windows Server 2008 R2活動目錄內(nèi)幕
- 大數(shù)據(jù)技術(shù)基礎(chǔ):基于Hadoop與Spark
- Machine Learning Algorithms(Second Edition)
- 基于敏捷開發(fā)的數(shù)據(jù)結(jié)構(gòu)研究
- 會聲會影X4中文版從入門到精通
- 基于ARM9的小型機器人制作
- 手把手教你學Photoshop CS3
- ADuC系列ARM器件應(yīng)用技術(shù)
- Practical AWS Networking
- 傳感技術(shù)基礎(chǔ)與技能實訓(xùn)
- 歐姆龍CP1系列PLC原理與應(yīng)用
- 歐姆龍CP1H型PLC編程與應(yīng)用