/*
* $Header$
* $Revision: 1749 $
* $Date: 2006-04-04 08:41:40 -0700 $
*
* ====================================================================
*
* Copyright 1999-2002 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.slide.search.basic;
import java.util.Iterator;
import org.apache.slide.common.Namespace;
import org.apache.slide.common.Scope;
import org.apache.slide.common.ServiceAccessException;
import org.apache.slide.common.SlideRuntimeException;
import org.apache.slide.search.InvalidScopeException;
import org.apache.slide.search.LuceneSearchQueryResult;
import org.apache.slide.search.QueryScope;
import org.apache.slide.search.SearchQueryResult;
import org.apache.slide.search.SearchToken;
/**
* Envelopes all queries that are necessary, if a scope covers several stores.
* For example: /mycoll is mapped to an SQL store, /mycoll/xml is mapped to an
* XML database. A query with scope /mycoll must be divided in two different
* queries, the result must be joined.
*
* @version $Revision: 1749 $
*
**/
public class LuceneBasicQueryEnvelope extends BasicQueryEnvelope {
/*
* Constructs a LuceneBasicQueryEnvelope
*
* @param token the searchtoken
* @param queryScope the scope of this query
*
* @throws InvalidScopeException
*/
public LuceneBasicQueryEnvelope (SearchToken token, QueryScope[] queryScope)
throws InvalidScopeException
{
super(token,queryScope);
}
/**
* Executes each involved query and merges the results
*
* @return a SearchQueryResult
*
* @throws ServiceAccessException
*
*/
public SearchQueryResult execute() throws ServiceAccessException {
Iterator it = subQueries.keySet().iterator();
SearchQueryResult result = null;
if (topLevelQuery.orderBy != null) {
result = new LuceneSearchQueryResult (topLevelQuery.orderBy.getComparator());
}
else {
result = new LuceneSearchQueryResult ();
}
while (it.hasNext()) {
Scope scope = (Scope)it.next();
BasicQuery query = (BasicQuery)subQueries.get (scope);
query.setScope (calculateSubQueryScope(scope));
SearchQueryResult subResult = query.execute();
result.add (subResult);
if (subResult.getStatus() != 0) {
result.setStatus (subResult.getStatus());
result.setDescription (subResult.getDescription());
}
}
return result;
}
/**
* creates a subquery
*
* @param namespace a Namespace
* @param slideScope a String
* @param token a SearchToken
*
* @return a BasicQueryImpl
*
* @throws SlideRuntimeException
*
*/
protected BasicQueryImpl createSubQuery (Namespace namespace,
String slideScope,
SearchToken token)
throws SlideRuntimeException
{
BasicQueryImpl q = super.createSubQuery(namespace,slideScope,token);
return q;
}
}
|