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


Java SchemaField.multiValued方法代码示例

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


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

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

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

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

示例4: toSolrDoc

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private static SolrDocument toSolrDoc(Document doc, 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());

      // don't return copyField targets
      if (sf != null && schema.isCopyFieldTarget(sf)) continue;

      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,代码来源:RealTimeGetComponent.java

示例5: toObject

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
public Map<String,Object> toObject(IndexSchema schema) {
  Map<String,Object> result = new HashMap<>();
  for (Fld fld : fields) {
    SchemaField sf = schema.getField(fld.ftype.fname);
    if (!sf.multiValued()) {
      result.put(fld.ftype.fname, fld.vals.get(0));
    } else {
      result.put(fld.ftype.fname, fld.vals);
    }
  }
  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:13,代码来源:SolrTestCaseJ4.java

示例6: getAndCheckVersionField

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
/**
 * Gets and returns the {@link #VERSION_FIELD} from the specified 
 * schema, after verifying that it is indexed, stored, and single-valued.  
 * If any of these pre-conditions are not met, it throws a SolrException 
 * with a user suitable message indicating the problem.
 */
public static SchemaField getAndCheckVersionField(IndexSchema schema) 
  throws SolrException {
  final String errPrefix = VERSION_FIELD + " field must exist in schema, using indexed=\"true\" or docValues=\"true\", stored=\"true\" and multiValued=\"false\"";
  SchemaField sf = schema.getFieldOrNull(VERSION_FIELD);

  if (null == sf) {
    throw new SolrException
      (SolrException.ErrorCode.SERVER_ERROR, 
       errPrefix + " (" + VERSION_FIELD + " does not exist)");
  }
  if ( !sf.indexed() && !sf.hasDocValues()) {
    throw new SolrException
      (SolrException.ErrorCode.SERVER_ERROR, 
       errPrefix + " (" + VERSION_FIELD + " must be either indexed or have docValues");
  }
  if ( !sf.stored() ) {
    throw new SolrException
      (SolrException.ErrorCode.SERVER_ERROR, 
       errPrefix + " (" + VERSION_FIELD + " is not stored");
  }
  if ( sf.multiValued() ) {
    throw new SolrException
      (SolrException.ErrorCode.SERVER_ERROR, 
       errPrefix + " (" + VERSION_FIELD + " is multiValued");
  }
  
  return sf;
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:VersionInfo.java

示例7: getDefaultSelector

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
@Override
public FieldMutatingUpdateProcessor.FieldNameSelector 
  getDefaultSelector(final SolrCore core) {

  return new FieldMutatingUpdateProcessor.FieldNameSelector() {
    @Override
    public boolean shouldMutate(final String fieldName) {
      final IndexSchema schema = core.getLatestSchema();

      // first check type since it should be fastest
      FieldType type = schema.getFieldTypeNoEx(fieldName);
      if (null == type) return false;
      
      if (! (TextField.class.isInstance(type) 
             || StrField.class.isInstance(type))) {
        return false;
      }

      // only ask for SchemaField if we passed the type check.
      SchemaField sf = schema.getFieldOrNull(fieldName);
      // shouldn't be null since since type wasn't, but just in case
      if (null == sf) return false;
      
      return ! sf.multiValued();
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:ConcatFieldUpdateProcessorFactory.java

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

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

示例10: getFilterQuery

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private String getFilterQuery( ResponseBuilder rb, String fieldName, ArrayList<String> valList,
                               int[] termPosRange, ArrayList<char[]> queryTokens, String suffix) {
  if (fieldName.indexOf( fieldDelim ) > 0) {
    return getFilterQuery( rb, fieldName.split( fieldSplitExpr ), valList, termPosRange, queryTokens, suffix );
  }
  if (valList.size() == 1) {
    // check if valList[0] is multi-term - if so, check if there is a single term equivalent
    // if this returns non-null, create an OR query with single term version
    // example "white linen perfume" vs "white linen shirt"  where "White Linen" is a brand
    String term = valList.get( 0 );
      
    if (term.indexOf( " " ) > 0) {
      String singleTermQuery = getSingleTermQuery( term );
      if (singleTermQuery != null) {
        StringBuilder strb = new StringBuilder( );
        // EH: possible meta-escaping problem if value includes {!field f=<fieldName>}value
        strb.append( "(" ).append( fieldName ).append( ":" )
            .append( term ).append( " OR (" ).append( singleTermQuery ).append( "))" ).append( suffix );
        Log.debug( "returning composite query: " + strb.toString( ) );
        return strb.toString( );
      }
    }
      
    String query = fieldName + ":" + term + suffix;
    Log.debug( "returning single query: " + query );
    return query;
  }
  else {
    SolrIndexSearcher searcher = rb.req.getSearcher();
    IndexSchema schema = searcher.getSchema();
    SchemaField field = schema.getField(fieldName);
    boolean useAnd = field.multiValued() && useAndForMultiValuedFields;
    // if query has 'or' in it and or is at a position 'within' the values for this field ...
    if (useAnd) {
      for (int i = termPosRange[0] + 1; i < termPosRange[1]; i++ ) {
        char[] qToken = queryTokens.get( i );
        // is the token 'or'?
        if (qToken.length == 2 && qToken[0] == 'o' && qToken[1] == 'r' ) {
          useAnd = false;
          break;
        }
      }
    }
      
    StringBuilder orQ = new StringBuilder( );
    for (String val : valList ) {
      if (orQ.length() > 0) orQ.append( (useAnd ? " AND " : " OR ") );
      orQ.append( val );
    }
    return fieldName + ":(" + orQ.toString() + ")" + suffix;
  }
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:53,代码来源:QueryAutoFilteringComponent.java

示例11: getFilterQuery

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
private String getFilterQuery( ResponseBuilder rb, String fieldName, ArrayList<String> valList,
                               int[] termPosRange, ArrayList<char[]> queryTokens, String suffix) {
    
  if (fieldName.indexOf( fieldDelim ) > 0) {
    return getFilterQuery( rb, fieldName.split( fieldSplitExpr ), valList, termPosRange, queryTokens, suffix );
  }
  if (valList.size() == 1) {
    // check if valList[0] is multi-term - if so, check if there is a single term equivalent
    // if this returns non-null, create an OR query with single term version
    // example "white linen perfume" vs "white linen shirt"  where "White Linen" is a brand
    String term = valList.get( 0 );

    if (term.indexOf( " " ) > 0) {
      String singleTermQuery = getSingleTermQuery( term );
      if (singleTermQuery != null) {
        StringBuilder strb = new StringBuilder( );
        strb.append( "(" ).append( fieldName ).append( ":" )
            .append( term ).append( " OR (" ).append( singleTermQuery ).append( "))" ).append( suffix );
        Log.debug( "returning composite query: " + strb.toString( ) );
        return strb.toString( );
      }
    }

    String query = fieldName + ":" + term + suffix;
    Log.debug( "returning single query: " + query );
    return query;
  }
  else {
    // Check if it is a MultiValued Field - if so, use AND internally
    SolrIndexSearcher searcher = rb.req.getSearcher();
    IndexSchema schema = searcher.getSchema();
    SchemaField field = schema.getField(fieldName);
      
    boolean useAnd = field.multiValued() && useAndForMultiValuedFields;
    // if query has 'or' in it and or is at a position 'within' the values for this field ...
    if (useAnd) {
      for (int i = termPosRange[0] + 1; i < termPosRange[1]; i++ ) {
        char[] qToken = queryTokens.get( i );
        if (qToken.length == 2 && qToken[0] == 'o' && qToken[1] == 'r' ) {
          useAnd = false;
          break;
        }
      }
    }
      
    StringBuilder orQ = new StringBuilder( );
    for (String val : valList ) {
      if (orQ.length() > 0) orQ.append( (useAnd ? " AND " : " OR ") );
      orQ.append( val );
    }
      
    String fq = fieldName + ":(" + orQ.toString() + ")" + suffix;
    Log.debug( "fq = " + fq );
    return fq;
  }
}
 
开发者ID:lucidworks,项目名称:query-autofiltering-component,代码行数:57,代码来源:QueryAutoFilteringComponent.java

示例12: getFieldWriters

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
protected FieldWriter[] getFieldWriters(String[] fields, SolrIndexSearcher searcher) throws IOException {
  IndexSchema schema = searcher.getSchema();
  FieldWriter[] writers = new FieldWriter[fields.length];
  for(int i=0; i<fields.length; i++) {
    String field = fields[i];
    SchemaField schemaField = schema.getField(field);

    if(!schemaField.hasDocValues()) {
      throw new IOException(field+" must have DocValues to use this feature.");
    }

    boolean multiValued = schemaField.multiValued();
    FieldType fieldType = schemaField.getType();
    if(fieldType instanceof TrieIntField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new IntFieldWriter(field);
      }
    } else if (fieldType instanceof TrieLongField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new LongFieldWriter(field);
      }
    } else if (fieldType instanceof TrieFloatField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new FloatFieldWriter(field);
      }
    } else if(fieldType instanceof TrieDoubleField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, true);
      } else {
        writers[i] = new DoubleFieldWriter(field);
      }
    } else if(fieldType instanceof StrField) {
      if(multiValued) {
        writers[i] = new MultiFieldWriter(field, fieldType, false);
      } else {
        writers[i] = new StringFieldWriter(field, fieldType);
      }
    } else {
      throw new IOException("Export fields must either be one of the following types: int,float,long,double,string");
    }
  }
  return writers;
}
 
开发者ID:europeana,项目名称:search,代码行数:50,代码来源:SortingResponseWriter.java

示例13: doEmptyFacetCounts

import org.apache.solr.schema.SchemaField; //导入方法依赖的package包/类
static void doEmptyFacetCounts(String field, String[] prefixes) throws Exception {
  SchemaField sf = h.getCore().getLatestSchema().getField(field);

  String response = JQ(req("q", "*:*"));
  Map rsp = (Map) ObjectBuilder.fromJSON(response);
  Long numFound  = (Long)(((Map)rsp.get("response")).get("numFound"));

  ModifiableSolrParams params = params("q","*:*", "rows","0", "facet","true", "facet.field","{!key=myalias}"+field);
  
  String[] methods = {null, "fc","enum","fcs"};
  if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
    methods = new String[]{null, "fc","enum"};
  }

  prefixes = prefixes==null ? new String[]{null} : prefixes;


  for (String method : methods) {
    if (method == null) {
      params.remove("facet.method");
    } else {
      params.set("facet.method", method);
    }
    for (String prefix : prefixes) {
      if (prefix == null) {
        params.remove("facet.prefix");
      } else {
        params.set("facet.prefix", prefix);
      }

      for (String missing : new String[] {null, "true"}) {
        if (missing == null) {
          params.remove("facet.missing");
        } else {
          params.set("facet.missing", missing);
        }
        
        String expected = missing==null ? "[]" : "[null," + numFound + "]";
        
        assertJQ(req(params),
            "/facet_counts/facet_fields/myalias==" + expected);
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:46,代码来源:SimpleFacetsTest.java


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