~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/solrj/src/java/org/apache/solr/client/solrj/request/AbstractUpdateRequest.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.client.solrj.request;
2
 
/**
3
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
4
 
 * contributor license agreements.  See the NOTICE file distributed with
5
 
 * this work for additional information regarding copyright ownership.
6
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
7
 
 * (the "License"); you may not use this file except in compliance with
8
 
 * the License.  You may obtain a copy of the License at
9
 
 *
10
 
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 
 *
12
 
 * Unless required by applicable law or agreed to in writing, software
13
 
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 
 * See the License for the specific language governing permissions and
16
 
 * limitations under the License.
17
 
 */
18
 
 
19
 
import org.apache.solr.client.solrj.SolrRequest;
20
 
import org.apache.solr.client.solrj.SolrServer;
21
 
import org.apache.solr.client.solrj.SolrServerException;
22
 
import org.apache.solr.client.solrj.response.UpdateResponse;
23
 
import org.apache.solr.common.params.ModifiableSolrParams;
24
 
import org.apache.solr.common.params.UpdateParams;
25
 
 
26
 
import java.io.IOException;
27
 
 
28
 
 
29
 
/**
30
 
 *
31
 
 *
32
 
 **/
33
 
public abstract class AbstractUpdateRequest extends SolrRequest {
34
 
  protected ModifiableSolrParams params;
35
 
  protected int commitWithin = -1;
36
 
 
37
 
  public enum ACTION {
38
 
    COMMIT,
39
 
    OPTIMIZE
40
 
  }
41
 
 
42
 
  public AbstractUpdateRequest(METHOD m, String path) {
43
 
    super(m, path);
44
 
  }
45
 
 
46
 
  /** Sets appropriate parameters for the given ACTION */
47
 
  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher ) {
48
 
    return setAction(action, waitFlush, waitSearcher, 1);
49
 
  }
50
 
 
51
 
  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments ) {
52
 
    if (params == null)
53
 
      params = new ModifiableSolrParams();
54
 
 
55
 
    if( action == ACTION.OPTIMIZE ) {
56
 
      params.set( UpdateParams.OPTIMIZE, "true" );
57
 
      params.set(UpdateParams.MAX_OPTIMIZE_SEGMENTS, maxSegments);
58
 
    }
59
 
    else if( action == ACTION.COMMIT ) {
60
 
      params.set( UpdateParams.COMMIT, "true" );
61
 
    }
62
 
    params.set( UpdateParams.WAIT_FLUSH, String.valueOf(waitFlush));
63
 
    params.set( UpdateParams.WAIT_SEARCHER, String.valueOf(waitSearcher));
64
 
    return this;
65
 
  }
66
 
 
67
 
  public AbstractUpdateRequest setAction(ACTION action, boolean waitFlush, boolean waitSearcher, int maxSegments , boolean expungeDeletes) {
68
 
    setAction(action, waitFlush, waitSearcher,maxSegments) ;
69
 
    params.set(UpdateParams.EXPUNGE_DELETES, String.valueOf(expungeDeletes));
70
 
    return this;
71
 
  }
72
 
 
73
 
  /**
74
 
   * @since Solr 1.4
75
 
   */
76
 
  public AbstractUpdateRequest rollback() {
77
 
    if (params == null)
78
 
      params = new ModifiableSolrParams();
79
 
 
80
 
    params.set( UpdateParams.ROLLBACK, "true" );
81
 
    return this;
82
 
  }
83
 
 
84
 
  public void setParam(String param, String value) {
85
 
    if (params == null)
86
 
      params = new ModifiableSolrParams();
87
 
    params.set(param, value);
88
 
  }
89
 
 
90
 
  /** Sets the parameters for this update request, overwriting any previous */
91
 
  public void setParams(ModifiableSolrParams params) {
92
 
    this.params = params;
93
 
  }
94
 
 
95
 
  @Override
96
 
  public ModifiableSolrParams getParams() {
97
 
    return params;
98
 
  }
99
 
 
100
 
  @Override
101
 
  public UpdateResponse process( SolrServer server ) throws SolrServerException, IOException
102
 
  {
103
 
    long startTime = System.currentTimeMillis();
104
 
    UpdateResponse res = new UpdateResponse();
105
 
    res.setResponse( server.request( this ) );
106
 
    res.setElapsedTime( System.currentTimeMillis()-startTime );
107
 
    return res;
108
 
  }
109
 
 
110
 
  public boolean isWaitFlush() {
111
 
    return params != null && params.getBool(UpdateParams.WAIT_FLUSH, false);
112
 
  }
113
 
 
114
 
  public boolean isWaitSearcher() {
115
 
    return params != null && params.getBool(UpdateParams.WAIT_SEARCHER, false);
116
 
  }
117
 
 
118
 
  public ACTION getAction() {
119
 
    if (params==null) return null;
120
 
    if (params.getBool(UpdateParams.COMMIT, false)) return ACTION.COMMIT;
121
 
    if (params.getBool(UpdateParams.OPTIMIZE, false)) return ACTION.OPTIMIZE;
122
 
    return null;
123
 
  }
124
 
 
125
 
  public void setWaitFlush(boolean waitFlush) {
126
 
    setParam( UpdateParams.WAIT_FLUSH, waitFlush+"" );
127
 
  }
128
 
 
129
 
  public void setWaitSearcher(boolean waitSearcher) {
130
 
    setParam( UpdateParams.WAIT_SEARCHER, waitSearcher+"" );
131
 
  }
132
 
 
133
 
  public int getCommitWithin() {
134
 
    return commitWithin;
135
 
  }
136
 
 
137
 
  public void setCommitWithin(int commitWithin) {
138
 
    this.commitWithin = commitWithin;
139
 
  }
140
 
 
141
 
 
142
 
}