2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.solr.update;
20
import org.apache.lucene.document.Document;
21
import org.apache.lucene.document.Fieldable;
22
import org.apache.lucene.index.Term;
23
import org.apache.solr.common.SolrInputDocument;
24
import org.apache.solr.common.SolrInputField;
25
import org.apache.solr.schema.IndexSchema;
26
import org.apache.solr.schema.SchemaField;
29
* @version $Id: AddUpdateCommand.java 1145201 2011-07-11 15:18:47Z yonik $
31
public class AddUpdateCommand extends UpdateCommand {
32
// optional id in "internal" indexed form... if it is needed and not supplied,
33
// it will be obtained from the doc.
34
public String indexedId;
36
// The Lucene document to be indexed
39
// Higher level SolrInputDocument, normally used to construct the Lucene Document
41
public SolrInputDocument solrDoc;
43
public boolean allowDups;
44
public boolean overwritePending;
45
public boolean overwriteCommitted;
47
public Term updateTerm;
48
public int commitWithin = -1;
51
/** Reset state to reuse this object with a different document in the same request */
58
public SolrInputDocument getSolrInputDocument() {
62
public Document getLuceneDocument(IndexSchema schema) {
63
if (doc == null && solrDoc != null) {
64
// TODO?? build the doc from the SolrDocument?
69
public String getIndexedId(IndexSchema schema) {
70
if (indexedId == null) {
71
SchemaField sf = schema.getUniqueKeyField();
74
schema.getUniqueKeyField();
75
Fieldable storedId = doc.getFieldable(sf.getName());
76
indexedId = sf.getType().storedToIndexed(storedId);
78
if (solrDoc != null) {
79
SolrInputField field = solrDoc.getField(sf.getName());
81
indexedId = sf.getType().toInternal( field.getFirstValue().toString() );
89
public String getPrintableId(IndexSchema schema) {
90
SchemaField sf = schema.getUniqueKeyField();
91
if (indexedId != null && sf != null) {
92
return sf.getType().indexedToReadable(indexedId);
96
return schema.printableUniqueKey(doc);
99
if (solrDoc != null && sf != null) {
100
SolrInputField field = solrDoc.getField(sf.getName());
102
return field.getFirstValue().toString();
108
public AddUpdateCommand() {
113
public String toString() {
114
StringBuilder sb = new StringBuilder(commandName);
116
if (indexedId !=null) sb.append("id=").append(indexedId);
117
sb.append(",allowDups=").append(allowDups);
118
sb.append(",overwritePending=").append(overwritePending);
119
sb.append(",overwriteCommitted=").append(overwriteCommitted);
120
return sb.toString();