01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.solr.core;
17:
18: import org.apache.solr.search.SolrIndexSearcher;
19: import org.apache.solr.search.DocList;
20: import org.apache.solr.search.DocIterator;
21: import org.apache.solr.request.LocalSolrQueryRequest;
22: import org.apache.solr.request.SolrQueryResponse;
23: import org.apache.solr.util.NamedList;
24:
25: import java.util.List;
26:
27: /**
28: * @author yonik
29: * @version $Id: QuerySenderListener.java 472574 2006-11-08 18:25:52Z yonik $
30: */
31: class QuerySenderListener extends AbstractSolrEventListener {
32:
33: public void newSearcher(SolrIndexSearcher newSearcher,
34: SolrIndexSearcher currentSearcher) {
35: final SolrIndexSearcher searcher = newSearcher;
36: SolrCore core = SolrCore.getSolrCore();
37: log.info("QuerySenderListener sending requests to "
38: + newSearcher);
39: for (NamedList nlst : (List<NamedList>) args.get("queries")) {
40: try {
41: // bind the request to a particular searcher (the newSearcher)
42: LocalSolrQueryRequest req = new LocalSolrQueryRequest(
43: core, nlst) {
44: public SolrIndexSearcher getSearcher() {
45: return searcher;
46: }
47:
48: public void close() {
49: }
50: };
51:
52: SolrQueryResponse rsp = new SolrQueryResponse();
53: core.execute(req, rsp);
54:
55: // Retrieve the Document instances (not just the ids) to warm
56: // the OS disk cache, and any Solr document cache. Only the top
57: // level values in the NamedList are checked for DocLists.
58: NamedList values = rsp.getValues();
59: for (int i = 0; i < values.size(); i++) {
60: Object o = values.getVal(i);
61: if (o instanceof DocList) {
62: DocList docs = (DocList) o;
63: for (DocIterator iter = docs.iterator(); iter
64: .hasNext();) {
65: newSearcher.doc(iter.nextDoc());
66: }
67: }
68: }
69:
70: req.close();
71:
72: } catch (Exception e) {
73: // do nothing... we want to continue with the other requests.
74: // the failure should have already been logged.
75: }
76: log.info("QuerySenderListener done.");
77: }
78: }
79:
80: }
|