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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/schema/ByteField.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.schema;
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.lucene.document.Fieldable;
20
 
import org.apache.lucene.search.SortField;
21
 
 
22
 
import org.apache.solr.response.TextResponseWriter;
23
 
import org.apache.solr.response.XMLWriter;
24
 
import org.apache.solr.search.function.ValueSource;
25
 
import org.apache.solr.search.function.ByteFieldSource;
26
 
import org.apache.solr.search.QParser;
27
 
 
28
 
import java.io.IOException;
29
 
import java.util.Map;
30
 
 
31
 
/**
32
 
 * @version $Id:$
33
 
 */
34
 
public class ByteField extends FieldType {
35
 
  @Override
36
 
  protected void init(IndexSchema schema, Map<String, String> args) {
37
 
    restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST);
38
 
  }
39
 
 
40
 
  /////////////////////////////////////////////////////////////
41
 
  @Override
42
 
  public SortField getSortField(SchemaField field, boolean reverse) {
43
 
    field.checkSortability();
44
 
    return new SortField(field.name, SortField.BYTE, reverse);
45
 
  }
46
 
 
47
 
  @Override
48
 
  public ValueSource getValueSource(SchemaField field, QParser qparser) {
49
 
    field.checkFieldCacheSource(qparser);
50
 
    return new ByteFieldSource(field.name);
51
 
  }
52
 
 
53
 
 
54
 
  @Override
55
 
  public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
56
 
    xmlWriter.writeByte(name, f.stringValue());
57
 
  }
58
 
 
59
 
  @Override
60
 
  public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
61
 
    String s = f.stringValue();
62
 
 
63
 
    // these values may be from a legacy lucene index, which may
64
 
    // not be properly formatted in some output formats, or may
65
 
    // incorrectly have a zero length.
66
 
 
67
 
    if (s.length()==0) {
68
 
      // zero length value means someone mistakenly indexed the value
69
 
      // instead of simply leaving it out.  Write a null value instead of a numeric.
70
 
      writer.writeNull(name);
71
 
      return;
72
 
    }
73
 
 
74
 
    try {
75
 
      byte val = Byte.parseByte(s);
76
 
      writer.writeByte(name, val);
77
 
    } catch (NumberFormatException e){
78
 
      // can't parse - write out the contents as a string so nothing is lost and
79
 
      // clients don't get a parse error.
80
 
      writer.writeStr(name, s, true);
81
 
    }
82
 
  }
83
 
 
84
 
  @Override
85
 
  public Byte toObject(Fieldable f) {
86
 
    return Byte.valueOf(toExternal(f));
87
 
  }
88
 
}