Line data Source code
1 : // Copyright (C) 2013 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.index; 16 : 17 : import com.google.common.collect.ImmutableList; 18 : import java.sql.Timestamp; 19 : 20 : /** Document field types supported by the secondary index system. */ 21 : public class FieldType<T> { 22 : /** A single integer-valued field. */ 23 155 : public static final FieldType<Integer> INTEGER = new FieldType<>("INTEGER"); 24 : 25 : /** A single-integer-valued field matched using range queries. */ 26 155 : public static final FieldType<Integer> INTEGER_RANGE = new FieldType<>("INTEGER_RANGE"); 27 : 28 : /** A single integer-valued field. */ 29 155 : public static final FieldType<Long> LONG = new FieldType<>("LONG"); 30 : 31 : /** A single date/time-valued field. */ 32 155 : public static final FieldType<Timestamp> TIMESTAMP = new FieldType<>("TIMESTAMP"); 33 : 34 : /** A string field searched using exact-match semantics. */ 35 155 : public static final FieldType<String> EXACT = new FieldType<>("EXACT"); 36 : 37 : /** A string field searched using prefix. */ 38 155 : public static final FieldType<String> PREFIX = new FieldType<>("PREFIX"); 39 : 40 : /** A string field searched using fuzzy-match semantics. */ 41 155 : public static final FieldType<String> FULL_TEXT = new FieldType<>("FULL_TEXT"); 42 : 43 : /** A field that is only stored as raw bytes and cannot be queried. */ 44 155 : public static final FieldType<byte[]> STORED_ONLY = new FieldType<>("STORED_ONLY"); 45 : 46 : /** List of all types that are stored as {@link String} in the index. */ 47 155 : public static final ImmutableList<FieldType<String>> STRING_TYPES = 48 155 : ImmutableList.of(EXACT, PREFIX, FULL_TEXT); 49 : 50 : /** List of all types that are stored as {@link Integer} in the index. */ 51 155 : public static final ImmutableList<FieldType<Integer>> INTEGER_TYPES = 52 155 : ImmutableList.of(INTEGER_RANGE, INTEGER); 53 : 54 : private final String name; 55 : 56 155 : private FieldType(String name) { 57 155 : this.name = name; 58 155 : } 59 : 60 : public String getName() { 61 150 : return name; 62 : } 63 : 64 : @Override 65 : public String toString() { 66 0 : return name; 67 : } 68 : 69 : public static IllegalArgumentException badFieldType(FieldType<?> t) { 70 0 : return new IllegalArgumentException("unknown index field type " + t); 71 : } 72 : }