Database model for saving random boolean expressions

Posted by zarko.susnjar on Stack Overflow See other posts from Stack Overflow or by zarko.susnjar
Published on 2010-05-20T14:38:55Z Indexed on 2010/05/20 16:00 UTC
Read the original article Hit count: 287

I have expressions like this:

(cat OR cats OR kitten OR kitty) AND (dog OR dogs) NOT (pigeon OR firefly)

Anyone having idea how to make tables to save those?

Before I got request for usage of brackets, I limited usage of operators to avoid ambiguous situations. So only ANDs and NOTs or only ORs and saved those in this manner:

operators

id | name  
1  | AND  
2  | OR  
3  | NOT  

keywords

id | keyword  
1  | cat  
2  | dog  
3  | firefly  

expressions

id | operator | keywordId  
1  | 0        | 1   
1  | 1        | 2  
1  | 3        | 3  

which was: cat AND dog NOT firefly

But now, I'm really puzzled...

© Stack Overflow or respective owner

Related posts about database-design

Related posts about boolean-logic