added methods and a storage object for precompiling queries
This commit is contained in:
parent
1b15703d3f
commit
c019f92b90
|
@ -20,6 +20,7 @@ package com.silverwrist.dynamo.iface;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.silverwrist.dynamo.except.IndexException;
|
import com.silverwrist.dynamo.except.IndexException;
|
||||||
|
import com.silverwrist.dynamo.index.CompiledQuery;
|
||||||
|
|
||||||
public interface IndexService
|
public interface IndexService
|
||||||
{
|
{
|
||||||
|
@ -28,10 +29,18 @@ public interface IndexService
|
||||||
|
|
||||||
public boolean deleteItem(String item_namespace, String item_name, Object item) throws IndexException;
|
public boolean deleteItem(String item_namespace, String item_name, Object item) throws IndexException;
|
||||||
|
|
||||||
|
public CompiledQuery compileQuery(String query_string, java.util.Date date_low, java.util.Date date_high,
|
||||||
|
DynamoUser match_owner, String match_scope) throws IndexException;
|
||||||
|
|
||||||
public List query(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner,
|
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;
|
String match_scope, int offset, int count) throws IndexException;
|
||||||
|
|
||||||
|
public List query(CompiledQuery query, int offset, int count) throws IndexException;
|
||||||
|
|
||||||
public int queryCount(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner,
|
public int queryCount(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner,
|
||||||
String match_scope) throws IndexException;
|
String match_scope) throws IndexException;
|
||||||
|
|
||||||
|
public int queryCount(CompiledQuery query) throws IndexException;
|
||||||
|
|
||||||
} // end interface IndexService
|
} // end interface IndexService
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* 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 <http://www.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* 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 <erbo@silcom.com>,
|
||||||
|
* 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 org.apache.lucene.search.Query;
|
||||||
|
|
||||||
|
public class CompiledQuery
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Attributes
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Query m_query;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* Constructor
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
CompiledQuery(Query query)
|
||||||
|
{
|
||||||
|
m_query = query;
|
||||||
|
|
||||||
|
} // end constructor
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------
|
||||||
|
* External getters
|
||||||
|
*--------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
Query getQuery()
|
||||||
|
{
|
||||||
|
return m_query;
|
||||||
|
|
||||||
|
} // end getQuery
|
||||||
|
|
||||||
|
} // end class CompiledQuery
|
|
@ -250,8 +250,8 @@ class IndexServiceImpl implements IndexService
|
||||||
|
|
||||||
} // end createTag
|
} // end createTag
|
||||||
|
|
||||||
private final Query compileQuery(String query_string, java.util.Date date_low, java.util.Date date_high,
|
private final Query compileInternal(String query_string, java.util.Date date_low, java.util.Date date_high,
|
||||||
DynamoUser match_owner, String match_scope) throws IndexException
|
DynamoUser match_owner, String match_scope) throws IndexException
|
||||||
{
|
{
|
||||||
ArrayList queries = new ArrayList();
|
ArrayList queries = new ArrayList();
|
||||||
if (query_string!=null)
|
if (query_string!=null)
|
||||||
|
@ -312,7 +312,89 @@ class IndexServiceImpl implements IndexService
|
||||||
rc.add((Query)(queries.get(i)),true,false);
|
rc.add((Query)(queries.get(i)),true,false);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
} // end compileQuery
|
} // end compileInternal
|
||||||
|
|
||||||
|
private final List doQuery(Query query, int offset, int count) throws IndexException
|
||||||
|
{
|
||||||
|
SubsetCollector subc = new SubsetCollector(offset,count);
|
||||||
|
List rc = null;
|
||||||
|
IndexReader irdr = null;
|
||||||
|
IndexSearcher srch = null;
|
||||||
|
try
|
||||||
|
{ // run that puppy!
|
||||||
|
irdr = IndexReader.open(m_directory);
|
||||||
|
srch = new IndexSearcher(irdr);
|
||||||
|
if (query==null)
|
||||||
|
visitAllDocuments(srch,subc);
|
||||||
|
else
|
||||||
|
srch.search(query,subc);
|
||||||
|
rc = subc.outputItems(irdr);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // the query failed somehow - throw an error
|
||||||
|
throw new IndexException(IndexServiceImpl.class,"IndexMessages","query.fail",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // make sure we close down OK
|
||||||
|
try
|
||||||
|
{ // close the search and index reader
|
||||||
|
if (srch!=null)
|
||||||
|
srch.close();
|
||||||
|
if (irdr!=null)
|
||||||
|
irdr.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // shouldn't happen
|
||||||
|
logger.warn("query(): error closing stuff",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
} // end doQuery
|
||||||
|
|
||||||
|
private final int doQueryCount(Query query) throws IndexException
|
||||||
|
{
|
||||||
|
CountingCollector cc = new CountingCollector();
|
||||||
|
IndexSearcher srch = null;
|
||||||
|
try
|
||||||
|
{ // run that puppy!
|
||||||
|
srch = new IndexSearcher(m_directory);
|
||||||
|
if (query==null)
|
||||||
|
visitAllDocuments(srch,cc);
|
||||||
|
else
|
||||||
|
srch.search(query,cc);
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // the query failed somehow - throw an error
|
||||||
|
throw new IndexException(IndexServiceImpl.class,"IndexMessages","query.fail",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
finally
|
||||||
|
{ // make sure we close down OK
|
||||||
|
try
|
||||||
|
{ // close the search and index reader
|
||||||
|
if (srch!=null)
|
||||||
|
srch.close();
|
||||||
|
|
||||||
|
} // end try
|
||||||
|
catch (IOException e)
|
||||||
|
{ // shouldn't happen
|
||||||
|
logger.warn("queryCount(): error closing stuff",e);
|
||||||
|
|
||||||
|
} // end catch
|
||||||
|
|
||||||
|
} // end finally
|
||||||
|
|
||||||
|
return cc.getCount();
|
||||||
|
|
||||||
|
} // end doQueryCount
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Implementations from interface IndexService
|
* Implementations from interface IndexService
|
||||||
|
@ -374,90 +456,39 @@ class IndexServiceImpl implements IndexService
|
||||||
|
|
||||||
} // end deleteItem
|
} // 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,
|
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
|
String match_scope, int offset, int count) throws IndexException
|
||||||
{
|
{
|
||||||
Query query = compileQuery(query_string,date_low,date_high,match_owner,match_scope);
|
Query query = compileInternal(query_string,date_low,date_high,match_owner,match_scope);
|
||||||
SubsetCollector subc = new SubsetCollector(offset,count);
|
return doQuery(query,offset,count);
|
||||||
|
|
||||||
List rc = null;
|
} // end query
|
||||||
IndexReader irdr = null;
|
|
||||||
IndexSearcher srch = null;
|
|
||||||
try
|
|
||||||
{ // run that puppy!
|
|
||||||
irdr = IndexReader.open(m_directory);
|
|
||||||
srch = new IndexSearcher(irdr);
|
|
||||||
if (query==null)
|
|
||||||
visitAllDocuments(srch,subc);
|
|
||||||
else
|
|
||||||
srch.search(query,subc);
|
|
||||||
rc = subc.outputItems(irdr);
|
|
||||||
|
|
||||||
} // end try
|
public List query(CompiledQuery query, int offset, int count) throws IndexException
|
||||||
catch (IOException e)
|
{
|
||||||
{ // the query failed somehow - throw an error
|
return doQuery(query.getQuery(),offset,count);
|
||||||
throw new IndexException(IndexServiceImpl.class,"IndexMessages","query.fail",e);
|
|
||||||
|
|
||||||
} // end catch
|
|
||||||
finally
|
|
||||||
{ // make sure we close down OK
|
|
||||||
try
|
|
||||||
{ // close the search and index reader
|
|
||||||
if (srch!=null)
|
|
||||||
srch.close();
|
|
||||||
if (irdr!=null)
|
|
||||||
irdr.close();
|
|
||||||
|
|
||||||
} // end try
|
|
||||||
catch (IOException e)
|
|
||||||
{ // shouldn't happen
|
|
||||||
logger.warn("query(): error closing stuff",e);
|
|
||||||
|
|
||||||
} // end catch
|
|
||||||
|
|
||||||
} // end finally
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
} // end query
|
} // end query
|
||||||
|
|
||||||
public int queryCount(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner,
|
public int queryCount(String query_string, java.util.Date date_low, java.util.Date date_high, DynamoUser match_owner,
|
||||||
String match_scope) throws IndexException
|
String match_scope) throws IndexException
|
||||||
{
|
{
|
||||||
Query query = compileQuery(query_string,date_low,date_high,match_owner,match_scope);
|
Query query = compileInternal(query_string,date_low,date_high,match_owner,match_scope);
|
||||||
CountingCollector cc = new CountingCollector();
|
return doQueryCount(query);
|
||||||
IndexSearcher srch = null;
|
|
||||||
try
|
|
||||||
{ // run that puppy!
|
|
||||||
srch = new IndexSearcher(m_directory);
|
|
||||||
if (query==null)
|
|
||||||
visitAllDocuments(srch,cc);
|
|
||||||
else
|
|
||||||
srch.search(query,cc);
|
|
||||||
|
|
||||||
} // end try
|
} // end queryCount
|
||||||
catch (IOException e)
|
|
||||||
{ // the query failed somehow - throw an error
|
|
||||||
throw new IndexException(IndexServiceImpl.class,"IndexMessages","query.fail",e);
|
|
||||||
|
|
||||||
} // end catch
|
public int queryCount(CompiledQuery query) throws IndexException
|
||||||
finally
|
{
|
||||||
{ // make sure we close down OK
|
return doQueryCount(query.getQuery());
|
||||||
try
|
|
||||||
{ // close the search and index reader
|
|
||||||
if (srch!=null)
|
|
||||||
srch.close();
|
|
||||||
|
|
||||||
} // end try
|
|
||||||
catch (IOException e)
|
|
||||||
{ // shouldn't happen
|
|
||||||
logger.warn("queryCount(): error closing stuff",e);
|
|
||||||
|
|
||||||
} // end catch
|
|
||||||
|
|
||||||
} // end finally
|
|
||||||
|
|
||||||
return cc.getCount();
|
|
||||||
|
|
||||||
} // end queryCount
|
} // end queryCount
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user