'Searching documents by tags, best solution

I want to build a webapp in node.js that would let me store notes with tags so I can easily search them by topics.

Tags could be chained, so programming.polymorphism would be different than biology.polymorphism and different than polymorphism. One doc can have multiple tags. Searching polymorphism would show all 3 results, but searching for programming.polymorphism would show only that one.

I wonder what would be the best solution for that. Two ideas come to my mind:

Data base but then what kind of database? SQL, noSQL? It needs to be stored on the same server as webapp.

Save tags as files, there would be a file programming.polymorphism that holds names of docs with that tag. I could put files in some hash map to index them.

Which of those solutions would be better? Or maybe is there another one?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source