-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathluasolr_sample.lua
72 lines (54 loc) · 1.21 KB
/
luasolr_sample.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/usr/lua
require('luasolr')
function search(id)
local search_doc ={}
search_doc.id=id
local obj = luasolr.search(search_doc)
if #obj.response.docs > 0 then
print("found id=["..id.."]")
print(obj.response.docs[1].id)
print(obj.response.docs[1].price)
else
print("not found id=["..id.."]")
end
end
-- set url
-- luasolr.setHostUrl("http://localhost:8983/solr")
-- add
print("--- add")
local docs = {}
local doc ={}
doc.id='solrtest101'
doc.price=4111
table.insert(docs, doc)
luasolr.add(docs)
-- search
print("--- search after add")
search("solrtest101")
-- update
print("--- update")
local docs2 = {}
local doc2 ={}
doc2.id='solrtest101'
doc2.price=4121
table.insert(docs2, doc2)
luasolr.add(docs2)
-- search after update
print("--- search after update")
search("solrtest101")
-- delete
print("--- delete")
local docs3 = {}
local doc3 ={}
doc3.id='solrtest101'
table.insert(docs3, doc3)
luasolr.delete(docs3)
-- search after delete
print("--- search after delete")
search("solrtest101")
-- search after delete
print("--- search for no such id")
search("no_such_id_document")
-- search after delete with escape
print("--- search for no such id")
search("no such id document")