当前位置: 首页>>代码示例>>Java>>正文


Java SchemaField类代码示例

本文整理汇总了Java中org.apache.solr.schema.SchemaField的典型用法代码示例。如果您正苦于以下问题:Java SchemaField类的具体用法?Java SchemaField怎么用?Java SchemaField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SchemaField类属于org.apache.solr.schema包,在下文中一共展示了SchemaField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectFacetMethod

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
/**
  * @param existsRequested facet.exists=true is passed for the given field
  * */
static FacetMethod selectFacetMethod(String fieldName, 
                                     SchemaField field, FacetMethod method, Integer mincount,
                                     boolean existsRequested) {
  if (existsRequested) {
    checkMincountOnExists(fieldName, mincount);
    if (method == null) {
      method = FacetMethod.ENUM;
    }
  }
  final FacetMethod facetMethod = selectFacetMethod(field, method, mincount);
  
  if (existsRequested && facetMethod!=FacetMethod.ENUM) {
    throw new SolrException (ErrorCode.BAD_REQUEST, 
        FacetParams.FACET_EXISTS + "=true is requested, but "+
        FacetParams.FACET_METHOD+"="+FacetParams.FACET_METHOD_enum+ " can't be used with "+fieldName
    );
  }
  return facetMethod;
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:23,代码来源:SimpleFacets.java

示例2: getInsanityWrapper

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
private Collector getInsanityWrapper(final String field, Collector collector) {
  SchemaField sf = searcher.getSchema().getFieldOrNull(field);
  if (sf != null && !sf.hasDocValues() && !sf.multiValued() && sf.getType().getNumberType() != null) {
    // it's a single-valued numeric field: we must currently create insanity :(
    // there isn't a GroupedFacetCollector that works on numerics right now...
    return new FilterCollector(collector) {
      @Override
      public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
        LeafReader insane = Insanity.wrapInsanity(context.reader(), field);
        return in.getLeafCollector(insane.getContext());
      }
    };
  } else {
    return collector;
  }
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:17,代码来源:SimpleFacets.java

示例3: analyzedField

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
private List<String> analyzedField(SchemaField field, Object value) {
  try {
    List<String> result = new ArrayList<>();
    TokenStream ts = field.getType().getIndexAnalyzer().tokenStream(field.getName(), value.toString());
    CharTermAttribute term = ts.addAttribute(CharTermAttribute.class);
    try {
      ts.reset();
      while (ts.incrementToken()) {
        result.add(term.toString());
      }
      ts.end();
    } finally {
      ts.close();
    }
    return result;
  } catch (IOException e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can't analyze " + value.toString() + " in " + field);
  }
}
 
开发者ID:grossws,项目名称:solr-dvtf,代码行数:20,代码来源:DocValuesTextField.java

示例4: getInstance

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
@Override
public UpdateRequestProcessor getInstance(SolrQueryRequest req,
                                          SolrQueryResponse rsp,
                                          UpdateRequestProcessor next) {
  final IndexSchema schema = req.getSchema();
  return new FieldMutatingUpdateProcessor(getSelector(), next) {
    @Override
    protected SolrInputField mutate(SolrInputField src) {
      if (src.getValueCount() <= 1)
        return src;//short circuit single value
      SchemaField field = schema.getField(src.getName());
      FieldType ft = field.getType();
      IndexableField result = ft.createField(field, src, src.getBoost());
      if (result == null)
        return null;//remove
      src.setValue(result, src.getBoost());
      return src;
    }
  };
}
 
开发者ID:randomstatistic,项目名称:SOLR-5170,代码行数:21,代码来源:MultiValUpdateRequestProcessorFactory.java

示例5: getStringFields

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
private ArrayList<String> getStringFields( SolrIndexSearcher searcher ) {
  IndexSchema schema = searcher.getSchema();
  ArrayList<String> strFields = new ArrayList<String>( );
    
  Collection<String> fieldNames = searcher.getFieldNames();
  Iterator<String> fnIt = fieldNames.iterator();
  while ( fnIt.hasNext() ) {
    String fieldName = fnIt.next( );
    if (excludeFields == null || !excludeFields.contains( fieldName )) {
      try {
        SchemaField field = schema.getField(fieldName);
        if (field.stored() && field.getType() instanceof StrField ) {
          strFields.add( fieldName );
        }
      }
      catch (Throwable e )
      {
          
      }
    }
  }
    
  return strFields;
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:25,代码来源:QueryAutoFilteringComponent.java

示例6: transformValue

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
/**
 * Can be used to transform input values based on their {@link org.apache.solr.schema.SchemaField}
 * <p/>
 * This implementation only formats dates using the {@link org.apache.solr.common.util.DateUtil}.
 *
 * @param val    The value to transform
 * @param schFld The {@link org.apache.solr.schema.SchemaField}
 * @return The potentially new value.
 */
protected String transformValue(String val, SchemaField schFld) {
  String result = val;
  if (schFld != null && schFld.getType() instanceof DateField) {
    //try to transform the date
    try {
      Date date = DateUtil.parseDate(val, dateFormats);
      DateFormat df = DateUtil.getThreadLocalDateFormat();
      result = df.format(date);

    } catch (Exception e) {
      // Let the specific fieldType handle errors
      // throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid value: " + val + " for field: " + schFld, e);
    }
  }
  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:SolrContentHandler.java

示例7: GenerateSolrSequenceKey

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
public GenerateSolrSequenceKey(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);
  this.baseIdFieldName = getConfigs().getString(config, "baseIdField", Fields.BASE_ID);
  this.preserveExisting = getConfigs().getBoolean(config, "preserveExisting", true);      
  
  Config solrLocatorConfig = getConfigs().getConfig(config, "solrLocator");
  SolrLocator locator = new SolrLocator(solrLocatorConfig, context);
  LOG.debug("solrLocator: {}", locator);
  IndexSchema schema = locator.getIndexSchema();
  SchemaField uniqueKey = schema.getUniqueKeyField();
  uniqueKeyName = uniqueKey == null ? null : uniqueKey.getName();
  
  String tmpIdPrefix = getConfigs().getString(config, "idPrefix", null);  // for load testing only
  Random tmpRandomIdPrefx = null;
  if ("random".equals(tmpIdPrefix)) { // for load testing only
    tmpRandomIdPrefx = new Random(new SecureRandom().nextLong());    
    tmpIdPrefix = null;
  }
  idPrefix = tmpIdPrefix;
  randomIdPrefix = tmpRandomIdPrefx;
  validateArguments();
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:GenerateSolrSequenceKeyBuilder.java

示例8: handleIndexableField

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
private IndexableField handleIndexableField(SchemaField field, String source, String target, float boost) {
    if (StringUtils.isEmpty(source) || StringUtils.isEmpty(target)) {
        return null;
    }
    FieldType fieldType = PreAnalyzedField.createFieldType(field);
    if (null == fieldType) {
        return null;
    }
    Field indexableField = null;
    if (field.stored()) {
        indexableField = new Field(field.getName(), target, fieldType);
    }
    if (field.indexed()) {
        TokenStream tokenStream = ((MultiLangAnalyzer) this.getAnalyzer()).createComponents(field.getName(),
                new StringReader(source)).getTokenStream();
        if (null != indexableField) {
            indexableField.setTokenStream(tokenStream);
        } else {
            indexableField = new Field(field.getName(), tokenStream, fieldType);
        }
    }
    if (null != indexableField) {
        indexableField.setBoost(boost);
    }
    return indexableField;
}
 
开发者ID:smalldirector,项目名称:solr-multilingual-analyzer,代码行数:27,代码来源:MultiLangField.java

示例9: getUniqueKeys

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
/** Retrieves the unique keys for the topdocs to key the results */
protected String[] getUniqueKeys(SolrIndexSearcher searcher, int[] docIDs) throws IOException {
  IndexSchema schema = searcher.getSchema();
  SchemaField keyField = schema.getUniqueKeyField();
  if (keyField != null) {
    Set<String> selector = Collections.singleton(keyField.getName());
    String uniqueKeys[] = new String[docIDs.length];
    for (int i = 0; i < docIDs.length; i++) {
      int docid = docIDs[i];
      Document doc = searcher.doc(docid, selector);
      String id = schema.printableUniqueKey(doc);
      uniqueKeys[i] = id;
    }
    return uniqueKeys;
  } else {
    return new String[docIDs.length];
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:PostingsSolrHighlighter.java

示例10: toSolrDocument

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
/**
 * Utility method for converting a {@link Document} from the index into a 
 * {@link SolrDocument} suitable for inclusion in a {@link SolrQueryResponse}
 */
public static final SolrDocument toSolrDocument( Document doc, final IndexSchema schema ) {
  SolrDocument out = new SolrDocument();
  for( IndexableField f : doc.getFields()) {
    // Make sure multivalued fields are represented as lists
    Object existing = out.get(f.name());
    if (existing == null) {
      SchemaField sf = schema.getFieldOrNull(f.name());
      if (sf != null && sf.multiValued()) {
        List<Object> vals = new ArrayList<>();
        vals.add( f );
        out.setField( f.name(), vals );
      }
      else{
        out.setField( f.name(), f );
      }
    }
    else {
      out.addField( f.name(), f );
    }
  }
  return out;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:ResponseWriterUtil.java

示例11: getIndexedId

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
/** Returns the indexed ID for this document.  The returned BytesRef is retained across multiple calls, and should not be modified. */
public BytesRef getIndexedId() {
  if (indexedId == null) {
    IndexSchema schema = req.getSchema();
    SchemaField sf = schema.getUniqueKeyField();
    if (sf != null) {
      if (solrDoc != null) {
        SolrInputField field = solrDoc.getField(sf.getName());

        int count = field==null ? 0 : field.getValueCount();
        if (count == 0) {
          if (overwrite) {
            throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document is missing mandatory uniqueKey field: " + sf.getName());
          }
        } else if (count  > 1) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document contains multiple values for uniqueKey field: " + field);
        } else {
          BytesRef b = new BytesRef();
          sf.getType().readableToIndexed(field.getFirstValue().toString(), b);
          indexedId = b;
        }
      }
    }
  }
  return indexedId;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:AddUpdateCommand.java

示例12: process

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
public SolrInputDocument process(SolrInputDocument doc) {
    Set<String> fieldParams = this.setting.getFieldParams();
    if (null != fieldParams && !fieldParams.isEmpty()) {
        for (String fieldParam : fieldParams) {
            SchemaField schemaField = this.schema.getField(fieldParam);
            if (null != schemaField && schemaField.getType() instanceof MultiLangField) {
                try {
                    predefineLangToMultiLangField(doc, fieldParam);
                } catch (IOException e) {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
                }
            }
        }
    } else {
        throw new SolrException(
                SolrException.ErrorCode.BAD_REQUEST,
                "Missing or faulty configuration of MultiLangIdentifierUpdateProcessor. Input fields must be specified as a comma separated list");
    }

    return doc;
}
 
开发者ID:smalldirector,项目名称:solr-multilingual-analyzer,代码行数:22,代码来源:MultiLangIdentifierUpdateProcessor.java

示例13: inform

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
@Override
public void inform(SolrCore core) {

  if (core.getUpdateHandler().getUpdateLog() == null) {
    throw new SolrException(SERVER_ERROR,
        "updateLog must be enabled.");
  }

  if (core.getLatestSchema().getUniqueKeyField() == null) {
    throw new SolrException(SERVER_ERROR,
        "schema must have uniqueKey defined.");
  }

  SchemaField userVersionField = core.getLatestSchema().getField(versionField);
  if (userVersionField == null || !userVersionField.stored() || userVersionField.multiValued()) {
    throw new SolrException(SERVER_ERROR,
        "field " + versionField + " must be defined in schema, be stored, and be single valued.");
  }

  try {
    ValueSource vs = userVersionField.getType().getValueSource(userVersionField, null);
    useFieldCache = true;
  } catch (Exception e) {
    log.warn("Can't use fieldcache/valuesource: " + e.getMessage());
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:DocBasedVersionConstraintsProcessorFactory.java

示例14: mutate

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
@Override
protected SolrInputField mutate(SolrInputField src) {
  SchemaField sf = schema.getFieldOrNull(src.getName());
  if (sf == null) { // remove this field
    return null;
  }
  FieldType type = PreAnalyzedField.createFieldType(sf);
  if (type == null) { // neither indexed nor stored - skip
    return null;
  }
  SolrInputField res = new SolrInputField(src.getName());
  res.setBoost(src.getBoost());
  for (Object o : src) {
    if (o == null) {
      continue;
    }
    Field pre = (Field)parser.createField(sf, o, 1.0f);
    if (pre != null) {
      res.addValue(pre, 1.0f);
    } else { // restore the original value
      log.warn("Could not parse field {} - using original value as is: {}", src.getName(), o);
      res.addValue(o, 1.0f);
    }
  }
  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:PreAnalyzedUpdateProcessorFactory.java

示例15: inform

import org.apache.solr.schema.SchemaField; //导入依赖的package包/类
@Override
public void inform(SolrCore core) {
  final SchemaField field = core.getLatestSchema().getFieldOrNull(getSignatureField());
  if (null == field) {
    throw new SolrException
      (ErrorCode.SERVER_ERROR,
       "Can't use signatureField which does not exist in schema: "
       + getSignatureField());
  }

  if (getOverwriteDupes() && ( ! field.indexed() ) ) {
    throw new SolrException
      (ErrorCode.SERVER_ERROR,
       "Can't set overwriteDupes when signatureField is not indexed: "
       + getSignatureField());
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:SignatureUpdateProcessorFactory.java


注:本文中的org.apache.solr.schema.SchemaField类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。