I have the following db schema
Product
Id | Name | ManufactureId |
---|---|---|
Guid (PK) | string | (FK) |
– | ECOSYS M2640idw | 3 |
– | Infoprint 1140 | 2 |
Manufacture
Id | Name |
---|---|
(PK) | string |
1 | Hitachi |
2 | IBM |
3 | Kyocera Mita |
- Both names (product and manufacturer) can consist of several words;
I have a search string (provided by user from mobile app) compiled in a random order ( product name manufacture name or manufacture name product name) names could be partial, I need to select db entries that will match with user input, there is no delimiters in search strings between manufacture and product parts.
eg
- search input:
Kyoce ecos
should provide in results an entryECOSYS M2640idw
- search input:
kyocera mi ecosys
should provide in results an entryECOSYS M2640idw
- search input:
ibm
should provide resultsInfoprint 1140
Could you please help to find a better way to construct SQL query to approach this on Postgresql
Thanks, for any help
2
Answers
Solution:
https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html
Query:
Fulltext:
https://neon.tech/postgresql/postgresql-indexes/postgresql-full-text-search
JOIN Product and Manufacturer and string_to table(search input).
Then use LIKE or ILIKE for search words and word parts.
You need to decide whether you will
For
search whole words
solution example provided by @Mertuarez.I suggest example for search parts of words.
For search input ‘kyo print’ output is
fiddle