/* * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at . * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT * WARRANTY OF ANY KIND, either express or implied. See the License for the specific * language governing rights and limitations under the License. * * The Original Code is the Venice Web Communities System. * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ package com.silverwrist.dynamo.index; import java.io.*; import java.lang.ref.*; import java.util.*; import org.apache.log4j.Logger; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.document.*; import org.apache.lucene.index.*; import org.apache.lucene.search.*; import org.apache.lucene.store.Directory; import com.silverwrist.util.*; import com.silverwrist.dynamo.except.*; import com.silverwrist.dynamo.iface.*; import com.silverwrist.dynamo.util.*; class IndexServiceImpl implements IndexService { /*-------------------------------------------------------------------------------- * Internal counting HitCollector *-------------------------------------------------------------------------------- */ private static class CountingCollector extends HitCollector { /*==================================================================== * Attributes *==================================================================== */ private int m_count = 0; /*==================================================================== * Constructor *==================================================================== */ CountingCollector() { // do nothing } // end constructor /*==================================================================== * Abstract implementations from class HitCollector *==================================================================== */ public void collect(int doc, float score) { m_count++; } // end collect /*==================================================================== * External operations *==================================================================== */ int getCount() { return m_count; } // end getCount } // end class CountingCollector /*-------------------------------------------------------------------------------- * Internal HitCollector that gathers a request subset *-------------------------------------------------------------------------------- */ private class SubsetCollector extends HitCollector { /*==================================================================== * Attributes *==================================================================== */ private int[] m_docs; private float[] m_scores; private int m_offset; private int m_size = 0; /*==================================================================== * Constructor *==================================================================== */ SubsetCollector(int offset, int count) { m_docs = new int[count]; m_scores = new float[count]; m_offset = offset; } // end constructor /*==================================================================== * Abstract implementations from class HitCollector *==================================================================== */ public void collect(int doc, float score) { if (m_offset>0) { // skip documents at beginning of list m_offset--; return; } // end if if (m_size=0) queries.add(new WildcardQuery(new Term("scope",match_scope))); else if (match_scope.indexOf('*')>=0) { // append another query String s = match_scope.substring(0,match_scope.length()-1); if (s.indexOf('*')<0) queries.add(new PrefixQuery(new Term("scope",s))); else queries.add(new WildcardQuery(new Term("scope",match_scope))); } // end else if else // match the scope directly queries.add(new TermQuery(new Term("scope",match_scope))); } // end if // Boil down all the queries for me. if (queries.size()==0) return null; if (queries.size()==1) return (Query)(queries.get(0)); BooleanQuery rc = new BooleanQuery(); for (int i=0; i0); } // end try catch (IOException e) { // translate Lucene's IOException here IndexException ie = new IndexException(IndexServiceImpl.class,"IndexMessages","deleteItem.fail",e); ie.setParameter(0,item_namespace); ie.setParameter(1,item_name); ie.setParameter(2,m_identity.toString()); throw ie; } // end catch } // end deleteItem public CompiledQuery compileQuery(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner, String match_scope) throws IndexException { Query query = compileInternal(query_string,date_low,date_high,match_owner,match_scope); return new CompiledQuery(query); } // end compileQuery public List query(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner, String match_scope, int offset, int count) throws IndexException { Query query = compileInternal(query_string,date_low,date_high,match_owner,match_scope); return doQuery(query,offset,count); } // end query public List query(CompiledQuery query, int offset, int count) throws IndexException { return doQuery(query.getQuery(),offset,count); } // end query public int queryCount(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner, String match_scope) throws IndexException { Query query = compileInternal(query_string,date_low,date_high,match_owner,match_scope); return doQueryCount(query); } // end queryCount public int queryCount(CompiledQuery query) throws IndexException { return doQueryCount(query.getQuery()); } // end queryCount } // end class IndexServiceImpl