Mercurial Hosting > luan
diff lucene/src/luan/modules/lucene/LuceneIndex.java @ 547:0be287ab0309
add lucene/Versioning and simplify Lucene fn names
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 15 Jun 2015 01:22:58 -0600 |
parents | eaef1005ab87 |
children | f1601a4ce1aa |
line wrap: on
line diff
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java Sun Jun 14 22:17:58 2015 -0600 +++ b/lucene/src/luan/modules/lucene/LuceneIndex.java Mon Jun 15 01:22:58 2015 -0600 @@ -114,53 +114,26 @@ } } - private static Term term(String key,int value) { - BytesRef br = new BytesRef(); - NumericUtils.intToPrefixCoded(value,0,br); - return new Term(key,br); - } - private static Term term(String key,long value) { BytesRef br = new BytesRef(); NumericUtils.longToPrefixCoded(value,0,br); return new Term(key,br); } - private static Term term(LuanState luan,String key,Object value) throws LuanException { - if( value instanceof String ) - return new Term( key, (String)value ); - if( value instanceof Integer ) - return term( key, (Integer)value ); - if( value instanceof Long ) - return term( key, (Long)value ); - if( value instanceof Float ) - return term( key, NumericUtils.floatToSortableInt((Float)value) ); - if( value instanceof Double ) - return term( key, NumericUtils.doubleToSortableLong((Double)value) ); - throw luan.exception("invalid value type '"+value.getClass().getSimpleName()+"' for key '"+key+"'"); - } - - public void delete_documents(LuanState luan,LuanTable tblTerms) throws LuanException, IOException { - List<Term> list = new ArrayList<Term>(); - for( Map.Entry<Object,Object> entry : tblTerms.iterable(luan) ) { - Object key = entry.getKey(); - Object value = entry.getValue(); - if( !(key instanceof String) ) - throw luan.exception("key must be a string but got "+key.getClass().getSimpleName()); - list.add( term( luan, (String)key, value ) ); - } + public void delete(LuanState luan,String queryStr) throws LuanException, IOException, ParseException { + Query query = SaneQueryParser.parseQuery(mfp,queryStr); boolean commit = !writeLock.isHeldByCurrentThread(); writeLock.lock(); try { - writer.deleteDocuments(list.toArray(new Term[list.size()])); + writer.deleteDocuments(query); if(commit) writer.commit(); } finally { writeLock.unlock(); } } - public void save_document(LuanState luan,LuanTable doc) throws LuanException, IOException { + public void save(LuanState luan,LuanTable doc) throws LuanException, IOException { if( doc.get(luan,"type")==null ) throw luan.exception("missing 'type' field"); Long id = (Long)doc.get(luan,"id"); @@ -199,6 +172,20 @@ private void initId(LuanState luan) throws LuanException, IOException { TopDocs td = searcher.search(new TermQuery(new Term("type","next_id")),1); + + // tmp hack + if( td.totalHits == 0 ) { + td = searcher.search(new TermQuery(new Term("type index","next_id")),1); + if( td.totalHits == 1 ) { + long idLim = (Long)searcher.doc(td.scoreDocs[0].doc).getField(FLD_NEXT_ID).numericValue(); + LuanTable doc = new LuanTable(); + doc.rawPut( "type", "next_id" ); + doc.rawPut( FLD_NEXT_ID, idLim ); + writer.addDocument(toLucene(luan,doc)); + writer.commit(); + } + } + switch(td.totalHits) { case 0: break; // do nothing @@ -327,7 +314,7 @@ MyCollector col = new MyCollector() { @Override public void collect(int doc) { try { - docFn.docID = doc; + docFn.docID = docBase + doc; luan.call(fn,new Object[]{++i,docFn}); } catch(LuanException e) { throw new LuanRuntimeException(e);