2
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local new_error = Luan.new_error or error()
|
53
|
4 local ipairs = Luan.ipairs or error()
|
58
|
5 local Table = require "luan:Table.luan"
|
|
6 local sort = Table.sort or error()
|
|
7 local concat = Table.concat or error()
|
2
|
8 local Lucene = require "luan:lucene/Lucene.luan"
|
|
9 local Io = require "luan:Io.luan"
|
|
10 local uri = Io.uri or error()
|
|
11 local Http = require "luan:http/Http.luan"
|
|
12 local Thread = require "luan:Thread.luan"
|
|
13 local Time = require "luan:Time.luan"
|
|
14 local Logging = require "luan:logging/Logging.luan"
|
|
15 local logger = Logging.logger "Db"
|
|
16
|
|
17
|
|
18 local dir = uri("site:/private/local/lucene")
|
|
19
|
|
20 local Db = Lucene.index( dir, {
|
|
21 log_dir = uri("site:/private/local/lucene_log")
|
|
22 name = "lucene"
|
|
23 version = 1
|
|
24 } )
|
|
25
|
|
26 Db.indexed_fields.user_email = Lucene.type.lowercase
|
|
27
|
4
|
28 Db.indexed_fields.chat_user_ids = Lucene.type.long
|
|
29 Db.indexed_fields.chat_updated = Lucene.type.long
|
58
|
30 Db.indexed_fields.chat_key = Lucene.type.string
|
4
|
31
|
10
|
32 Db.indexed_fields.post_chat_id = Lucene.type.long
|
53
|
33 Db.indexed_fields.post_date = Lucene.type.long
|
|
34
|
57
|
35 Db.indexed_fields.chatuser_key = Lucene.type.string
|
55
|
36 Db.indexed_fields.chatuser_chat_id = Lucene.type.long
|
10
|
37
|
2
|
38 function Db.not_in_transaction()
|
|
39 logger.error(new_error("not in transaction"))
|
|
40 end
|
|
41
|
58
|
42 -- copied from Chat
|
|
43 local function get_chat_key(user_ids)
|
|
44 sort(user_ids)
|
|
45 return concat(user_ids,"~")
|
|
46 end
|
|
47
|
2
|
48 Db.update{
|
53
|
49 [1] = function()
|
|
50 local docs = Db.search("type:post",1,1000000)
|
|
51 for _, doc in ipairs(docs) do
|
|
52 doc.post_date = doc.post_date or doc.date
|
|
53 Db.save(doc)
|
|
54 end
|
|
55 end
|
55
|
56 [2] = function()
|
|
57 Db.delete("type:chatuser")
|
|
58 end
|
57
|
59 [3] = function()
|
|
60 Db.delete("type:chatuser")
|
|
61 end
|
58
|
62 [4] = function()
|
|
63 local docs = Db.search("type:chat",1,1000000)
|
|
64 for _, doc in ipairs(docs) do
|
|
65 doc.chat_key = get_chat_key(doc.chat_user_ids)
|
|
66 Db.save(doc)
|
|
67 end
|
|
68 end
|
2
|
69 }
|
|
70
|
|
71 if Http.is_serving then
|
|
72 Thread.schedule( Db.check, { delay=0, repeating_delay=Time.period{hours=1} } )
|
|
73 end
|
|
74
|
|
75 return Db
|