01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.solr.schema;
17:
18: import org.apache.lucene.search.SortField;
19: import org.apache.solr.search.function.ValueSource;
20: import org.apache.lucene.document.Fieldable;
21: import org.apache.solr.util.BCDUtils;
22: import org.apache.solr.request.XMLWriter;
23: import org.apache.solr.request.TextResponseWriter;
24:
25: import java.util.Map;
26: import java.io.IOException;
27:
28: /**
29: * @author yonik
30: * @version $Id: BCDIntField.java 479793 2006-11-27 22:40:21Z klaas $
31: */
32: public class BCDIntField extends FieldType {
33: protected void init(IndexSchema schema, Map<String, String> args) {
34: }
35:
36: public SortField getSortField(SchemaField field, boolean reverse) {
37: return getStringSort(field, reverse);
38: }
39:
40: public ValueSource getValueSource(SchemaField field) {
41: throw new UnsupportedOperationException(
42: "ValueSource not implemented");
43: }
44:
45: public String toInternal(String val) {
46: return BCDUtils.base10toBase10kSortableInt(val);
47: }
48:
49: public String toExternal(Fieldable f) {
50: return indexedToReadable(f.stringValue());
51: }
52:
53: public String indexedToReadable(String indexedForm) {
54: return BCDUtils.base10kSortableIntToBase10(indexedForm);
55: }
56:
57: public void write(XMLWriter xmlWriter, String name, Fieldable f)
58: throws IOException {
59: xmlWriter.writeInt(name, toExternal(f));
60: }
61:
62: public void write(TextResponseWriter writer, String name,
63: Fieldable f) throws IOException {
64: writer.writeInt(name, toExternal(f));
65: }
66: }
|