More work on the type issue.
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/a6bfbcec Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/a6bfbcec Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/a6bfbcec Branch: refs/heads/0.2.0-newtypesystem Commit: a6bfbcece1d9a7980e186df25270a73a6340a310 Parents: 91c5f1d Author: Aaron McCurry <[email protected]> Authored: Tue Jul 2 11:43:40 2013 -0400 Committer: Aaron McCurry <[email protected]> Committed: Tue Jul 2 11:43:40 2013 -0400 ---------------------------------------------------------------------- .../analysis/AnalyzerNotFoundException.java | 16 ++ .../apache/blur/analysis/BaseFieldManager.java | 223 +++++++++++++++++++ .../org/apache/blur/analysis/FieldManager.java | 21 +- .../blur/analysis/FieldTypeDefinition.java | 11 + .../apache/blur/analysis/LightBlurAnalyzer.java | 17 +- .../blur/analysis/MemoryFieldManager.java | 114 ---------- .../type/DoubleFieldTypeDefinition.java | 91 ++++++++ .../analysis/type/FloatFieldTypeDefinition.java | 91 ++++++++ .../analysis/type/IntFieldTypeDefinition.java | 91 ++++++++ .../analysis/type/LongFieldTypeDefinition.java | 91 ++++++++ .../type/StoredFieldTypeDefinition.java | 77 +++++++ .../type/StringFieldTypeDefinition.java | 78 +++++++ .../analysis/type/TextFieldTypeDefinition.java | 24 +- 13 files changed, 823 insertions(+), 122 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/AnalyzerNotFoundException.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/AnalyzerNotFoundException.java b/blur-query/src/main/java/org/apache/blur/analysis/AnalyzerNotFoundException.java index 7d34981..e30173a 100644 --- a/blur-query/src/main/java/org/apache/blur/analysis/AnalyzerNotFoundException.java +++ b/blur-query/src/main/java/org/apache/blur/analysis/AnalyzerNotFoundException.java @@ -1,5 +1,21 @@ package org.apache.blur.analysis; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ public class AnalyzerNotFoundException extends RuntimeException { private static final long serialVersionUID = -1669681684004161773L; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java new file mode 100644 index 0000000..e14250a --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/BaseFieldManager.java @@ -0,0 +1,223 @@ +package org.apache.blur.analysis; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.blur.analysis.type.DoubleFieldTypeDefinition; +import org.apache.blur.analysis.type.FloatFieldTypeDefinition; +import org.apache.blur.analysis.type.IntFieldTypeDefinition; +import org.apache.blur.analysis.type.LongFieldTypeDefinition; +import org.apache.blur.analysis.type.StoredFieldTypeDefinition; +import org.apache.blur.analysis.type.StringFieldTypeDefinition; +import org.apache.blur.analysis.type.TextFieldTypeDefinition; +import org.apache.blur.log.Log; +import org.apache.blur.log.LogFactory; +import org.apache.blur.thrift.generated.Column; +import org.apache.blur.thrift.generated.Record; +import org.apache.blur.utils.BlurConstants; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.Field.Store; +import org.apache.lucene.document.StringField; + +public abstract class BaseFieldManager extends FieldManager { + + private static final Log LOG = LogFactory.getLog(BaseFieldManager.class); + private static final Map<String, String> EMPTY_MAP = new HashMap<String, String>();; + + private Map<String, FieldTypeDefinition> _fieldNameToDefMap = new ConcurrentHashMap<String, FieldTypeDefinition>(); + private Map<String, Class<? extends FieldTypeDefinition>> _typeMap = new ConcurrentHashMap<String, Class<? extends FieldTypeDefinition>>(); + private Map<String, Set<String>> _columnToSubColumn = new ConcurrentHashMap<String, Set<String>>(); + + public BaseFieldManager() { + _typeMap.put(TextFieldTypeDefinition.NAME, TextFieldTypeDefinition.class); + _typeMap.put(StringFieldTypeDefinition.NAME, StringFieldTypeDefinition.class); + _typeMap.put(StoredFieldTypeDefinition.NAME, StoredFieldTypeDefinition.class); + _typeMap.put(IntFieldTypeDefinition.NAME, IntFieldTypeDefinition.class); + _typeMap.put(LongFieldTypeDefinition.NAME, LongFieldTypeDefinition.class); + _typeMap.put(DoubleFieldTypeDefinition.NAME, DoubleFieldTypeDefinition.class); + _typeMap.put(FloatFieldTypeDefinition.NAME, FloatFieldTypeDefinition.class); + } + + @Override + public Iterable<? extends Field> getFields(String rowId, Record record) { + List<Field> fields = new ArrayList<Field>(); + String family = record.getFamily(); + List<Column> columns = record.getColumns(); + addDefaultFields(fields, rowId, record); + for (Column column : columns) { + getAndAddFields(fields, family, column, getFieldTypeDefinition(family, column)); + Collection<String> subColumns = getSubColumns(family, column); + if (subColumns != null) { + for (String subName : subColumns) { + getAndAddFields(fields, family, column, subName, getFieldTypeDefinition(family, column, subName)); + } + } + } + return fields; + } + + private void getAndAddFields(List<Field> fields, String family, Column column, String subName, + FieldTypeDefinition fieldTypeDefinition) { + for (Field field : fieldTypeDefinition.getFieldsForSubColumn(family, column, subName)) { + fields.add(field); + } + } + + private void addDefaultFields(List<Field> fields, String rowId, Record record) { + String family = record.getFamily(); + String recordId = record.getRecordId(); + + validateNotNull(rowId, "rowId"); + validateNotNull(family, "family"); + validateNotNull(recordId, "recordId"); + + fields.add(new StringField(BlurConstants.FAMILY, family, Store.YES)); + fields.add(new StringField(BlurConstants.ROW_ID, rowId, Store.YES)); + fields.add(new StringField(BlurConstants.RECORD_ID, recordId, Store.YES)); + } + + private void validateNotNull(String value, String fieldName) { + if (value != null) { + return; + } + throw new IllegalArgumentException("Field [" + fieldName + "] cannot be null."); + } + + private void getAndAddFields(List<Field> fields, String family, Column column, FieldTypeDefinition fieldTypeDefinition) { + for (Field field : fieldTypeDefinition.getFieldsForColumn(family, column)) { + fields.add(field); + } + if (fieldTypeDefinition.isFieldLessIndexing()) { + addFieldLessIndex(fields, column.getValue()); + } + } + + private void addFieldLessIndex(List<Field> fields, String value) { + fields.add(new Field(BlurConstants.SUPER, value, TextFieldTypeDefinition.TYPE_NOT_STORED)); + } + + private FieldTypeDefinition getFieldTypeDefinition(String family, Column column, String subName) { + return _fieldNameToDefMap.get(getSubColumnName(family, column, subName)); + } + + private String getSubColumnName(String family, Column column, String subName) { + return getColumnName(family, column) + "." + subName; + } + + private String getColumnName(String family, Column column) { + return getColumnName(family, column.getName()); + } + + private String getColumnName(String family, String columnName) { + return family + "." + columnName; + } + + private Collection<String> getSubColumns(String family, Column column) { + return _columnToSubColumn.get(getColumnName(family, column)); + } + + private FieldTypeDefinition getFieldTypeDefinition(String family, Column column) { + return _fieldNameToDefMap.get(getColumnName(family, column)); + } + + @Override + public void addColumnDefinition(String family, String columnName, String subColumnName, boolean fieldLessIndexing, + String fieldType, Map<String, String> props) { + String baseFieldName = family + "." + columnName; + String fieldName; + if (subColumnName != null) { + if (!_fieldNameToDefMap.containsKey(baseFieldName)) { + throw new IllegalArgumentException("Base column of [" + baseFieldName + + "] not found, please add base before adding sub column."); + } + if (fieldLessIndexing) { + throw new IllegalArgumentException("Subcolumn of [" + subColumnName + "] from base of [" + baseFieldName + + "] cannot be added with fieldLessIndexing set to true."); + } + fieldName = baseFieldName + "." + subColumnName; + } else { + fieldName = baseFieldName; + } + tryToStore(fieldName, fieldLessIndexing, fieldType, props); + Class<? extends FieldTypeDefinition> clazz = _typeMap.get(fieldType); + if (clazz == null) { + throw new IllegalArgumentException("FieldType of [" + fieldType + "] was not found."); + } + FieldTypeDefinition fieldTypeDefinition; + try { + fieldTypeDefinition = clazz.newInstance(); + } catch (InstantiationException e) { + LOG.error("Unknown error trying to create a type of [{0}] from class [{1}]", e, fieldType, clazz); + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + LOG.error("Unknown error trying to create a type of [{0}] from class [{1}]", e, fieldType, clazz); + throw new RuntimeException(e); + } + if (props == null) { + fieldTypeDefinition.configure(EMPTY_MAP); + } else { + fieldTypeDefinition.configure(props); + } + fieldTypeDefinition.setFieldLessIndexing(fieldLessIndexing); + _fieldNameToDefMap.put(fieldName, fieldTypeDefinition); + if (subColumnName != null) { + Set<String> subColumnNames = _columnToSubColumn.put(baseFieldName, getConcurrentSet()); + subColumnNames.add(subColumnName); + } + } + + protected abstract void tryToStore(String fieldName, boolean fieldLessIndexing, String fieldType, + Map<String, String> props); + + private Set<String> getConcurrentSet() { + return Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>()); + } + + @Override + public boolean isValidColumnDefinition(String family, String columnName) { + String fieldName = getColumnName(family, columnName); + return _fieldNameToDefMap.containsKey(fieldName); + } + + @Override + public Analyzer getAnalyzerForIndex(String fieldName) { + FieldTypeDefinition fieldTypeDefinition = _fieldNameToDefMap.get(fieldName); + if (fieldTypeDefinition == null) { + throw new AnalyzerNotFoundException(fieldName); + } + return fieldTypeDefinition.getAnalyzerForIndex(); + } + + @Override + public Analyzer getAnalyzerForQuery(String fieldName) { + FieldTypeDefinition fieldTypeDefinition = _fieldNameToDefMap.get(fieldName); + if (fieldTypeDefinition == null) { + throw new AnalyzerNotFoundException(fieldName); + } + return fieldTypeDefinition.getAnalyzerForQuery(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java index 9be9f57..1269047 100644 --- a/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java +++ b/blur-query/src/main/java/org/apache/blur/analysis/FieldManager.java @@ -31,7 +31,7 @@ public abstract class FieldManager { * @param record * @return */ - public abstract Iterable<? extends Field> getFields(Record record); + public abstract Iterable<? extends Field> getFields(String rowId, Record record); /** * Adds a column definition. @@ -43,13 +43,16 @@ public abstract class FieldManager { * @param subColumnName * the sub column name, optional can be null if it's not a sub * column. + * @param fieldLessIndexing + * indicates whether the field should be added to the default field + * for the record for fieldless searching. * @param fieldType * the field type name, required. * @param props * the configuration properties for this column and type. */ - public abstract void addColumnDefinition(String family, String columnName, String subColumnName, String fieldType, - Map<String, String> props); + public abstract void addColumnDefinition(String family, String columnName, String subColumnName, + boolean fieldLessIndexing, String fieldType, Map<String, String> props); /** * Gets the analyzer for the indexing process. @@ -69,4 +72,16 @@ public abstract class FieldManager { */ public abstract Analyzer getAnalyzerForQuery(String fieldName); + /** + * Checks if there is a valid column definition for the given family and + * column name. + * + * @param family + * the family name, + * @param columnName + * the column name. + * @return boolean + */ + public abstract boolean isValidColumnDefinition(String family, String columnName); + } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java index 7aecc95..e5877f8 100644 --- a/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java +++ b/blur-query/src/main/java/org/apache/blur/analysis/FieldTypeDefinition.java @@ -25,6 +25,10 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.FieldType; public abstract class FieldTypeDefinition { + + protected static final String NUMERIC_PRECISION_STEP = "numericPrecisionStep"; + + protected boolean _fieldLessIndexing; /** * Gets the name of the field type. @@ -129,4 +133,11 @@ public abstract class FieldTypeDefinition { return family + "." + name + "." + subName; } + public boolean isFieldLessIndexing() { + return _fieldLessIndexing; + } + + public void setFieldLessIndexing(boolean fieldLessIndexing) { + _fieldLessIndexing = fieldLessIndexing; + } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/LightBlurAnalyzer.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/LightBlurAnalyzer.java b/blur-query/src/main/java/org/apache/blur/analysis/LightBlurAnalyzer.java index a9c2c21..1939119 100644 --- a/blur-query/src/main/java/org/apache/blur/analysis/LightBlurAnalyzer.java +++ b/blur-query/src/main/java/org/apache/blur/analysis/LightBlurAnalyzer.java @@ -1,5 +1,20 @@ package org.apache.blur.analysis; - +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.AnalyzerWrapper; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/MemoryFieldManager.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/MemoryFieldManager.java b/blur-query/src/main/java/org/apache/blur/analysis/MemoryFieldManager.java deleted file mode 100644 index 895b748..0000000 --- a/blur-query/src/main/java/org/apache/blur/analysis/MemoryFieldManager.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.apache.blur.analysis; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.blur.log.Log; -import org.apache.blur.log.LogFactory; -import org.apache.blur.thrift.generated.Column; -import org.apache.blur.thrift.generated.Record; -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.document.Field; - -public class MemoryFieldManager extends FieldManager { - - private static final Log LOG = LogFactory.getLog(MemoryFieldManager.class); - - private Map<String, FieldTypeDefinition> _fieldNameToDefMap = new ConcurrentHashMap<String, FieldTypeDefinition>(); - private Map<String, Class<? extends FieldTypeDefinition>> _typeMap = new ConcurrentHashMap<String, Class<? extends FieldTypeDefinition>>(); - - @Override - public Iterable<? extends Field> getFields(Record record) { - List<Field> fields = new ArrayList<Field>(); - String family = record.getFamily(); - List<Column> columns = record.getColumns(); - addDefaultFields(fields,record); - for (Column column : columns) { - getAndAddFields(fields, family, column, getFieldTypeDefinition(column)); - for (String subName : getSubColumns(column)) { - getAndAddFields(fields, family, column, getFieldTypeDefinition(column, subName)); - } - } - return fields; - } - - private void addDefaultFields(List<Field> fields, Record record) { - //add family - //record id fields - - } - - private void getAndAddFields(List<Field> fields, String family, Column column, FieldTypeDefinition fieldTypeDefinition) { - for (Field field : fieldTypeDefinition.getFieldsForColumn(family, column)) { - fields.add(field); - } - } - - private FieldTypeDefinition getFieldTypeDefinition(Column column, String subName) { - // TODO Auto-generated method stub - return null; - } - - private List<String> getSubColumns(Column column) { - // TODO Auto-generated method stub - return null; - } - - private FieldTypeDefinition getFieldTypeDefinition(Column column) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void addColumnDefinition(String family, String columnName, String subColumnName, String fieldType, - Map<String, String> props) { - String baseFieldName = family + "." + columnName; - String fieldName; - if (subColumnName != null) { - if (!_fieldNameToDefMap.containsKey(baseFieldName)) { - throw new IllegalArgumentException("Base column of [" + baseFieldName - + "] not found, please add base before adding sub column."); - } - fieldName = baseFieldName + "." + subColumnName; - } else { - fieldName = baseFieldName; - } - Class<? extends FieldTypeDefinition> clazz = _typeMap.get(fieldType); - if (clazz == null) { - throw new IllegalArgumentException("FieldType of [" + fieldType + "] was not found."); - } - FieldTypeDefinition fieldTypeDefinition; - try { - fieldTypeDefinition = clazz.newInstance(); - } catch (InstantiationException e) { - LOG.error("Unknown error trying to create a type of [{0}] from class [{1}]", e, fieldType, clazz); - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - LOG.error("Unknown error trying to create a type of [{0}] from class [{1}]", e, fieldType, clazz); - throw new RuntimeException(e); - } - fieldTypeDefinition.configure(props); - _fieldNameToDefMap.put(fieldName, fieldTypeDefinition); - } - - @Override - public Analyzer getAnalyzerForIndex(String fieldName) { - FieldTypeDefinition fieldTypeDefinition = _fieldNameToDefMap.get(fieldName); - if (fieldTypeDefinition == null) { - throw new AnalyzerNotFoundException(fieldName); - } - return fieldTypeDefinition.getAnalyzerForIndex(); - } - - @Override - public Analyzer getAnalyzerForQuery(String fieldName) { - FieldTypeDefinition fieldTypeDefinition = _fieldNameToDefMap.get(fieldName); - if (fieldTypeDefinition == null) { - throw new AnalyzerNotFoundException(fieldName); - } - return fieldTypeDefinition.getAnalyzerForQuery(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/DoubleFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/DoubleFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/DoubleFieldTypeDefinition.java new file mode 100644 index 0000000..41e086e --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/DoubleFieldTypeDefinition.java @@ -0,0 +1,91 @@ +package org.apache.blur.analysis.type; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.Map; + +import org.apache.blur.analysis.FieldTypeDefinition; +import org.apache.blur.thrift.generated.Column; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.DoubleField; + +public class DoubleFieldTypeDefinition extends FieldTypeDefinition { + + public static final String NAME = "double"; + private FieldType _typeStored; + private FieldType _typeNotStored; + + @Override + public String getName() { + return NAME; + } + + @Override + public void configure(Map<String, String> properties) { + String precisionStepStr = properties.get(NUMERIC_PRECISION_STEP); + if (precisionStepStr != null) { + int precisionStep = Integer.parseInt(precisionStepStr); + _typeStored = new FieldType(DoubleField.TYPE_STORED); + _typeStored.setNumericPrecisionStep(precisionStep); + _typeStored.freeze(); + _typeNotStored = new FieldType(DoubleField.TYPE_NOT_STORED); + _typeNotStored.setNumericPrecisionStep(precisionStep); + _typeNotStored.freeze(); + } else { + _typeStored = DoubleField.TYPE_STORED; + _typeNotStored = DoubleField.TYPE_NOT_STORED; + } + } + + @Override + public Iterable<? extends Field> getFieldsForColumn(String family, Column column) { + String name = getName(family, column.getName()); + DoubleField field = new DoubleField(name, Double.parseDouble(column.getValue()), getStoredFieldType()); + return makeIterable(field); + } + + @Override + public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) { + String name = getName(family, column.getName(), subName); + return makeIterable(new DoubleField(name, Double.parseDouble(column.getValue()), getNotStoredFieldType())); + } + + @Override + public FieldType getStoredFieldType() { + return _typeStored; + } + + @Override + public FieldType getNotStoredFieldType() { + return _typeNotStored; + } + + @Override + public Analyzer getAnalyzerForIndex() { + // shouldn't be used ever + return new KeywordAnalyzer(); + } + + @Override + public Analyzer getAnalyzerForQuery() { + return new KeywordAnalyzer(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/FloatFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/FloatFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/FloatFieldTypeDefinition.java new file mode 100644 index 0000000..6ba79fc --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/FloatFieldTypeDefinition.java @@ -0,0 +1,91 @@ +package org.apache.blur.analysis.type; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.Map; + +import org.apache.blur.analysis.FieldTypeDefinition; +import org.apache.blur.thrift.generated.Column; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.FloatField; + +public class FloatFieldTypeDefinition extends FieldTypeDefinition { + + public static final String NAME = "float"; + private FieldType _typeStored; + private FieldType _typeNotStored; + + @Override + public String getName() { + return NAME; + } + + @Override + public void configure(Map<String, String> properties) { + String precisionStepStr = properties.get(NUMERIC_PRECISION_STEP); + if (precisionStepStr != null) { + int precisionStep = Integer.parseInt(precisionStepStr); + _typeStored = new FieldType(FloatField.TYPE_STORED); + _typeStored.setNumericPrecisionStep(precisionStep); + _typeStored.freeze(); + _typeNotStored = new FieldType(FloatField.TYPE_NOT_STORED); + _typeNotStored.setNumericPrecisionStep(precisionStep); + _typeNotStored.freeze(); + } else { + _typeStored = FloatField.TYPE_STORED; + _typeNotStored = FloatField.TYPE_NOT_STORED; + } + } + + @Override + public Iterable<? extends Field> getFieldsForColumn(String family, Column column) { + String name = getName(family, column.getName()); + FloatField field = new FloatField(name, Float.parseFloat(column.getValue()), getStoredFieldType()); + return makeIterable(field); + } + + @Override + public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) { + String name = getName(family, column.getName(), subName); + return makeIterable(new FloatField(name, Float.parseFloat(column.getValue()), getNotStoredFieldType())); + } + + @Override + public FieldType getStoredFieldType() { + return _typeStored; + } + + @Override + public FieldType getNotStoredFieldType() { + return _typeNotStored; + } + + @Override + public Analyzer getAnalyzerForIndex() { + // shouldn't be used ever + return new KeywordAnalyzer(); + } + + @Override + public Analyzer getAnalyzerForQuery() { + return new KeywordAnalyzer(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/IntFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/IntFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/IntFieldTypeDefinition.java new file mode 100644 index 0000000..61333e3 --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/IntFieldTypeDefinition.java @@ -0,0 +1,91 @@ +package org.apache.blur.analysis.type; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.Map; + +import org.apache.blur.analysis.FieldTypeDefinition; +import org.apache.blur.thrift.generated.Column; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.IntField; + +public class IntFieldTypeDefinition extends FieldTypeDefinition { + + public static final String NAME = "int"; + private FieldType _typeStored; + private FieldType _typeNotStored; + + @Override + public String getName() { + return NAME; + } + + @Override + public void configure(Map<String, String> properties) { + String precisionStepStr = properties.get(NUMERIC_PRECISION_STEP); + if (precisionStepStr != null) { + int precisionStep = Integer.parseInt(precisionStepStr); + _typeStored = new FieldType(IntField.TYPE_STORED); + _typeStored.setNumericPrecisionStep(precisionStep); + _typeStored.freeze(); + _typeNotStored = new FieldType(IntField.TYPE_NOT_STORED); + _typeNotStored.setNumericPrecisionStep(precisionStep); + _typeNotStored.freeze(); + } else { + _typeStored = IntField.TYPE_STORED; + _typeNotStored = IntField.TYPE_NOT_STORED; + } + } + + @Override + public Iterable<? extends Field> getFieldsForColumn(String family, Column column) { + String name = getName(family, column.getName()); + IntField field = new IntField(name, Integer.parseInt(column.getValue()), getStoredFieldType()); + return makeIterable(field); + } + + @Override + public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) { + String name = getName(family, column.getName(), subName); + return makeIterable(new IntField(name, Integer.parseInt(column.getValue()), getNotStoredFieldType())); + } + + @Override + public FieldType getStoredFieldType() { + return _typeStored; + } + + @Override + public FieldType getNotStoredFieldType() { + return _typeNotStored; + } + + @Override + public Analyzer getAnalyzerForIndex() { + // shouldn't be used ever + return new KeywordAnalyzer(); + } + + @Override + public Analyzer getAnalyzerForQuery() { + return new KeywordAnalyzer(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/LongFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/LongFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/LongFieldTypeDefinition.java new file mode 100644 index 0000000..69e74c6 --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/LongFieldTypeDefinition.java @@ -0,0 +1,91 @@ +package org.apache.blur.analysis.type; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.Map; + +import org.apache.blur.analysis.FieldTypeDefinition; +import org.apache.blur.thrift.generated.Column; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.LongField; + +public class LongFieldTypeDefinition extends FieldTypeDefinition { + + public static final String NAME = "long"; + private FieldType _typeStored; + private FieldType _typeNotStored; + + @Override + public String getName() { + return NAME; + } + + @Override + public void configure(Map<String, String> properties) { + String precisionStepStr = properties.get(NUMERIC_PRECISION_STEP); + if (precisionStepStr != null) { + int precisionStep = Integer.parseInt(precisionStepStr); + _typeStored = new FieldType(LongField.TYPE_STORED); + _typeStored.setNumericPrecisionStep(precisionStep); + _typeStored.freeze(); + _typeNotStored = new FieldType(LongField.TYPE_NOT_STORED); + _typeNotStored.setNumericPrecisionStep(precisionStep); + _typeNotStored.freeze(); + } else { + _typeStored = LongField.TYPE_STORED; + _typeNotStored = LongField.TYPE_NOT_STORED; + } + } + + @Override + public Iterable<? extends Field> getFieldsForColumn(String family, Column column) { + String name = getName(family, column.getName()); + LongField field = new LongField(name, Long.parseLong(column.getValue()), getStoredFieldType()); + return makeIterable(field); + } + + @Override + public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) { + String name = getName(family, column.getName(), subName); + return makeIterable(new LongField(name, Long.parseLong(column.getValue()), getNotStoredFieldType())); + } + + @Override + public FieldType getStoredFieldType() { + return _typeStored; + } + + @Override + public FieldType getNotStoredFieldType() { + return _typeNotStored; + } + + @Override + public Analyzer getAnalyzerForIndex() { + // shouldn't be used ever + return new KeywordAnalyzer(); + } + + @Override + public Analyzer getAnalyzerForQuery() { + return new KeywordAnalyzer(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java new file mode 100644 index 0000000..de0b8d8 --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/StoredFieldTypeDefinition.java @@ -0,0 +1,77 @@ +package org.apache.blur.analysis.type; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.Arrays; +import java.util.Map; + +import org.apache.blur.analysis.FieldTypeDefinition; +import org.apache.blur.thrift.generated.Column; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StoredField; + +public class StoredFieldTypeDefinition extends FieldTypeDefinition { + + public static final String NAME = "stored"; + private static final Iterable<? extends Field> EMPTY = Arrays.asList(); + + @Override + public String getName() { + return NAME; + } + + @Override + public void configure(Map<String, String> properties) { + + } + + @Override + public Iterable<? extends Field> getFieldsForColumn(String family, Column column) { + String name = getName(family, column.getName()); + return makeIterable(new StoredField(name, column.getValue())); + } + + @Override + public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) { + return EMPTY; + } + + @Override + public FieldType getStoredFieldType() { + return StoredField.TYPE; + } + + @Override + public FieldType getNotStoredFieldType() { + return StoredField.TYPE; + } + + @Override + public Analyzer getAnalyzerForIndex() { + // shouldn't be used ever + return new KeywordAnalyzer(); + } + + @Override + public Analyzer getAnalyzerForQuery() { + return new KeywordAnalyzer(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java new file mode 100644 index 0000000..6422304 --- /dev/null +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/StringFieldTypeDefinition.java @@ -0,0 +1,78 @@ +package org.apache.blur.analysis.type; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import java.util.Map; + +import org.apache.blur.analysis.FieldTypeDefinition; +import org.apache.blur.thrift.generated.Column; +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.FieldType; +import org.apache.lucene.document.StringField; + +public class StringFieldTypeDefinition extends FieldTypeDefinition { + + public static final String NAME = "string"; + + @Override + public String getName() { + return NAME; + } + + @Override + public void configure(Map<String, String> properties) { + + } + + @Override + public Iterable<? extends Field> getFieldsForColumn(String family, Column column) { + String name = getName(family, column.getName()); + Field field = new Field(name, column.getValue(), getStoredFieldType()); + return makeIterable(field); + } + + @Override + public Iterable<? extends Field> getFieldsForSubColumn(String family, Column column, String subName) { + String name = getName(family, column.getName(), subName); + Field field = new Field(name, column.getValue(), getNotStoredFieldType()); + return makeIterable(field); + } + + @Override + public FieldType getStoredFieldType() { + return StringField.TYPE_STORED; + } + + @Override + public FieldType getNotStoredFieldType() { + return StringField.TYPE_NOT_STORED; + } + + @Override + public Analyzer getAnalyzerForIndex() { + // shouldn't be used ever + return new KeywordAnalyzer(); + } + + @Override + public Analyzer getAnalyzerForQuery() { + return new KeywordAnalyzer(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a6bfbcec/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java ---------------------------------------------------------------------- diff --git a/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java b/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java index 7e141fe..eb05007 100644 --- a/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java +++ b/blur-query/src/main/java/org/apache/blur/analysis/type/TextFieldTypeDefinition.java @@ -1,5 +1,21 @@ package org.apache.blur.analysis.type; +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import java.util.Map; import org.apache.blur.analysis.FieldTypeDefinition; @@ -12,9 +28,9 @@ import org.apache.lucene.document.TextField; public class TextFieldTypeDefinition extends FieldTypeDefinition { - private static final String TEXT = "text"; - private static final FieldType TYPE_NOT_STORED; - private static final FieldType TYPE_STORED; + public static final String NAME = "text"; + public static final FieldType TYPE_NOT_STORED; + public static final FieldType TYPE_STORED; static { TYPE_STORED = new FieldType(TextField.TYPE_STORED); @@ -28,7 +44,7 @@ public class TextFieldTypeDefinition extends FieldTypeDefinition { @Override public String getName() { - return TEXT; + return NAME; } @Override
