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.handler;
17:
18: import java.io.IOException;
19: import java.util.HashMap;
20:
21: import org.apache.solr.request.MapSolrParams;
22: import org.apache.solr.request.SolrParams;
23: import org.apache.solr.request.SolrQueryRequest;
24: import org.apache.solr.request.SolrQueryResponse;
25: import org.apache.solr.update.CommitUpdateCommand;
26: import org.apache.solr.util.UpdateParams;
27:
28: /**
29: * Common helper functions for RequestHandlers
30: *
31: * @author ryan
32: * @version $Id: RequestHandlerUtils.java 534669 2007-05-03 00:59:09Z ryan $
33: * @since solr 1.2
34: */
35: public class RequestHandlerUtils {
36: /**
37: * A common way to mark the response format as experimental
38: */
39: public static void addExperimentalFormatWarning(
40: SolrQueryResponse rsp) {
41: rsp
42: .add("WARNING",
43: "This response format is experimental. It is likely to change in the future.");
44: }
45:
46: /**
47: * Check the request parameters and decide if it should commit or optimize.
48: * If it does, it will check parameters for "waitFlush" and "waitSearcher"
49: */
50: public static boolean handleCommit(SolrQueryRequest req,
51: SolrQueryResponse rsp, boolean force) throws IOException {
52: SolrParams params = req.getParams();
53: if (params == null) {
54: params = new MapSolrParams(new HashMap<String, String>());
55: }
56:
57: boolean optimize = params.getBool(UpdateParams.OPTIMIZE, false);
58: boolean commit = params.getBool(UpdateParams.COMMIT, false);
59:
60: if (optimize || commit || force) {
61: CommitUpdateCommand cmd = new CommitUpdateCommand(optimize);
62: cmd.waitFlush = params.getBool(UpdateParams.WAIT_FLUSH,
63: cmd.waitFlush);
64: cmd.waitSearcher = params.getBool(
65: UpdateParams.WAIT_SEARCHER, cmd.waitSearcher);
66: req.getCore().getUpdateHandler().commit(cmd);
67:
68: // Lets wait till after solr1.2 to define consistent output format
69: //if( optimize ) {
70: // rsp.add( "optimize", true );
71: //}
72: //else {
73: // rsp.add( "commit", true );
74: //}
75: return true;
76: }
77: return false;
78: }
79: }
|