1551
|
1 package luan.modules.lucene;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.util.Map;
|
|
5 import org.apache.lucene.search.Query;
|
|
6 import goodjava.lucene.api.GoodIndexWriter;
|
|
7 import goodjava.lucene.logging.OpDoer;
|
|
8 import goodjava.lucene.logging.BasicOpDoer;
|
|
9 import luan.LuanFunction;
|
|
10 import luan.LuanException;
|
|
11 import luan.LuanRuntimeException;
|
|
12
|
|
13
|
|
14 final class LuanOpDoer implements OpDoer {
|
|
15 private final OpDoer opDoer;
|
|
16 private final LuanFunction fn;
|
|
17
|
|
18 LuanOpDoer(GoodIndexWriter writer,LuanFunction fn) {
|
|
19 this.opDoer = new BasicOpDoer(writer);
|
|
20 this.fn = fn;
|
|
21 }
|
|
22
|
|
23 public void commit() throws IOException {
|
|
24 try {
|
|
25 fn.call(new CommitAction(opDoer));
|
|
26 } catch(LuanException e) {
|
|
27 throw new LuanRuntimeException(e);
|
|
28 }
|
|
29 }
|
|
30
|
|
31 public void deleteAll(long time) throws IOException {
|
|
32 try {
|
|
33 fn.call(new DeleteAllAction(opDoer,time));
|
|
34 } catch(LuanException e) {
|
|
35 throw new LuanRuntimeException(e);
|
|
36 }
|
|
37 }
|
|
38
|
|
39 public void deleteDocuments(long time,Query query) throws IOException {
|
|
40 try {
|
|
41 fn.call(new DeleteDocumentsAction(opDoer,time,query));
|
|
42 } catch(LuanException e) {
|
|
43 throw new LuanRuntimeException(e);
|
|
44 }
|
|
45 }
|
|
46
|
|
47 public void addDocument(long time,Map<String,Object> storedFields) throws IOException {
|
|
48 try {
|
|
49 fn.call(new AddDocumentAction(opDoer,time,storedFields));
|
|
50 } catch(LuanException e) {
|
|
51 throw new LuanRuntimeException(e);
|
|
52 }
|
|
53 }
|
|
54
|
|
55 public void updateDocument(long time,String keyFieldName,Map<String,Object> storedFields) throws IOException {
|
|
56 try {
|
|
57 fn.call(new UpdateDocumentAction(opDoer,time,keyFieldName,storedFields));
|
|
58 } catch(LuanException e) {
|
|
59 throw new LuanRuntimeException(e);
|
|
60 }
|
|
61 }
|
|
62
|
|
63 public void tag(long time,String tag) throws IOException {
|
|
64 try {
|
|
65 fn.call(new TagAction(opDoer,time,tag));
|
|
66 } catch(LuanException e) {
|
|
67 throw new LuanRuntimeException(e);
|
|
68 }
|
|
69 }
|
|
70
|
|
71 public static abstract class Action {
|
|
72 public final OpDoer opDoer;
|
|
73 public final String name;
|
|
74
|
|
75 private Action(OpDoer opDoer,String name) {
|
|
76 this.opDoer = opDoer;
|
|
77 this.name = name;
|
|
78 }
|
|
79
|
|
80 public abstract void run() throws IOException;
|
|
81 }
|
|
82
|
|
83 public static final class CommitAction extends Action {
|
|
84
|
|
85 private CommitAction(OpDoer opDoer) {
|
|
86 super(opDoer,"commit");
|
|
87 }
|
|
88
|
|
89 public void run() throws IOException {
|
|
90 opDoer.commit();
|
|
91 }
|
|
92 }
|
|
93
|
|
94 public static final class DeleteAllAction extends Action {
|
|
95 public final long time;
|
|
96
|
|
97 private DeleteAllAction(OpDoer opDoer,long time) {
|
|
98 super(opDoer,"deleteAll");
|
|
99 this.time = time;
|
|
100 }
|
|
101
|
|
102 public void run() throws IOException {
|
|
103 opDoer.deleteAll(time);
|
|
104 }
|
|
105 }
|
|
106
|
|
107 public static final class DeleteDocumentsAction extends Action {
|
|
108 public final long time;
|
|
109 public final Query query;
|
|
110
|
|
111 private DeleteDocumentsAction(OpDoer opDoer,long time,Query query) {
|
|
112 super(opDoer,"deleteDocuments");
|
|
113 this.time = time;
|
|
114 this.query = query;
|
|
115 }
|
|
116
|
|
117 public void run() throws IOException {
|
|
118 opDoer.deleteDocuments(time,query);
|
|
119 }
|
|
120 }
|
|
121
|
|
122 public static final class AddDocumentAction extends Action {
|
|
123 public final long time;
|
|
124 public final Map<String,Object> storedFields;
|
|
125
|
|
126 private AddDocumentAction(OpDoer opDoer,long time,Map<String,Object> storedFields) {
|
|
127 super(opDoer,"addDocument");
|
|
128 this.time = time;
|
|
129 this.storedFields = storedFields;
|
|
130 }
|
|
131
|
|
132 public void run() throws IOException {
|
|
133 opDoer.addDocument(time,storedFields);
|
|
134 }
|
|
135 }
|
|
136
|
|
137 public static final class UpdateDocumentAction extends Action {
|
|
138 public final long time;
|
|
139 public final String keyFieldName;
|
|
140 public final Map<String,Object> storedFields;
|
|
141
|
|
142 private UpdateDocumentAction(OpDoer opDoer,long time,String keyFieldName,Map<String,Object> storedFields) {
|
|
143 super(opDoer,"updateDocument");
|
|
144 this.time = time;
|
|
145 this.keyFieldName = keyFieldName;
|
|
146 this.storedFields = storedFields;
|
|
147 }
|
|
148
|
|
149 public void run() throws IOException {
|
|
150 opDoer.updateDocument(time,keyFieldName,storedFields);
|
|
151 }
|
|
152 }
|
|
153
|
|
154 public static final class TagAction extends Action {
|
|
155 public final long time;
|
|
156 public final String tag;
|
|
157
|
|
158 private TagAction(OpDoer opDoer,long time,String tag) {
|
|
159 super(opDoer,"tag");
|
|
160 this.time = time;
|
|
161 this.tag = tag;
|
|
162 }
|
|
163
|
|
164 public void run() throws IOException {
|
|
165 opDoer.tag(time,tag);
|
|
166 }
|
|
167 }
|
|
168
|
|
169 }
|