You need to aggregate at the document level.
select d.docid, d.url, sum(weight) as weight
from document d join
loc l
on d.docid = l.docid join
word w
on w.wordid = l.wordid
where w.word in ('word1', 'word2', 'word3')
group by d.docid
order by weight DESC;