How to search for compound words, and get the word parts returned

Database Administrators Asked by on January 4, 2022

I need to be able to search for compound words like “menneskerettighedsforkæmperens” (the human rights activist’s) and find the words “menneske” (human), “rettighed” (right) and “forkæmper” (activist).

I have all the words (and hundreds of thousands of other words) listed in MySQL, all in separate rows with additional information about each word (like hyphenation, which is what I need the DB to return), but I need to search a lot of words at the same time, which can be painfully slow.

I’m currently using a MySQL database, but willing to switch it out for something better suiting my needs, maybe some kind of NoSQL or elasticsearch. But I haven’t been able to find any examples of how to accomplish what I’m looking for in any other type of databases. So if anyone can help me out, I would really appreciate it.

One Answer

I would look for a library that specializes in splitting compound words. Search Java, PHP, Perl, etc. SQL is not likely to be involved.

If you must use a database, then consider this for a piece of the algorithm:

SELECT word FROM words
    WHERE word < 'menneskerettighedsforkæmperens'
    ORDER BY word DESC
    LIMIT 5;

That is likely to return a few compound words that begin with 'menneske' and perhaps 'menneske', itself.

In MySQL, that query will be quite fast (assuming an index on word). You would need some code in addition to a few SQL calls.

Answered by Rick James on January 4, 2022

Add your own answers!

Related Questions

How to log into a fresh MariaDB install?

2  Asked on October 28, 2021


Query tables with information_schema in pgsql

1  Asked on October 28, 2021 by boodoo


Designing golf pro scheduling into POS

0  Asked on October 28, 2021 by jarrette


MariaDB Galera + Remote Backup

1  Asked on October 28, 2021


Query is failing

2  Asked on October 27, 2021


PostgreSQL resources requirements

0  Asked on October 27, 2021 by miyuki-narahara


Optimizing my query

2  Asked on October 27, 2021 by kilazur


When (or why even) use PLPython(3)u

2  Asked on October 27, 2021 by chessbrain


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP