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


Java SolrIndexSearcher.getAtomicReader方法代码示例

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


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

示例1: testDocValues

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public void testDocValues() throws IOException {
  assertU(adoc("id", "1", "floatdv", "4.5", "intdv", "-1", "intdv", "3", "stringdv", "value1", "stringdv", "value2"));
  assertU(commit());
  try (SolrCore core = h.getCoreInc()) {
    final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
    final SolrIndexSearcher searcher = searcherRef.get();
    try {
      final AtomicReader reader = searcher.getAtomicReader();
      assertEquals(1, reader.numDocs());
      final FieldInfos infos = reader.getFieldInfos();
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("stringdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("floatdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED_SET, infos.fieldInfo("intdv").getDocValuesType());

      SortedSetDocValues dv = reader.getSortedSetDocValues("stringdv");
      dv.setDocument(0);
      assertEquals(0, dv.nextOrd());
      assertEquals(1, dv.nextOrd());
      assertEquals(SortedSetDocValues.NO_MORE_ORDS, dv.nextOrd());
    } finally {
      searcherRef.decref();
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:25,代码来源:DocValuesMultiTest.java

示例2: UnInvertedField

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public UnInvertedField(String field, SolrIndexSearcher searcher) throws IOException {
  super(field,
        // threshold, over which we use set intersections instead of counting
        // to (1) save memory, and (2) speed up faceting.
        // Add 2 for testing purposes so that there will always be some terms under
        // the threshold even when the index is very
        // small.
        searcher.maxDoc()/20 + 2,
        DEFAULT_INDEX_INTERVAL_BITS);
  //System.out.println("maxTermDocFreq=" + maxTermDocFreq + " maxDoc=" + searcher.maxDoc());

  final String prefix = TrieField.getMainValuePrefix(searcher.getSchema().getFieldType(field));
  this.searcher = searcher;
  try {
    AtomicReader r = searcher.getAtomicReader();
    uninvert(r, r.getLiveDocs(), prefix == null ? null : new BytesRef(prefix));
  } catch (IllegalStateException ise) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, ise.getMessage());
  }
  if (tnums != null) {
    for(byte[] target : tnums) {
      if (target != null && target.length > (1<<24)*.9) {
        SolrCore.log.warn("Approaching too many values for UnInvertedField faceting on field '"+field+"' : bucket size=" + target.length);
      }
    }
  }

  // free space if outrageously wasteful (tradeoff memory/cpu) 
  if ((maxTermCounts.length - numTermsInField) > 1024) { // too much waste!
    int[] newMaxTermCounts = new int[numTermsInField];
    System.arraycopy(maxTermCounts, 0, newMaxTermCounts, 0, numTermsInField);
    maxTermCounts = newMaxTermCounts;
  }

  SolrCore.log.info("UnInverted multi-valued field " + toString());
  //System.out.println("CREATED: " + toString() + " ti.index=" + ti.index);
}
 
开发者ID:europeana,项目名称:search,代码行数:38,代码来源:UnInvertedField.java

示例3: FieldFacetStats

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public FieldFacetStats(SolrIndexSearcher searcher, String name, SchemaField field_sf, SchemaField facet_sf, boolean calcDistinct) {
  this.name = name;
  this.field_sf = field_sf;
  this.facet_sf = facet_sf;
  this.calcDistinct = calcDistinct;

  topLevelReader = searcher.getAtomicReader();
  valueSource = facet_sf.getType().getValueSource(facet_sf, null);

  facetStatsValues = new HashMap<>();
  facetStatsTerms = new ArrayList<>();
  missingStats = new HashMap<>();
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:FieldFacetStats.java

示例4: getSortDoc

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
private SortDoc getSortDoc(SolrIndexSearcher searcher, SortField[] sortFields) throws IOException {
  SortValue[] sortValues = new SortValue[sortFields.length];
  IndexSchema schema = searcher.getSchema();
  for(int i=0; i<sortFields.length; ++i) {
    SortField sf = sortFields[i];
    String field = sf.getField();
    boolean reverse = sf.getReverse();
    SchemaField schemaField = schema.getField(field);
    FieldType ft = schemaField.getType();

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

    if(ft instanceof TrieIntField) {
      if(reverse) {
        sortValues[i] = new IntValue(field, new IntDesc());
      } else {
        sortValues[i] = new IntValue(field, new IntAsc());
      }
    } else if(ft instanceof TrieFloatField) {
      if(reverse) {
        sortValues[i] = new FloatValue(field, new FloatDesc());
      } else {
        sortValues[i] = new FloatValue(field, new FloatAsc());
      }
    } else if(ft instanceof TrieDoubleField) {
      if(reverse) {
        sortValues[i] = new DoubleValue(field, new DoubleDesc());
      } else {
        sortValues[i] = new DoubleValue(field, new DoubleAsc());
      }
    } else if(ft instanceof TrieLongField) {
      if(reverse) {
        sortValues[i] = new LongValue(field, new LongDesc());
      } else {
        sortValues[i] = new LongValue(field, new LongAsc());
      }
    } else if(ft instanceof StrField) {
      AtomicReader reader = searcher.getAtomicReader();
      SortedDocValues vals =  reader.getSortedDocValues(field);
      if(reverse) {
        sortValues[i] = new StringValue(vals, field, new IntDesc());
      } else {
        sortValues[i] = new StringValue(vals, field, new IntAsc());
      }
    } else {
      throw new IOException("Sort fields must be one of the following types: int,float,long,double,string");
    }
  }

  if(sortValues.length == 1) {
    return new SingleValueSortDoc(sortValues[0]);
  } else if(sortValues.length == 2) {
    return new DoubleValueSortDoc(sortValues[0], sortValues[1]);
  } else if(sortValues.length == 3) {
    return new TripleValueSortDoc(sortValues[0], sortValues[1], sortValues[2]);
  } else if(sortValues.length == 4) {
    return new QuadValueSortDoc(sortValues[0], sortValues[1], sortValues[2], sortValues[3]);
  } else {
    throw new IOException("A max of 4 sorts can be specified");
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:64,代码来源:SortingResponseWriter.java

示例5: getIndexedFieldsInfo

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

示例6: testDocValues

import org.apache.solr.search.SolrIndexSearcher; //导入方法依赖的package包/类
public void testDocValues() throws IOException {
  assertU(adoc("id", "1"));
  assertU(commit());
  try (SolrCore core = h.getCoreInc()) {
    final RefCounted<SolrIndexSearcher> searcherRef = core.openNewSearcher(true, true);
    final SolrIndexSearcher searcher = searcherRef.get();
    try {
      final AtomicReader reader = searcher.getAtomicReader();
      assertEquals(1, reader.numDocs());
      final FieldInfos infos = reader.getFieldInfos();
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("floatdv").getDocValuesType());
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("intdv").getDocValuesType());
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("doubledv").getDocValuesType());
      assertEquals(DocValuesType.NUMERIC, infos.fieldInfo("longdv").getDocValuesType());
      assertEquals(DocValuesType.SORTED, infos.fieldInfo("stringdv").getDocValuesType());

      assertEquals((long) Float.floatToIntBits(1), reader.getNumericDocValues("floatdv").get(0));
      assertEquals(2L, reader.getNumericDocValues("intdv").get(0));
      assertEquals(Double.doubleToLongBits(3), reader.getNumericDocValues("doubledv").get(0));
      assertEquals(4L, reader.getNumericDocValues("longdv").get(0));

      final IndexSchema schema = core.getLatestSchema();
      final SchemaField floatDv = schema.getField("floatdv");
      final SchemaField intDv = schema.getField("intdv");
      final SchemaField doubleDv = schema.getField("doubledv");
      final SchemaField longDv = schema.getField("longdv");

      FunctionValues values = floatDv.getType().getValueSource(floatDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0));
      assertEquals(1f, values.floatVal(0), 0f);
      assertEquals(1f, values.objectVal(0));
      values = intDv.getType().getValueSource(intDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0));
      assertEquals(2, values.intVal(0));
      assertEquals(2, values.objectVal(0));
      values = doubleDv.getType().getValueSource(doubleDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0));
      assertEquals(3d, values.doubleVal(0), 0d);
      assertEquals(3d, values.objectVal(0));
      values = longDv.getType().getValueSource(longDv, null).getValues(null, searcher.getAtomicReader().leaves().get(0));
      assertEquals(4L, values.longVal(0));
      assertEquals(4L, values.objectVal(0));
    } finally {
      searcherRef.decref();
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:DocValuesTest.java


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