comparison lucene/src/luan/modules/lucene/LuceneIndex.java @ 572:f1601a4ce1aa

fix stack when calling meta-methods
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 12 Jul 2015 21:34:23 -0600
parents 0be287ab0309
children 6cc2f047019b
comparison
equal deleted inserted replaced
571:cd944b010f25 572:f1601a4ce1aa
132 writeLock.unlock(); 132 writeLock.unlock();
133 } 133 }
134 } 134 }
135 135
136 public void save(LuanState luan,LuanTable doc) throws LuanException, IOException { 136 public void save(LuanState luan,LuanTable doc) throws LuanException, IOException {
137 if( doc.get(luan,"type")==null ) 137 if( doc.get(luan.JAVA,"type")==null )
138 throw luan.exception("missing 'type' field"); 138 throw luan.exception("missing 'type' field");
139 Long id = (Long)doc.get(luan,"id"); 139 Long id = (Long)doc.get(luan.JAVA,"id");
140 140
141 boolean commit = !writeLock.isHeldByCurrentThread(); 141 boolean commit = !writeLock.isHeldByCurrentThread();
142 writeLock.lock(); 142 writeLock.lock();
143 try { 143 try {
144 if( id == null ) { 144 if( id == null ) {
145 id = nextId(luan); 145 id = nextId(luan);
146 doc.put(luan,"id",id); 146 doc.put(luan.JAVA,"id",id);
147 writer.addDocument(toLucene(luan,doc)); 147 writer.addDocument(toLucene(luan,doc));
148 } else { 148 } else {
149 writer.updateDocument( term("id",id), toLucene(luan,doc) ); 149 writer.updateDocument( term("id",id), toLucene(luan,doc) );
150 } 150 }
151 if(commit) writer.commit(); 151 if(commit) writer.commit();
401 401
402 402
403 private Document toLucene(LuanState luan,LuanTable table) throws LuanException { 403 private Document toLucene(LuanState luan,LuanTable table) throws LuanException {
404 Set<String> indexed = mfp.fields.keySet(); 404 Set<String> indexed = mfp.fields.keySet();
405 Document doc = new Document(); 405 Document doc = new Document();
406 for( Map.Entry<Object,Object> entry : table.iterable(luan) ) { 406 for( Map.Entry<Object,Object> entry : table.iterable(luan.JAVA) ) {
407 Object key = entry.getKey(); 407 Object key = entry.getKey();
408 if( !(key instanceof String) ) 408 if( !(key instanceof String) )
409 throw luan.exception("key must be string"); 409 throw luan.exception("key must be string");
410 String name = (String)key; 410 String name = (String)key;
411 Object value = entry.getValue(); 411 Object value = entry.getValue();