mirror of https://github.com/apache/lucene.git
factor out commit param parsing: SOLR-185
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@524612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
32d95f5c89
commit
665e7d7834
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.solr.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.solr.request.MapSolrParams;
|
||||
import org.apache.solr.request.SolrParams;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.request.SolrQueryResponse;
|
||||
import org.apache.solr.update.CommitUpdateCommand;
|
||||
|
||||
/**
|
||||
* Common helper functions for RequestHandlers
|
||||
*
|
||||
* @author ryan
|
||||
* @version $Id$
|
||||
* @since solr 1.2
|
||||
*/
|
||||
public class RequestHandlerUtils
|
||||
{
|
||||
/**
|
||||
* A common way to mark the response format as experimental
|
||||
*/
|
||||
public static void addExperimentalFormatWarning( SolrQueryResponse rsp )
|
||||
{
|
||||
rsp.add( "WARNING", "This response format is experimental. It is likely to change in the future." );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the request parameters and decide if it should commit or optimize.
|
||||
* If it does, it will check parameters for "waitFlush" and "waitSearcher"
|
||||
*/
|
||||
public static boolean handleCommit( SolrQueryRequest req, SolrQueryResponse rsp, boolean force ) throws IOException
|
||||
{
|
||||
SolrParams params = req.getParams();
|
||||
if( params == null ) {
|
||||
params = new MapSolrParams( new HashMap<String, String>() );
|
||||
}
|
||||
|
||||
boolean optimize = params.getBool( UpdateParams.OPTIMIZE, false );
|
||||
boolean commit = params.getBool( UpdateParams.COMMIT, false );
|
||||
|
||||
if( optimize || commit || force ) {
|
||||
CommitUpdateCommand cmd = new CommitUpdateCommand( optimize );
|
||||
cmd.waitFlush = params.getBool( UpdateParams.WAIT_FLUSH, cmd.waitFlush );
|
||||
cmd.waitSearcher = params.getBool( UpdateParams.WAIT_SEARCHER, cmd.waitSearcher );
|
||||
req.getCore().getUpdateHandler().commit( cmd );
|
||||
if( optimize ) {
|
||||
rsp.add( "optimize", true );
|
||||
}
|
||||
else {
|
||||
rsp.add( "commit", true );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue