comparison lucene/src/luan/modules/lucene/LuceneIndex.java @ 575:7c3ad6db8ac3

make LuanState.JAVA private
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 13 Jul 2015 18:34:31 -0600
parents 6cc2f047019b
children 60c549d43988
comparison
equal deleted inserted replaced
574:6cc2f047019b 575:7c3ad6db8ac3
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.JAVA,"type")==null ) 137 if( doc.get(luan,"type")==null )
138 throw luan.exception("missing 'type' field"); 138 throw luan.exception("missing 'type' field");
139 Long id = (Long)doc.get(luan.JAVA,"id"); 139 Long id = (Long)doc.get(luan,"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.JAVA,"id",id); 146 doc.put(luan,"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.JAVA) ) { 406 for( Map.Entry<Object,Object> entry : table.iterable(luan) ) {
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();