001: /*
002: * $Header$
003: * $Revision: 1749 $
004: * $Date: 2006-04-04 08:41:40 -0700 $
005: *
006: * ====================================================================
007: *
008: * Copyright 1999-2002 The Apache Software Foundation
009: *
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: *
022: */
023:
024: package org.apache.slide.search.basic;
025:
026: import java.util.Iterator;
027:
028: import org.apache.slide.common.Namespace;
029: import org.apache.slide.common.Scope;
030: import org.apache.slide.common.ServiceAccessException;
031: import org.apache.slide.common.SlideRuntimeException;
032: import org.apache.slide.search.InvalidScopeException;
033: import org.apache.slide.search.LuceneSearchQueryResult;
034: import org.apache.slide.search.QueryScope;
035: import org.apache.slide.search.SearchQueryResult;
036: import org.apache.slide.search.SearchToken;
037:
038: /**
039: * Envelopes all queries that are necessary, if a scope covers several stores.
040: * For example: /mycoll is mapped to an SQL store, /mycoll/xml is mapped to an
041: * XML database. A query with scope /mycoll must be divided in two different
042: * queries, the result must be joined.
043: *
044: * @version $Revision: 1749 $
045: *
046: **/
047: public class LuceneBasicQueryEnvelope extends BasicQueryEnvelope {
048:
049: /*
050: * Constructs a LuceneBasicQueryEnvelope
051: *
052: * @param token the searchtoken
053: * @param queryScope the scope of this query
054: *
055: * @throws InvalidScopeException
056: */
057: public LuceneBasicQueryEnvelope(SearchToken token,
058: QueryScope[] queryScope) throws InvalidScopeException {
059: super (token, queryScope);
060: }
061:
062: /**
063: * Executes each involved query and merges the results
064: *
065: * @return a SearchQueryResult
066: *
067: * @throws ServiceAccessException
068: *
069: */
070: public SearchQueryResult execute() throws ServiceAccessException {
071:
072: Iterator it = subQueries.keySet().iterator();
073: SearchQueryResult result = null;
074:
075: if (topLevelQuery.orderBy != null) {
076: result = new LuceneSearchQueryResult(topLevelQuery.orderBy
077: .getComparator());
078: } else {
079: result = new LuceneSearchQueryResult();
080: }
081:
082: while (it.hasNext()) {
083: Scope scope = (Scope) it.next();
084:
085: BasicQuery query = (BasicQuery) subQueries.get(scope);
086: query.setScope(calculateSubQueryScope(scope));
087:
088: SearchQueryResult subResult = query.execute();
089:
090: result.add(subResult);
091: if (subResult.getStatus() != 0) {
092: result.setStatus(subResult.getStatus());
093: result.setDescription(subResult.getDescription());
094: }
095: }
096:
097: return result;
098: }
099:
100: /**
101: * creates a subquery
102: *
103: * @param namespace a Namespace
104: * @param slideScope a String
105: * @param token a SearchToken
106: *
107: * @return a BasicQueryImpl
108: *
109: * @throws SlideRuntimeException
110: *
111: */
112: protected BasicQueryImpl createSubQuery(Namespace namespace,
113: String slideScope, SearchToken token)
114: throws SlideRuntimeException {
115: BasicQueryImpl q = super.createSubQuery(namespace, slideScope,
116: token);
117:
118: return q;
119: }
120:
121: }
|