I am looking for a highly efficient data structure for storage of data similar to the following.
Id Tags Order1 Order2 -------------------------- 1 1,2 1 1 2 2,5 2 3 3 1,7 4 7 4 6 3 0
I need to be able to query this structure in such a way that it would give me a list of all ids containing an expression of tags - supporting
NOT operations. Eg. ((1 or 2) and not 7)
I also need to be able to specify the ordering of the results (Order1 or Order2) and be able to specify maximum rows returned with an optional offset. Performance for the fetch of the first 30-100 results is key.
Finally, I need a cheap way to lookup "tag relations" for example I want to know which tags "relate" to tags (1 OR 2) and in what frequency. Meaning which tags appear in the same set as 1 OR 2 ... ordered by frequency.
Any idea of what data structure (or set of structures) would be highly efficient for this kind of work?
(I would like to use this as a proof of concept for redesigning the tagged pages of the SE family of sites)