complex boolean and join query
695392Apr 22 2009 — edited Apr 24 2009Hi,
Previously I wanted a boolean and query across a word OCCURRENCE table. Now I want to add functionality that queries across a METADATA table in addition to the OCCURRENCE table to give the user the option.
The first table is:
OCCURRENCE_TBL
------------
BOOK_ID
PAGE_ID
WORD indexed
RANK_VAL
The second table is:
METADATA_TBL
----------------------
BOOK_ID
ATTR_1
ATTR_2
ATTR_3
....
ATTR_N
My first query caught the PAGE_ID and BOOK_ID (s) of all and-ed occurrences of a set of words by rank. You guys helped me with
select page_id, sum(rank_val)
from occurrence_tbl
where word in ('word1', 'word2', 'word3')
group by page_id
having count(word)=3
order by sum(rank_val) desc
with the recommendation to just index on WORD in OCCURRENCE_TBL
Now, how do I make a similar query against both OCCURRENCE_TBL and METADATA_TBL for 'word1' AND 'word2' AND 'word3'? In particular, an occurrence of one of the words must be in either table joined by BOOK_ID. What I was thinking was that I should augment the OCCURRENCE_TBL with records for the metadata column words in each book and give two ranks, one for the content only and one for the metadata and content. Is this the right approach rather than trying some kind of table join query?
Thanks,
Andy