Mercurial Hosting > luan
diff lucene/src/luan/modules/lucene/LuceneIndex.java @ 646:cdc70de628b5
simplify LuanException
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Mar 2016 19:58:39 -0600 |
parents | 8281a248c47e |
children | b21d82ee5756 |
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java Tue Mar 29 18:09:51 2016 -0600 +++ b/lucene/src/luan/modules/lucene/LuceneIndex.java Tue Mar 29 19:58:39 2016 -0600 @@ -115,7 +115,7 @@ reader = DirectoryReader.open(dir); luan.onClose(this); searcher = new IndexSearcher(reader); - initId(luan); + initId(); } @@ -155,23 +155,23 @@ Set indexedOnlySet = new HashSet(); Object typeObj = doc.get(luan,"type"); if( typeObj==null ) - throw new LuanException(luan,"missing 'type' field"); + throw new LuanException("missing 'type' field"); if( !(typeObj instanceof String) ) - throw new LuanException(luan,"type must be string"); + throw new LuanException("type must be string"); String type = (String)typeObj; Object indexedOnlyObj = indexed_only_fields.get(luan,type); if( indexedOnlyObj != null ) { if( !(indexedOnlyObj instanceof LuanTable) ) - throw new LuanException(luan,"indexed_only_fields elements must be tables"); + throw new LuanException("indexed_only_fields elements must be tables"); LuanTable indexedOnly = (LuanTable)indexedOnlyObj; for( Map.Entry<Object,Object> entry : indexedOnly.iterable(luan) ) { Object key = entry.getKey(); if( !(key instanceof String) ) - throw new LuanException(luan,"indexed_only_fields."+type+" entries must be strings"); + throw new LuanException("indexed_only_fields."+type+" entries must be strings"); String name = (String)key; Object value = entry.getValue(); if( !(value instanceof LuanFunction) ) - throw new LuanException(luan,"indexed_only_fields."+type+" values must be functions"); + throw new LuanException("indexed_only_fields."+type+" values must be functions"); LuanFunction fn = (LuanFunction)value; value = Luan.first(fn.call(luan,new Object[]{doc})); doc.put(luan, name, value ); @@ -183,7 +183,7 @@ try { id = (Long)obj; } catch(ClassCastException e) { - throw new LuanException(luan,"id should be Long but is "+obj.getClass().getSimpleName()); + throw new LuanException("id should be Long but is "+obj.getClass().getSimpleName()); } boolean commit = !writeLock.isHeldByCurrentThread(); @@ -218,7 +218,7 @@ private long idLim = 0; private final int idBatch = 10; - private void initId(LuanState luan) throws LuanException, IOException { + private void initId() throws LuanException, IOException { TopDocs td = searcher.search(new TermQuery(new Term("type","next_id")),1); /* // tmp hack @@ -258,9 +258,9 @@ } - public void backup(LuanState luan,String zipFile) throws LuanException, IOException { + public void backup(String zipFile) throws LuanException, IOException { if( !zipFile.endsWith(".zip") ) - throw new LuanException(luan,"file "+zipFile+" doesn't end with '.zip'"); + throw new LuanException("file "+zipFile+" doesn't end with '.zip'"); IndexCommit ic = snapshotDeletionPolicy.snapshot(); try { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile)); @@ -311,9 +311,9 @@ @Override public Object call(LuanState luan,Object[] args) throws LuanException { try { - return toTable(luan,searcher.doc(docID)); + return toTable(searcher.doc(docID)); } catch(IOException e) { - throw new LuanException(luan,e); + throw new LuanException(e); } } } @@ -352,7 +352,7 @@ } public int advanced_search( final LuanState luan, String queryStr, LuanFunction fn, Integer n, String sortStr ) throws LuanException, IOException, ParseException { - Utils.checkNotNull(luan,queryStr); + Utils.checkNotNull(queryStr); Query query = SaneQueryParser.parseQuery(mfp,queryStr); IndexSearcher searcher = threadLocalSearcher.get(); boolean inTransaction = searcher != null; @@ -361,7 +361,7 @@ try { if( fn!=null && n==null ) { if( sortStr != null ) - throw new LuanException(luan,"sort must be nil when n is nil"); + throw new LuanException("sort must be nil when n is nil"); final DocFn docFn = new DocFn(searcher); MyCollector col = new MyCollector() { @Override public void collect(int doc) { @@ -402,7 +402,7 @@ public Object search_in_transaction(LuanState luan,LuanFunction fn) throws LuanException, IOException { if( threadLocalSearcher.get() != null ) - throw new LuanException(luan,"can't nest search_in_transaction calls"); + throw new LuanException("can't nest search_in_transaction calls"); IndexSearcher searcher = openSearcher(); threadLocalSearcher.set(searcher); try { @@ -427,14 +427,14 @@ @Override public void __new_index(LuanState luan,LuanTable tbl,Object key,Object value) throws LuanException { if( !(key instanceof String) ) - throw new LuanException(luan,"key must be string"); + throw new LuanException("key must be string"); String field = (String)key; if( value==null ) { // delete mfp.fields.remove(field); return; } if( !(value instanceof FieldParser) ) - throw new LuanException(luan,"value must be FieldParser like the values of Lucene.type"); + throw new LuanException("value must be FieldParser like the values of Lucene.type"); FieldParser parser = (FieldParser)value; mfp.fields.put( field, parser ); } @@ -451,7 +451,7 @@ - private IndexableField newField(LuanState luan,String name,Object value,Field.Store store,Set<String> indexed) + private IndexableField newField(String name,Object value,Field.Store store,Set<String> indexed) throws LuanException { if( value instanceof String ) { @@ -491,7 +491,7 @@ byte[] b = (byte[])value; return new StoredField(name, b); } else - throw new LuanException(luan,"invalid value type "+value.getClass()+"' for '"+name+"'"); + throw new LuanException("invalid value type "+value.getClass()+"' for '"+name+"'"); } private Document toLucene(LuanState luan,LuanTable table,Set indexOnly) throws LuanException { @@ -500,23 +500,23 @@ for( Map.Entry<Object,Object> entry : table.iterable(luan) ) { Object key = entry.getKey(); if( !(key instanceof String) ) - throw new LuanException(luan,"key must be string"); + throw new LuanException("key must be string"); String name = (String)key; Object value = entry.getValue(); Field.Store store = indexOnly.contains(name) ? Field.Store.NO : Field.Store.YES; if( !(value instanceof LuanTable) ) { - doc.add(newField(luan, name, value, store, indexed)); + doc.add(newField(name, value, store, indexed)); } else { // list LuanTable list = (LuanTable)value; for( Object el : list.asList() ) { - doc.add(newField(luan, name, el, store, indexed)); + doc.add(newField(name, el, store, indexed)); } } } return doc; } - private static Object getValue(LuanState luan,IndexableField ifld) throws LuanException { + private static Object getValue(IndexableField ifld) throws LuanException { BytesRef br = ifld.binaryValue(); if( br != null ) return br.bytes; @@ -526,16 +526,16 @@ String s = ifld.stringValue(); if( s != null ) return s; - throw new LuanException(luan,"invalid field type for "+ifld); + throw new LuanException("invalid field type for "+ifld); } - private static LuanTable toTable(LuanState luan,Document doc) throws LuanException { + private static LuanTable toTable(Document doc) throws LuanException { if( doc==null ) return null; LuanTable table = new LuanTable(); for( IndexableField ifld : doc ) { String name = ifld.name(); - Object value = getValue(luan,ifld); + Object value = getValue(ifld); Object old = table.rawGet(name); if( old == null ) { table.rawPut(name,value);