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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/update/AddUpdateCommand.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
 
/**
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
8
 
 *
9
 
 *     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
 
 */
17
 
 
18
 
package org.apache.solr.update;
19
 
 
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;
27
 
 
28
 
/**
29
 
 * @version $Id: AddUpdateCommand.java 1145201 2011-07-11 15:18:47Z yonik $
30
 
 */
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;
35
 
 
36
 
   // The Lucene document to be indexed
37
 
   public Document doc;
38
 
 
39
 
   // Higher level SolrInputDocument, normally used to construct the Lucene Document
40
 
   // to index.
41
 
   public SolrInputDocument solrDoc;
42
 
 
43
 
   public boolean allowDups;
44
 
   public boolean overwritePending;
45
 
   public boolean overwriteCommitted;
46
 
   
47
 
   public Term updateTerm;
48
 
   public int commitWithin = -1;
49
 
   
50
 
 
51
 
   /** Reset state to reuse this object with a different document in the same request */
52
 
   public void clear() {
53
 
     doc = null;
54
 
     solrDoc = null;
55
 
     indexedId = null;
56
 
   }
57
 
 
58
 
   public SolrInputDocument getSolrInputDocument() {
59
 
     return solrDoc;
60
 
   }
61
 
 
62
 
   public Document getLuceneDocument(IndexSchema schema) {
63
 
     if (doc == null && solrDoc != null) {
64
 
       // TODO??  build the doc from the SolrDocument?
65
 
     }
66
 
     return doc;    
67
 
   }
68
 
 
69
 
   public String getIndexedId(IndexSchema schema) {
70
 
     if (indexedId == null) {
71
 
       SchemaField sf = schema.getUniqueKeyField();
72
 
       if (sf != null) {
73
 
         if (doc != null) {
74
 
           schema.getUniqueKeyField();
75
 
           Fieldable storedId = doc.getFieldable(sf.getName());
76
 
           indexedId = sf.getType().storedToIndexed(storedId);
77
 
         }
78
 
         if (solrDoc != null) {
79
 
           SolrInputField field = solrDoc.getField(sf.getName());
80
 
           if (field != null) {
81
 
             indexedId = sf.getType().toInternal( field.getFirstValue().toString() );
82
 
           }
83
 
         }
84
 
       }
85
 
     }
86
 
     return indexedId;
87
 
   }
88
 
 
89
 
   public String getPrintableId(IndexSchema schema) {
90
 
     SchemaField sf = schema.getUniqueKeyField();
91
 
     if (indexedId != null && sf != null) {
92
 
       return sf.getType().indexedToReadable(indexedId);
93
 
     }
94
 
 
95
 
     if (doc != null) {
96
 
       return schema.printableUniqueKey(doc);
97
 
     }
98
 
 
99
 
     if (solrDoc != null && sf != null) {
100
 
       SolrInputField field = solrDoc.getField(sf.getName());
101
 
       if (field != null) {
102
 
         return field.getFirstValue().toString();
103
 
       }
104
 
     }
105
 
     return "(null)";
106
 
   }
107
 
 
108
 
   public AddUpdateCommand() {
109
 
     super("add");
110
 
   }
111
 
 
112
 
   @Override
113
 
  public String toString() {
114
 
     StringBuilder sb = new StringBuilder(commandName);
115
 
     sb.append(':');
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();
121
 
   }
122
 
 }