| 1 |
Attach = |
|---|
| 2 |
[[ |
|---|
| 3 |
attach database '[v:path]' as [v:name] |
|---|
| 4 |
]], |
|---|
| 5 |
|
|---|
| 6 |
BeginTransaction = |
|---|
| 7 |
[[ |
|---|
| 8 |
begin transaction |
|---|
| 9 |
]], |
|---|
| 10 |
|
|---|
| 11 |
EndTransaction = |
|---|
| 12 |
[[ |
|---|
| 13 |
end transaction |
|---|
| 14 |
]], |
|---|
| 15 |
|
|---|
| 16 |
Rollback = |
|---|
| 17 |
[[ |
|---|
| 18 |
rollback |
|---|
| 19 |
]], |
|---|
| 20 |
|
|---|
| 21 |
DeleteDocument = |
|---|
| 22 |
[[ |
|---|
| 23 |
delete |
|---|
| 24 |
from [v:partition].document |
|---|
| 25 |
where name = %s |
|---|
| 26 |
]], |
|---|
| 27 |
|
|---|
| 28 |
InsertDocument = |
|---|
| 29 |
[[ |
|---|
| 30 |
insert or ignore into [v:partition].document( name ) values( %s ) |
|---|
| 31 |
]], |
|---|
| 32 |
|
|---|
| 33 |
UpdateDocument = |
|---|
| 34 |
[[ |
|---|
| 35 |
update or ignore [v:partition].document set name = %s where name = %s |
|---|
| 36 |
]], |
|---|
| 37 |
|
|---|
| 38 |
DeleteStage = |
|---|
| 39 |
[[ |
|---|
| 40 |
delete from stage |
|---|
| 41 |
]], |
|---|
| 42 |
|
|---|
| 43 |
InsertStage = |
|---|
| 44 |
[[ |
|---|
| 45 |
insert into stage( document, token, weight ) values( %s, %s, %s ) |
|---|
| 46 |
]], |
|---|
| 47 |
|
|---|
| 48 |
InsertToken = |
|---|
| 49 |
[[ |
|---|
| 50 |
insert |
|---|
| 51 |
into [v:partition].token( name ) |
|---|
| 52 |
select stage.token as name |
|---|
| 53 |
from stage |
|---|
| 54 |
left join [v:partition].token on token.name = stage.token |
|---|
| 55 |
where token.id is null |
|---|
| 56 |
]], |
|---|
| 57 |
|
|---|
| 58 |
DeleteDocumentToken = |
|---|
| 59 |
[[ |
|---|
| 60 |
delete |
|---|
| 61 |
from [v:partition].document_token |
|---|
| 62 |
where document_id |
|---|
| 63 |
in ( |
|---|
| 64 |
select id |
|---|
| 65 |
from [v:partition].document |
|---|
| 66 |
where name = %s |
|---|
| 67 |
) |
|---|
| 68 |
]], |
|---|
| 69 |
|
|---|
| 70 |
InsertDocumentToken = |
|---|
| 71 |
[[ |
|---|
| 72 |
insert |
|---|
| 73 |
into [v:partition].document_token |
|---|
| 74 |
( |
|---|
| 75 |
document_id, |
|---|
| 76 |
token_id, |
|---|
| 77 |
weight |
|---|
| 78 |
) |
|---|
| 79 |
select document.id as document_id, |
|---|
| 80 |
token.id as token_id, |
|---|
| 81 |
stage.weight as weight |
|---|
| 82 |
from stage |
|---|
| 83 |
join [v:partition].document on document.name = stage.document |
|---|
| 84 |
join [v:partition].token on token.name = stage.token |
|---|
| 85 |
]], |
|---|
| 86 |
|
|---|
| 87 |
SelectDocumentToken = |
|---|
| 88 |
[[ |
|---|
| 89 |
select token.name as name, |
|---|
| 90 |
document_token.weight as weight |
|---|
| 91 |
from [v:partition].document |
|---|
| 92 |
join [v:partition].document_token on document_token.document_id = document.id |
|---|
| 93 |
join [v:partition].token on token.id = document_token.token_id |
|---|
| 94 |
where document.name = %s |
|---|
| 95 |
order by token.name, |
|---|
| 96 |
document_token.weight |
|---|
| 97 |
]], |
|---|
| 98 |
|
|---|
| 99 |
FindDocument = |
|---|
| 100 |
[[ |
|---|
| 101 |
insert |
|---|
| 102 |
into hit |
|---|
| 103 |
( |
|---|
| 104 |
document, |
|---|
| 105 |
score |
|---|
| 106 |
) |
|---|
| 107 |
select document.name as name, |
|---|
| 108 |
sum( document_token.weight ) as score |
|---|
| 109 |
from stage |
|---|
| 110 |
join [v:partition].token on token.name >= stage.document and token.name < stage.token |
|---|
| 111 |
join [v:partition].document_token on document_token.token_id = token.id |
|---|
| 112 |
join [v:partition].document on document.id = document_token.document_id |
|---|
| 113 |
group by document.name |
|---|
| 114 |
having count( document_token.token_id ) >= |
|---|
| 115 |
( |
|---|
| 116 |
select count( stage.document ) as count |
|---|
| 117 |
from stage |
|---|
| 118 |
) |
|---|
| 119 |
order by 2 desc, |
|---|
| 120 |
1 |
|---|
| 121 |
limit %s |
|---|
| 122 |
]], |
|---|
| 123 |
|
|---|
| 124 |
DeleteHit = |
|---|
| 125 |
[[ |
|---|
| 126 |
delete from hit |
|---|
| 127 |
]], |
|---|
| 128 |
|
|---|
| 129 |
SelectHit = |
|---|
| 130 |
[[ |
|---|
| 131 |
select document, |
|---|
| 132 |
score |
|---|
| 133 |
from hit |
|---|
| 134 |
order by score desc, |
|---|
| 135 |
document |
|---|
| 136 |
limit %s |
|---|
| 137 |
]] |
|---|