annotate src/luan/modules/lucene/Versioning.luan @ 1153:1f4da56abd4f

change http cookies interface
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 04 Feb 2018 20:01:23 -0700
parents bae2d0c2576c
children 7f4a12fb7716
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
1 local Luan = require "luan:Luan.luan"
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local pairs = Luan.pairs or error()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
4 local Number = require "luan:Number.luan"
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local integer = Number.integer or error()
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local long = Number.long or error()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
7 local String = require "luan:String.luan"
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local matches = String.matches or error()
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local sub = String.sub or error()
548
f4dfe9c64c25 shorten some String function names
Franklin Schmidt <fschmidt@gmail.com>
parents: 547
diff changeset
10 local string_to_number = String.to_number or error()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
11 local Table = require "luan:Table.luan"
565
22bfd8a2eaee do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents: 548
diff changeset
12 local copy = Table.copy or error()
693
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
13 local Lucene = require "luan:lucene/Lucene.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
14 require "luan:logging/init.luan"
ca169567ce07 module URIs must now include ".luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 629
diff changeset
15 local Logging = require "luan:logging/Logging.luan"
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local logger = Logging.logger "lucene versioning"
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
20 local Versioning = {}
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
22 function Versioning.update(db,steps,version)
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 local doc = db.get_document"type:version" or { type="version", version=integer(0) }
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 while doc.version < version do
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 doc.version = integer(doc.version + 1)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 logger.error("step "..doc.version)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 db.update_in_transaction( function()
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 local step = steps[doc.version]
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 step and step(db)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 db.save(doc)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end )
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 end
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 end
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 -- hack to deal with latest changes
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
37 function Versioning.a_big_step(db)
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 db.indexed_fields["id index"] = Lucene.type.string
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 db.advanced_search( Lucene.literal"id index" .. ":*", function(_,doc_fn)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 local doc = doc_fn()
565
22bfd8a2eaee do Table documentation;
Franklin Schmidt <fschmidt@gmail.com>
parents: 548
diff changeset
41 for field, value in pairs(copy(doc)) do
629
35dde32c02ab change String.matches()
Franklin Schmidt <fschmidt@gmail.com>
parents: 565
diff changeset
42 if matches(field," index$") then
547
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 local new_field = sub(field,1,-7)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 db.indexed_fields[new_field] or error("field '"..new_field.."' not indexed")
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 doc[new_field] = value
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 doc[field] = nil
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 end
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 end
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 doc.id = long(string_to_number(doc.id))
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 db.save(doc)
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 end )
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 db.indexed_fields["type index"] = Lucene.type.string
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 db.delete( Lucene.literal"type index" .. ":*" )
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 end
0be287ab0309 add lucene/Versioning and simplify Lucene fn names
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55
1088
bae2d0c2576c change module naming convention
Franklin Schmidt <fschmidt@gmail.com>
parents: 775
diff changeset
56 return Versioning