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


Java SchemaField.getType方法代码示例

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


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

示例1: 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 )) {
      SchemaField field = schema.getField(fieldName);
      if (field.stored() && field.getType() instanceof StrField ) {
        strFields.add( fieldName );
      }
    }
  }
    
  return strFields;
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:19,代码来源:QueryAutoFilteringComponent.java

示例2: 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

示例3: 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

示例4: getStoredHighlightFieldNames

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
/**
 * Returns a collection of the names of all stored fields which can be
 * highlighted the index reader knows about.
 */
public Collection<String> getStoredHighlightFieldNames() {
  synchronized (this) {
    if (storedHighlightFieldNames == null) {
      storedHighlightFieldNames = new LinkedList<>();
      for (String fieldName : fieldNames) {
        try {
          SchemaField field = schema.getField(fieldName);
          if (field.stored() &&
              ((field.getType() instanceof org.apache.solr.schema.TextField) ||
                  (field.getType() instanceof org.apache.solr.schema.StrField))) {
            storedHighlightFieldNames.add(fieldName);
          }
        } catch (RuntimeException e) { // getField() throws a SolrException, but it arrives as a RuntimeException
          log.warn("Field \"" + fieldName + "\" found in index, but not defined in schema.");
        }
      }
    }
    return storedHighlightFieldNames;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:SolrIndexSearcher.java

示例5: extendedFieldType

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
public MultiSerializable extendedFieldType(String name, ResponseBuilder rb) {
  IndexSchema sch;
  SchemaField sf;
  FieldType ft;
  if ((sch = rb.req.getSchema()) != null && (sf = sch.getFieldOrNull(name)) != null
      && (ft = sf.getType()) != null && ft instanceof MultiSerializable) {
    return (MultiSerializable)ft;
  } else {
    return null;
  }
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:12,代码来源:FacetComponent.java

示例6: parseSfield

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
    String sfield = fp.getParam(SpatialParams.FIELD);
    if (sfield == null) return null;
    SchemaField sf = fp.getReq().getSchema().getField(sfield);
    FieldType type = sf.getType();
    if (type instanceof AbstractSpatialFieldType) {
        AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type;
        return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield));
    }
    ValueSource vs = type.getValueSource(sf, fp);
    if (vs instanceof MultiValueSource) {
        return (MultiValueSource)vs;
    }
    throw new SyntaxError("Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf);
}
 
开发者ID:gogobot,项目名称:solr-distance-cluster,代码行数:16,代码来源:DistanceParser.java

示例7: populateFieldInfo

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private static void populateFieldInfo(IndexSchema schema,
                                      Map<String, List<String>> typeusemap, Map<String, Object> fields,
                                      SchemaField uniqueField, SchemaField f) {
  FieldType ft = f.getType();
  SimpleOrderedMap<Object> field = new SimpleOrderedMap<>();
  field.add( "type", ft.getTypeName() );
  field.add( "flags", getFieldFlags(f) );
  if( f.isRequired() ) {
    field.add( "required", f.isRequired() );
  }
  if( f.getDefaultValue() != null ) {
    field.add( "default", f.getDefaultValue() );
  }
  if (f == uniqueField){
    field.add("uniqueKey", true);
  }
  if (ft.getIndexAnalyzer().getPositionIncrementGap(f.getName()) != 0) {
    field.add("positionIncrementGap", ft.getIndexAnalyzer().getPositionIncrementGap(f.getName()));
  }
  field.add("copyDests", toListOfStringDests(schema.getCopyFieldsList(f.getName())));
  field.add("copySources", schema.getCopySources(f.getName()));


  fields.put( f.getName(), field );

  List<String> v = typeusemap.get( ft.getTypeName() );
  if( v == null ) {
    v = new ArrayList<>();
  }
  v.add( f.getName() );
  typeusemap.put( ft.getTypeName(), v );
}
 
开发者ID:europeana,项目名称:search,代码行数:33,代码来源:LukeRequestHandler.java

示例8: addFieldCommand

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
/**
 * Adds a field command based on the specified field.
 * If the field is not compatible with {@link CommandField} it invokes the
 * {@link #addFunctionCommand(String, org.apache.solr.request.SolrQueryRequest)} method.
 *
 * @param field The fieldname to group by.
 */
public void addFieldCommand(String field, SolrQueryRequest request) throws SyntaxError {
  SchemaField schemaField = searcher.getSchema().getField(field); // Throws an exception when field doesn't exist. Bad request.
  FieldType fieldType = schemaField.getType();
  ValueSource valueSource = fieldType.getValueSource(schemaField, null);
  if (!(valueSource instanceof StrFieldSource)) {
    addFunctionCommand(field, request);
    return;
  }

  Grouping.CommandField gc = new CommandField();
  gc.groupSort = groupSort;
  gc.groupBy = field;
  gc.key = field;
  gc.numGroups = limitDefault;
  gc.docsPerGroup = docsPerGroupDefault;
  gc.groupOffset = groupOffsetDefault;
  gc.offset = cmd.getOffset();
  gc.sort = sort;
  gc.format = defaultFormat;
  gc.totalCount = defaultTotalCount;

  if (main) {
    gc.main = true;
    gc.format = Grouping.Format.simple;
  }

  if (gc.format == Grouping.Format.simple) {
    gc.groupOffset = 0;  // doesn't make sense
  }
  commands.add(gc);
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:Grouping.java

示例9: parseSfield

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
  String sfield = fp.getParam(SpatialParams.FIELD);
  if (sfield == null) return null;
  SchemaField sf = fp.getReq().getSchema().getField(sfield);
  FieldType type = sf.getType();
  if (type instanceof AbstractSpatialFieldType) {
    AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type;
    return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield));
  }
  ValueSource vs = type.getValueSource(sf, fp);
  if (vs instanceof MultiValueSource) {
    return (MultiValueSource)vs;
  }
  throw new SyntaxError("Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf);
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:GeoDistValueSourceParser.java

示例10: createParser

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
  return new QParser(qstr, localParams, params, req) {
    @Override
    public Query parse() {
      String field = localParams.get(QueryParsing.F);
      String queryText = localParams.get(QueryParsing.V);
      SchemaField sf = req.getSchema().getField(field);
      FieldType ft = sf.getType();
      return ft.getFieldQuery(this, sf, queryText);
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:FieldQParserPlugin.java

示例11: getStatsFields

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
public NamedList<Object> getStatsFields() throws IOException, SyntaxError {
  NamedList<Object> res = new SimpleOrderedMap<>();
  String[] statsFs = params.getParams(StatsParams.STATS_FIELD);
  boolean isShard = params.getBool(ShardParams.IS_SHARD, false);
  if (null != statsFs) {
    final IndexSchema schema = searcher.getSchema();
    for (String f : statsFs) {
      boolean calcDistinct = params.getFieldBool(f, StatsParams.STATS_CALC_DISTINCT, false);

      parseParams(f);

      String[] facets = params.getFieldParams(key, StatsParams.STATS_FACET);
      if (facets == null) {
        facets = new String[0]; // make sure it is something...
      }
      SchemaField sf = schema.getField(statsField);
      FieldType ft = sf.getType();
      NamedList<?> stv;
      
      if (sf.multiValued() || ft.multiValuedFieldCache()) {
        if(sf.hasDocValues()) {
          stv = DocValuesStats.getCounts(searcher, sf.getName(), base, calcDistinct, facets).getStatsValues();
        } else {
          //use UnInvertedField for multivalued fields
          UnInvertedField uif = UnInvertedField.getUnInvertedField(statsField, searcher);
          stv = uif.getStats(searcher, base, calcDistinct, facets).getStatsValues();
        }
      } else {
        stv = getFieldCacheStats(statsField, calcDistinct, facets);
      }
      if (isShard == true || (Long) stv.get("count") > 0) {
        res.add(key, stv);
      } else {
        res.add(key, null);
      }
    }
  }
  return res;
}
 
开发者ID:europeana,项目名称:search,代码行数:40,代码来源:StatsComponent.java

示例12: selectFacetMethod

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
/**
 * This method will force the appropriate facet method even if the user provided a different one as a request parameter
 *
 * N.B. this method could overwrite what you passed as request parameter. Be Extra careful
 *
 * @param field field we are faceting
 * @param method the facet method passed as a request parameter
 * @param mincount the minimum value a facet should have to be returned
 * @return the FacetMethod to use
 */
 static FacetMethod selectFacetMethod(SchemaField field, FacetMethod method, Integer mincount) {

   FieldType type = field.getType();
   if (type.isPointField()) {
     // Only FCS is supported for PointFields for now
     return FacetMethod.FCS;
   }

   /*The user did not specify any preference*/
   if (method == null) {
     /* Always use filters for booleans if not DocValues only... we know the number of values is very small. */
     if (type instanceof BoolField && (field.indexed() == true || field.hasDocValues() == false)) {
       method = FacetMethod.ENUM;
     } else if (type.getNumberType() != null && !field.multiValued()) {
      /* the per-segment approach is optimal for numeric field types since there
         are no global ords to merge and no need to create an expensive
         top-level reader */
       method = FacetMethod.FCS;
     } else {
       // TODO: default to per-segment or not?
       method = FacetMethod.FC;
     }
   }

   /* FC without docValues does not support single valued numeric facets */
   if (method == FacetMethod.FC
       && type.getNumberType() != null && !field.multiValued()) {
     method = FacetMethod.FCS;
   }

   /* UIF without DocValues can't deal with mincount=0, the reason is because
       we create the buckets based on the values present in the result set.
       So we are not going to see facet values which are not in the result set */
   if (method == FacetMethod.UIF
       && !field.hasDocValues() && mincount == 0) {
     method = field.multiValued() ? FacetMethod.FC : FacetMethod.FCS;
   }

   /* ENUM can't deal with trie fields that index several terms per value */
   if (method == FacetMethod.ENUM
       && TrieField.getMainValuePrefix(type) != null) {
     method = field.multiValued() ? FacetMethod.FC : FacetMethod.FCS;
   }

   /* FCS can't deal with multi token fields */
   final boolean multiToken = field.multiValued() || type.multiValuedFieldCache();
   if (method == FacetMethod.FCS
       && multiToken) {
     method = FacetMethod.FC;
   }

   return method;
}
 
开发者ID:upenn-libraries,项目名称:solrplugins,代码行数:64,代码来源:SimpleFacets.java

示例13: serializeTopDocs

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
protected NamedList serializeTopDocs(QueryCommandResult result) throws IOException {
  NamedList<Object> queryResult = new NamedList<>();
  queryResult.add("matches", result.getMatches());
  queryResult.add("totalHits", result.getTopDocs().totalHits);
  if (rb.getGroupingSpec().isNeedScore()) {
    queryResult.add("maxScore", result.getTopDocs().getMaxScore());
  }
  List<NamedList> documents = new ArrayList<>();
  queryResult.add("documents", documents);

  final IndexSchema schema = rb.req.getSearcher().getSchema();
  SchemaField uniqueField = schema.getUniqueKeyField();
  CharsRef spare = new CharsRef();
  for (ScoreDoc scoreDoc : result.getTopDocs().scoreDocs) {
    NamedList<Object> document = new NamedList<>();
    documents.add(document);

    Document doc = retrieveDocument(uniqueField, scoreDoc.doc);
    document.add("id", uniqueField.getType().toExternal(doc.getField(uniqueField.getName())));
    if (rb.getGroupingSpec().isNeedScore())  {
      document.add("score", scoreDoc.score);
    }
    if (!FieldDoc.class.isInstance(scoreDoc)) {
      continue;
    }

    FieldDoc fieldDoc = (FieldDoc) scoreDoc;
    Object[] convertedSortValues  = new Object[fieldDoc.fields.length];
    for (int j = 0; j < fieldDoc.fields.length; j++) {
      Object sortValue  = fieldDoc.fields[j];
      Sort groupSort = rb.getGroupingSpec().getGroupSort();
      SchemaField field = groupSort.getSort()[j].getField() != null 
                        ? schema.getFieldOrNull(groupSort.getSort()[j].getField()) : null;
      if (field != null) {
        FieldType fieldType = field.getType();
        if (sortValue != null) {
          sortValue = fieldType.marshalSortValue(sortValue);
        }
      }
      convertedSortValues[j] = sortValue;
    }
    document.add("sortValues", convertedSortValues);
  }

  return queryResult;
}
 
开发者ID:europeana,项目名称:search,代码行数:47,代码来源:TopGroupsResultTransformer.java

示例14: doPivots

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
protected List<NamedList<Object>> doPivots(NamedList<Integer> superFacets, String fieldName, String fieldPath,
                                           Deque<String> queue, DocSet docs) throws IOException {

    SchemaField field = getSchemaField(fieldName);
    FieldType ftype = field.getType();
    String subField = null;
    if( queue.size() > 0 )  {
        subField = queue.remove();
    }

    // re-usable BytesRefBuilder for conversion of term values to Objects
    BytesRefBuilder termval = new BytesRefBuilder();

    List<NamedList<Object>> values = new ArrayList<NamedList<Object>>(superFacets.size());
    for (Map.Entry<String, Integer> kv : superFacets) {
        // Only sub-facet if parent facet has positive count - still may not be any values for the sub-field though
        if (kv.getValue() >= this.minCount) {

            final String fieldValue = kv.getKey();
            final int pivotCount = kv.getValue();

            SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<Object>();
            if (null == fieldValue) {
                pivot.add( VALUE, null );
            } else {
                ftype.readableToIndexed(fieldValue, termval);
                pivot.add( VALUE, ftype.toObject(field, termval.get()) );
            }
            pivot.add( COUNT, pivotCount );

            if( subField != null )  {
                final String newfieldPath = fieldPath + "|" + subField;
                //TODO pass subset here
                final DocSet subset = getSubset(docs, field, fieldValue);
                NamedList<Integer> facetCounts= this.getTermCounts(subField, newfieldPath, minCount, limit, subset);
                if (facetCounts.size() >= 1) {
                    // returns null if empty
                    pivot.add(subField, doPivots(facetCounts, subField, newfieldPath, queue, subset));
                }
            }
            values.add( pivot );
        }
    }
    return values;
}
 
开发者ID:DiceTechJobs,项目名称:SolrPlugins,代码行数:46,代码来源:JointCounts.java

示例15: getIndexedFieldsInfo

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private static SimpleOrderedMap<Object> getIndexedFieldsInfo(SolrQueryRequest req)
    throws Exception {

  SolrIndexSearcher searcher = req.getSearcher();
  SolrParams params = req.getParams();

  Set<String> fields = null;
  String fl = params.get(CommonParams.FL);
  if (fl != null) {
    fields = new TreeSet<>(Arrays.asList(fl.split( "[,\\s]+" )));
  }

  AtomicReader reader = searcher.getAtomicReader();
  IndexSchema schema = searcher.getSchema();

  // Don't be tempted to put this in the loop below, the whole point here is to alphabetize the fields!
  Set<String> fieldNames = new TreeSet<>();
  for(FieldInfo fieldInfo : reader.getFieldInfos()) {
    fieldNames.add(fieldInfo.name);
  }

  // Walk the term enum and keep a priority queue for each map in our set
  SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>();

  for (String fieldName : fieldNames) {
    if (fields != null && ! fields.contains(fieldName) && ! fields.contains("*")) {
      continue; //we're not interested in this field Still an issue here
    }

    SimpleOrderedMap<Object> fieldMap = new SimpleOrderedMap<>();

    SchemaField sfield = schema.getFieldOrNull( fieldName );
    FieldType ftype = (sfield==null)?null:sfield.getType();

    fieldMap.add( "type", (ftype==null)?null:ftype.getTypeName() );
    fieldMap.add("schema", getFieldFlags(sfield));
    if (sfield != null && schema.isDynamicField(sfield.getName()) && schema.getDynamicPattern(sfield.getName()) != null) {
      fieldMap.add("dynamicBase", schema.getDynamicPattern(sfield.getName()));
    }
    Terms terms = reader.fields().terms(fieldName);
    if (terms == null) { // Not indexed, so we need to report what we can (it made it through the fl param if specified)
      finfo.add( fieldName, fieldMap );
      continue;
    }

    if(sfield != null && sfield.indexed() ) {
      // In the pre-4.0 days, this did a veeeery expensive range query. But we can be much faster now,
      // so just do this all the time.
      Document doc = getFirstLiveDoc(terms, reader);


      if( doc != null ) {
        // Found a document with this field
        try {
          IndexableField fld = doc.getField( fieldName );
          if( fld != null ) {
            fieldMap.add("index", getFieldFlags(fld));
          }
          else {
            // it is a non-stored field...
            fieldMap.add("index", "(unstored field)");
          }
        }
        catch( Exception ex ) {
          log.warn( "error reading field: "+fieldName );
        }
      }
      fieldMap.add("docs", terms.getDocCount());

    }
    if (fields != null && (fields.contains(fieldName) || fields.contains("*"))) {
      getDetailedFieldInfo(req, fieldName, fieldMap);
    }
    // Add the field
    finfo.add( fieldName, fieldMap );
  }
  return finfo;
}
 
开发者ID:europeana,项目名称:search,代码行数:79,代码来源:LukeRequestHandler.java


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