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


Java FieldType.readableToIndexed方法代码示例

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


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

示例1: createParser

import org.apache.solr.schema.FieldType; //导入方法依赖的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 fname = localParams.get(QueryParsing.F);
      FieldType ft = req.getSchema().getFieldTypeNoEx(fname);
      String val = localParams.get(QueryParsing.V);
      BytesRef term = new BytesRef();
      if (ft != null) {
        ft.readableToIndexed(val, term);
      } else {
        term.copyChars(val);
      }
      return new TermQuery(new Term(fname, term));
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TermQParserPlugin.java

示例2: transformer

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
static private Transformer transformer(final FieldType ft) {
  return new Transformer() {
    
    BytesRefBuilder term = new BytesRefBuilder();
    
    @Override
    public BytesRef transform(Object joinId) {
      String joinStr = joinId.toString();
      // logic same as TermQParserPlugin
      if (ft != null) {
        ft.readableToIndexed(joinStr, term);
      } else {
        term.copyChars(joinStr);
      }
      return term.toBytesRef();
    }
    
  };
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:20,代码来源:XJoinQParserPlugin.java

示例3: transformer

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
static private Transformer transformer(final FieldType ft) {
  return new Transformer() {
    
    BytesRef term = new BytesRef();
    
    @Override
    public BytesRef transform(Object joinId) {
      if (joinId == null) {
        throw new RuntimeException("joinId is null! (weird)");
      }
      String joinStr = joinId.toString();
      // logic same as TermQParserPlugin
      if (ft != null) {
        ft.readableToIndexed(joinStr, term);
      } else {
        term.copyChars(joinStr);
      }
      return BytesRef.deepCopyOf(term);
    }
    
  };
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:23,代码来源:XJoinQParserPlugin.java

示例4: convertFieldValueUsingType

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
/**
 * Inspects a raw field value (which may come from a doc in the index, or a 
 * doc in the UpdateLog that still has String values, or a String sent by 
 * the user as a param) and if it is a String, asks the versionField FieldType 
 * to convert it to an Object suitable for comparison.
 */
private Object convertFieldValueUsingType(SchemaField sf, final Object rawValue) {
  if (rawValue instanceof CharSequence) {
    // in theory, the FieldType might still be CharSequence based,
    // but in that case trust it to do an identiy conversion...
    FieldType fieldType = userVersionField.getType();
    BytesRef term = new BytesRef();
    fieldType.readableToIndexed((CharSequence)rawValue, term);
    return fieldType.toObject(userVersionField, term);
  }
  // else...
  return rawValue;
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:DocBasedVersionConstraintsProcessorFactory.java

示例5: doPivots

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
/**
 * Recursive function to compute all the pivot counts for the values under teh specified field
 */
protected List<NamedList<Object>> doPivots(NamedList<Integer> superFacets,
    String field, String subField, Deque<String> fnames,Deque<String> vnames,DocSet docs) throws IOException {

  SolrIndexSearcher searcher = rb.req.getSearcher();
  // TODO: optimize to avoid converting to an external string and then having to convert back to internal below
  SchemaField sfield = searcher.getSchema().getField(field);
  FieldType ftype = sfield.getType();

  String nextField = fnames.poll();

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

  List<NamedList<Object>> values = new ArrayList<>( 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() >= getMinCountForField(field)) {  
      final String fieldValue = kv.getKey();

      SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<>();
      pivot.add( "field", field );
      if (null == fieldValue) {
        pivot.add( "value", null );
      } else {
        ftype.readableToIndexed(fieldValue, termval);
        pivot.add( "value", ftype.toObject(sfield, termval) );
      }
      pivot.add( "count", kv.getValue() );

      DocSet subset = getSubset(docs, sfield, fieldValue);
      
      if( subField != null )  {
        NamedList<Integer> facetCounts;
        if(!vnames.isEmpty()){
          String val = vnames.pop();
          facetCounts = new NamedList<Integer>();
          facetCounts.add(val, getSubsetSize(subset,
                                             searcher.getSchema().getField(subField),
                                             val));
        } else {
          facetCounts = this.getTermCountsForPivots(subField, subset);
        }

        if (facetCounts.size() >= 1) {
          pivot.add( "pivot", doPivots( facetCounts, subField, nextField, fnames, vnames, subset) );
        }
      }
      values.add( pivot );
    }

  }
  // put the field back on the list
  fnames.push( nextField );
  return values;
}
 
开发者ID:europeana,项目名称:search,代码行数:59,代码来源:PivotFacetProcessor.java

示例6: doPivots

import org.apache.solr.schema.FieldType; //导入方法依赖的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

示例7: loadQLTBMap

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
/**
 * Load the QLTB map from a Config.
 *
 * Read and process the "boosts/query" XPath nodes from the given
 * Config, and build them into a QLTB map. The XML format is described
 * in the class documentation.
 *
 * The result of this function is a map of (analyzed) query strings
 * with their respective lists of boosted query terms. These are
 * ConstantScoreQuery instances for each term with the corresponding
 * boost factor. (Invalid - i.e. non-numerical - boost factors are
 * logged as warnings).
 *
 * The SOLR core that is passed into this function is necessary for
 * determinating the FieldType of the boosted fields. Only with the
 * correct field type is it possible to boost non-string fields, as
 * these non-string values need to be ft.readableToIndexed().
 *
 * @param cfg
 *            Config object to read the XML QLTB from
 * @param core
 *            SOLR Core the query is performed on
 * @return QLTB map
 *
 * @throws IOException
 *             If the query could not be analysed
 */
private Map<String, List<Query>> loadQLTBMap(final Config cfg, final SolrCore core) throws IOException {
    Map<String, List<Query>> map = new HashMap<String, List<Query>>();
    NodeList nodes = (NodeList) cfg.evaluate("boosts/query", XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        String qstr = DOMUtil.getAttr(node, "text", "missing query 'text'");
        qstr = getAnalyzedQuery(qstr);
        NodeList children = node.getChildNodes();
        List<Query> termBoosts = new ArrayList<Query>();
        for (int j = 0; j < children.getLength(); j++) {
            Node child = children.item(j);
            if (!child.getNodeName().equals("term")) {
                continue;
            }
            String field = DOMUtil.getAttr(child, "field", "missing 'field'");
            String value = DOMUtil.getAttr(child, "value", "missing 'value'");
            String boost = DOMUtil.getAttr(child, "boost", "missing 'boost'");
            float termBoost = 1;
            try {
                termBoost = Float.parseFloat(boost);
            } catch (NumberFormatException e) {
                log.warn(
                    "invalid boost " + boost + " for query \"" + qstr
                    + "\", term: \"" + field + ":" + value + "\": "
                    +  e.getMessage()
                );
                continue;
            }
            // without readableToIndexed QLTB boosting would only work
            // for string field types
            FieldType ft = core.getLatestSchema().getField(field).getType();
            value = ft.readableToIndexed(value);
            Term t = new Term(field, value);
            TermQuery tq = new TermQuery(t);
            ConstantScoreQuery csq = new ConstantScoreQuery(tq);
            csq.setBoost(termBoost);
            termBoosts.add(csq);
        }
        map.put(qstr, termBoosts);
    }
    return map;
}
 
开发者ID:solute,项目名称:qltb,代码行数:70,代码来源:QLTBComponent.java

示例8: doPivots

import org.apache.solr.schema.FieldType; //导入方法依赖的package包/类
/**
 * Recursive function to do all the pivots
 */
protected List<NamedList<Object>> doPivots(NamedList<Integer> superFacets,
                                           String field, String subField, Deque<String> fnames,
                                           DocSet docs) throws IOException
{
  SolrIndexSearcher searcher = rb.req.getSearcher();
  // TODO: optimize to avoid converting to an external string and then having to convert back to internal below
  SchemaField sfield = searcher.getSchema().getField(field);
  FieldType ftype = sfield.getType();

  String nextField = fnames.poll();

  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() >= minMatch) {

      // may be null when using facet.missing
      final String fieldValue = kv.getKey(); 

      // don't reuse the same BytesRef each time since we will be 
      // constructing Term objects used in TermQueries that may be cached.
      BytesRef termval = null;

      SimpleOrderedMap<Object> pivot = new SimpleOrderedMap<Object>();
      pivot.add( "field", field );
      if (null == fieldValue) {
        pivot.add( "value", null );
      } else {
        termval = new BytesRef();
        ftype.readableToIndexed(fieldValue, termval);
        pivot.add( "value", ftype.toObject(sfield, termval) );
      }
      pivot.add( "count", kv.getValue() );
      
      if( subField == null ) {
        values.add( pivot );
      }
      else {
        DocSet subset = null;
        if ( null == termval ) {
          DocSet hasVal = searcher.getDocSet
            (new TermRangeQuery(field, null, null, false, false));
          subset = docs.andNot(hasVal);
        } else {
          Query query = new TermQuery(new Term(field, termval));
          subset = searcher.getDocSet(query, docs);
        }
        super.docs = subset;//used by getTermCounts()

        NamedList<Integer> nl = this.getTermCounts(subField);
        if (nl.size() >= minMatch) {
          pivot.add( "pivot", doPivots( nl, subField, nextField, fnames, subset) );
          values.add( pivot ); // only add response if there are some counts
        }
      }
    }
  }
  
  // put the field back on the list
  fnames.push( nextField );
  return values;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:66,代码来源:PivotFacetHelper.java


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