Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/frontend/SearchDaemon.java |
— | — | @@ -373,7 +373,7 @@ |
374 | 374 | */ |
375 | 375 | private void sendResultLine(double score, String namespace, String title) { |
376 | 376 | try{ |
377 | | - sendOutputLine(score + " " + namespace + " " + encodeTitle(title)); |
| 377 | + sendOutputLine((float)score + " " + namespace + " " + encodeTitle(title)); |
378 | 378 | } catch(Exception e){ |
379 | 379 | log.error("Error sending result line ("+score + " " + namespace + " " + title +"): "+e.getMessage()); |
380 | 380 | } |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/spell/CleanIndexWriter.java |
— | — | @@ -91,16 +91,20 @@ |
92 | 92 | Transaction trans = new Transaction(iid, IndexId.Transaction.INDEX); |
93 | 93 | trans.begin(); |
94 | 94 | try{ |
95 | | - IndexReader reader = IndexReader.open(iid.getIndexPath()); |
96 | | - // batch delete |
97 | | - for(IndexUpdateRecord rec : records){ |
98 | | - if(rec.doDelete()){ |
99 | | - Article a = rec.getArticle(); |
100 | | - log.debug(iid+": Deleting "+a); |
101 | | - reader.deleteDocuments(new Term("key",rec.getIndexKey())); |
| 95 | + try{ |
| 96 | + IndexReader reader = IndexReader.open(iid.getIndexPath()); |
| 97 | + // batch delete |
| 98 | + for(IndexUpdateRecord rec : records){ |
| 99 | + if(rec.doDelete()){ |
| 100 | + Article a = rec.getArticle(); |
| 101 | + log.debug(iid+": Deleting "+a); |
| 102 | + reader.deleteDocuments(new Term("key",rec.getIndexKey())); |
| 103 | + } |
102 | 104 | } |
| 105 | + reader.close(); |
| 106 | + } catch(Exception e){ |
| 107 | + log.warn("Error opening for batch update read "+iid+" : "+e.getMessage()); |
103 | 108 | } |
104 | | - reader.close(); |
105 | 109 | // batch add |
106 | 110 | openWriter(iid.getIndexPath(),false); |
107 | 111 | for(IndexUpdateRecord rec : records){ |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerClient.java |
— | — | @@ -11,6 +11,7 @@ |
12 | 12 | import java.util.HashMap; |
13 | 13 | import java.util.HashSet; |
14 | 14 | import java.util.Hashtable; |
| 15 | +import java.util.Map; |
15 | 16 | import java.util.Set; |
16 | 17 | |
17 | 18 | import org.apache.log4j.Logger; |
— | — | @@ -395,4 +396,15 @@ |
396 | 397 | } |
397 | 398 | return false; |
398 | 399 | } |
| 400 | + |
| 401 | + public void addLocalizationCustomMapping(String host, Map<Integer,String> namespaceIndexToName, String dbname) throws RemoteException { |
| 402 | + RMIMessenger r; |
| 403 | + try { |
| 404 | + r = messengerFromCache(host); |
| 405 | + r.addLocalizationCustomMapping(namespaceIndexToName, dbname); |
| 406 | + } catch(NotBoundException e){ |
| 407 | + e.printStackTrace(); |
| 408 | + log.error("Messenger not bound: "+e.getMessage()); |
| 409 | + } |
| 410 | + } |
399 | 411 | } |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessenger.java |
— | — | @@ -6,6 +6,7 @@ |
7 | 7 | import java.util.ArrayList; |
8 | 8 | import java.util.HashMap; |
9 | 9 | import java.util.HashSet; |
| 10 | +import java.util.Map; |
10 | 11 | |
11 | 12 | import org.apache.lucene.analysis.Token; |
12 | 13 | import org.apache.lucene.index.Term; |
— | — | @@ -245,4 +246,13 @@ |
246 | 247 | * @return |
247 | 248 | */ |
248 | 249 | public boolean snapshotFinished(boolean optimize, String pattern, boolean forPrecursor) throws RemoteException; |
| 250 | + |
| 251 | + /** |
| 252 | + * Call on indexer to remotely add custom localized names for OAI header site info |
| 253 | + * |
| 254 | + * @param namespaceIndexToName |
| 255 | + * @param dbname |
| 256 | + * @throws RemoteException |
| 257 | + */ |
| 258 | + public void addLocalizationCustomMapping(Map<Integer,String> namespaceIndexToName, String dbname) throws RemoteException; |
249 | 259 | } |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/interoperability/RMIMessengerImpl.java |
— | — | @@ -6,6 +6,8 @@ |
7 | 7 | import java.util.Arrays; |
8 | 8 | import java.util.HashMap; |
9 | 9 | import java.util.HashSet; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.Map.Entry; |
10 | 12 | |
11 | 13 | import org.apache.log4j.Logger; |
12 | 14 | import org.apache.lucene.analysis.Token; |
— | — | @@ -37,6 +39,7 @@ |
38 | 40 | import org.wikimedia.lsearch.spell.SuggestQuery; |
39 | 41 | import org.wikimedia.lsearch.spell.SuggestResult; |
40 | 42 | import org.wikimedia.lsearch.spell.SuggestSimilar; |
| 43 | +import org.wikimedia.lsearch.util.Localization; |
41 | 44 | |
42 | 45 | /** Local implementation for {@link RMIMessenger} */ |
43 | 46 | public class RMIMessengerImpl implements RMIMessenger { |
— | — | @@ -232,6 +235,13 @@ |
233 | 236 | return indexThread.snapshotFinished(optimize,pattern,forPrecursor); |
234 | 237 | } |
235 | 238 | |
| 239 | + public void addLocalizationCustomMapping(Map<Integer, String> namespaceIndexToName, String dbname) throws RemoteException { |
| 240 | + for(Entry<Integer,String> e : namespaceIndexToName.entrySet()){ |
| 241 | + Localization.addCustomMapping(e.getValue(),e.getKey(),dbname); |
| 242 | + } |
| 243 | + |
| 244 | + } |
| 245 | + |
236 | 246 | protected RMIMessengerImpl(){ |
237 | 247 | networkStatus = null; |
238 | 248 | indexRegistry = null; |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/prefix/PrefixIndexBuilder.java |
— | — | @@ -315,6 +315,7 @@ |
316 | 316 | Transaction trans = new Transaction(pre, IndexId.Transaction.INDEX); |
317 | 317 | trans.begin(); |
318 | 318 | try{ |
| 319 | + try{ |
319 | 320 | IndexReader reader = IndexReader.open(pre.getIndexPath()); |
320 | 321 | // batch delete |
321 | 322 | for(IndexUpdateRecord rec : records){ |
— | — | @@ -325,6 +326,9 @@ |
326 | 327 | } |
327 | 328 | } |
328 | 329 | reader.close(); |
| 330 | + } catch(Exception e){ |
| 331 | + log.warn("Error while opening prefix precursor "+pre+" : "+e.getMessage()); |
| 332 | + } |
329 | 333 | // batch add |
330 | 334 | writer = WikiIndexModifier.openForWrite(pre.getIndexPath(),false,new PrefixAnalyzer()); |
331 | 335 | initWriter(writer); |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/index/Transaction.java |
— | — | @@ -147,12 +147,14 @@ |
148 | 148 | * Commit changes to index. |
149 | 149 | */ |
150 | 150 | public void commit(){ |
| 151 | + boolean wasInTransaction = inTransaction; |
151 | 152 | try{ |
152 | 153 | cleanup(); |
153 | 154 | inTransaction = false; |
154 | 155 | log.info("Successfully commited changes on "+iid); |
155 | 156 | } finally{ |
156 | | - lock.unlock(); |
| 157 | + if(wasInTransaction) |
| 158 | + lock.unlock(); |
157 | 159 | } |
158 | 160 | } |
159 | 161 | |
— | — | @@ -160,6 +162,7 @@ |
161 | 163 | * Rollback changes to index. Returns to previous consistent state. |
162 | 164 | */ |
163 | 165 | public void rollback(){ |
| 166 | + boolean wasInTransaction = inTransaction; |
164 | 167 | try{ |
165 | 168 | if(inTransaction){ |
166 | 169 | recover(); |
— | — | @@ -167,7 +170,8 @@ |
168 | 171 | log.info("Succesfully rollbacked changes on "+iid); |
169 | 172 | } |
170 | 173 | } finally{ |
171 | | - lock.unlock(); |
| 174 | + if(wasInTransaction) |
| 175 | + lock.unlock(); |
172 | 176 | } |
173 | 177 | } |
174 | 178 | |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/index/WikiIndexModifier.java |
— | — | @@ -238,13 +238,15 @@ |
239 | 239 | public static IndexWriter openForWrite(String path, boolean rewrite) throws IOException{ |
240 | 240 | return openForWrite(path,rewrite,null); |
241 | 241 | } |
| 242 | + |
242 | 243 | public static IndexWriter openForWrite(String path, boolean rewrite, Analyzer analyzer) throws IOException{ |
243 | 244 | try { |
244 | 245 | return new IndexWriter(path,analyzer,rewrite); |
245 | 246 | } catch (IOException e) { |
246 | 247 | try { |
247 | 248 | // unlock, retry |
248 | | - if(!new File(path).exists()){ |
| 249 | + File target = new File(path); |
| 250 | + if(!target.exists() || (target.isDirectory() && target.listFiles().length==0)){ |
249 | 251 | // try to make brand new index |
250 | 252 | makeDBPath(path); // ensure all directories are made |
251 | 253 | log.info("Making new index at path "+path); |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/oai/IndexUpdatesCollector.java |
— | — | @@ -3,6 +3,7 @@ |
4 | 4 | import java.io.IOException; |
5 | 5 | import java.util.ArrayList; |
6 | 6 | import java.util.Date; |
| 7 | +import java.util.HashMap; |
7 | 8 | import java.util.Hashtable; |
8 | 9 | import java.util.Iterator; |
9 | 10 | import java.util.Map.Entry; |
— | — | @@ -18,6 +19,7 @@ |
19 | 20 | import org.wikimedia.lsearch.config.GlobalConfiguration; |
20 | 21 | import org.wikimedia.lsearch.config.IndexId; |
21 | 22 | import org.wikimedia.lsearch.index.IndexUpdateRecord; |
| 23 | +import org.wikimedia.lsearch.interoperability.RMIMessengerClient; |
22 | 24 | import org.wikimedia.lsearch.ranks.LinksBuilder; |
23 | 25 | import org.wikimedia.lsearch.related.Related; |
24 | 26 | import org.wikimedia.lsearch.related.RelatedTitle; |
— | — | @@ -86,12 +88,15 @@ |
87 | 89 | |
88 | 90 | public void writeSiteinfo(Siteinfo info) throws IOException { |
89 | 91 | this.info = info; |
| 92 | + RMIMessengerClient messenger = new RMIMessengerClient(true); |
90 | 93 | // write to localization |
| 94 | + HashMap<Integer,String> map = new HashMap<Integer,String>(); |
91 | 95 | Iterator it = info.Namespaces.orderedEntries(); |
92 | 96 | while(it.hasNext()){ |
93 | 97 | Entry<Integer,String> pair = (Entry<Integer,String>)it.next(); |
94 | | - Localization.addCustomMapping(pair.getValue(),pair.getKey(),iid.getDBname()); |
| 98 | + map.put(pair.getKey(),pair.getValue()); |
95 | 99 | } |
| 100 | + messenger.addLocalizationCustomMapping(iid.getIndexHost(),map,iid.getDBname()); |
96 | 101 | } |
97 | 102 | |
98 | 103 | public void close() throws IOException { |
Index: branches/lucene-search-2.1/src/org/wikimedia/lsearch/ranks/Links.java |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | |
4 | 4 | import java.io.ByteArrayInputStream; |
5 | 5 | import java.io.ByteArrayOutputStream; |
| 6 | +import java.io.File; |
6 | 7 | import java.io.IOException; |
7 | 8 | import java.io.ObjectInputStream; |
8 | 9 | import java.io.ObjectOutputStream; |
— | — | @@ -40,6 +41,7 @@ |
41 | 42 | import org.apache.lucene.search.PhraseQuery; |
42 | 43 | import org.apache.lucene.search.TermQuery; |
43 | 44 | import org.apache.lucene.store.Directory; |
| 45 | +import org.apache.lucene.store.FSDirectory; |
44 | 46 | import org.apache.lucene.store.RAMDirectory; |
45 | 47 | import org.wikimedia.lsearch.analyzers.FilterFactory; |
46 | 48 | import org.wikimedia.lsearch.analyzers.PrefixAnalyzer; |
— | — | @@ -224,7 +226,7 @@ |
225 | 227 | if(writer == null){ |
226 | 228 | if(directory == null) |
227 | 229 | throw new RuntimeException("Opened for read, but trying to write"); |
228 | | - writer = new IndexWriter(directory,new SimpleAnalyzer(),false); |
| 230 | + writer = WikiIndexModifier.openForWrite(((FSDirectory)directory).getFile().getAbsolutePath(),false,new SimpleAnalyzer()); |
229 | 231 | initWriter(writer); |
230 | 232 | reader = null; |
231 | 233 | searcher = null; |
— | — | @@ -247,24 +249,29 @@ |
248 | 250 | Transaction trans = new Transaction(iid, IndexId.Transaction.INDEX); |
249 | 251 | trans.begin(); |
250 | 252 | try{ |
251 | | - ensureRead(); |
252 | | - // batch delete |
253 | | - for(IndexUpdateRecord rec : records){ |
254 | | - if(rec.doDelete()){ |
255 | | - Article a = rec.getArticle(); |
256 | | - if(a.getTitle()==null || a.getTitle().equals("")){ |
257 | | - // try to fetch ns:title so we can have nicer debug info |
258 | | - String key = getKeyFromPageId(rec.getIndexKey()); |
259 | | - if(key != null) |
260 | | - a.setNsTitleKey(key); |
| 253 | + try{ |
| 254 | + ensureRead(); |
| 255 | + // batch delete |
| 256 | + for(IndexUpdateRecord rec : records){ |
| 257 | + if(rec.doDelete()){ |
| 258 | + Article a = rec.getArticle(); |
| 259 | + if(a.getTitle()==null || a.getTitle().equals("")){ |
| 260 | + // try to fetch ns:title so we can have nicer debug info |
| 261 | + String key = getKeyFromPageId(rec.getIndexKey()); |
| 262 | + if(key != null) |
| 263 | + a.setNsTitleKey(key); |
| 264 | + } |
| 265 | + log.debug(iid+": Deleting "+a); |
| 266 | + reader.deleteDocuments(new Term("article_pageid",rec.getIndexKey())); |
261 | 267 | } |
262 | | - log.debug(iid+": Deleting "+a); |
263 | | - reader.deleteDocuments(new Term("article_pageid",rec.getIndexKey())); |
264 | 268 | } |
| 269 | + flush(); |
| 270 | + } catch(Exception e){ |
| 271 | + // report but continue |
| 272 | + log.warn("Error opening links index "+ iid +": "+e.getMessage()); |
265 | 273 | } |
266 | | - flush(); |
267 | 274 | // batch add |
268 | | - writer = new IndexWriter(iid.getIndexPath(),new SimpleAnalyzer(),false); |
| 275 | + writer = WikiIndexModifier.openForWrite(iid.getIndexPath(),false,new SimpleAnalyzer()); |
269 | 276 | initWriter(writer); |
270 | 277 | for(IndexUpdateRecord rec : records){ |
271 | 278 | if(rec.doAdd()){ |