Working on a MySQL db which contains the Book Title, Author, Publication in a single column(field). The original db designer is said to put all those in single field to allow for easy search. Age-old client database, so I am NOT allowed to modify it.
Example:
Id BookDetails
1 A Tale of Two Cities|Charles Dickens|Penguin
2 And Then There Were None,Agatha Christie Random House
3 Adventures of Sherlock Holmes Arthur Conan Doyle-Harper Collins
4 Integrated Physics, Sarah Ann Barnes & Nobles
5 Integrated Electronics Millman & Halkias McGraw
6 Integrated Electronics|Millman|McGraw
As one can see from above, the book name, author name, pub names are all jumbled up - some fields they are pipe delimited, somewhere hyphen-delimited, & somewhere no or space delimited.
Current search allows for only 1 word in search query (like "Integrated" which will return row 4, 5 & 6). Among other requirements, I am tasked with extending the search to allow multi-words (Integrated Electronics Halkias - 3 words).
The implementation challenge I am facing is which SQL query will be best?
- If I go with
BookDetails like '%Integrated%Electronics%Halkias%'
, it will match 5 perfectly, but will miss 6. But if someone changes to search query order to say 'Halkias Integrated Electronics' - it will fail to match anything - If I go with breaking it into single word AND (like
BookDetails like '%Integrated%' and BookDetails like '%Electronic%' and BookDetails like '%Halkias%'
) will only match 5 (while ideally it should match 6 as well). - If I go with breaking it into single word AND (like
BookDetails like '%Integrated%' OR BookDetails like '%Electronic%' OR BookDetails like '%Halkias%'
) will match 4, 5 & 6 (while ideally it should only match 5 & 6 only). - Any other suggestions
I've checked existing SO threads (like How do I do a fuzzy match of company names in MYSQL with PHP for auto-complete? - doesnt fit books need) and (Searching for names in a MySQL database that probably has typos - talks about pronunciations/typos which still does not fit books).
Any inputs on possible implementations please