Java 类org.apache.lucene.index.MultiDocValues 实例源码

项目:Elasticsearch    文件:HasChildQueryParser.java   
@Override
public Query rewrite(IndexReader reader) throws IOException {
    if (getBoost() != 1.0F) {
        return super.rewrite(reader);
    }
    if (reader instanceof DirectoryReader) {
        String joinField = ParentFieldMapper.joinField(parentType);
        IndexSearcher indexSearcher = new IndexSearcher(reader);
        indexSearcher.setQueryCache(null);
        indexSearcher.setSimilarity(similarity);
        IndexParentChildFieldData indexParentChildFieldData = parentChildIndexFieldData.loadGlobal((DirectoryReader) reader);
        MultiDocValues.OrdinalMap ordinalMap = ParentChildIndexFieldData.getOrdinalMap(indexParentChildFieldData, parentType);
        return JoinUtil.createJoinQuery(joinField, innerQuery, toQuery, indexSearcher, scoreMode, ordinalMap, minChildren, maxChildren);
    } else {
        if (reader.leaves().isEmpty() && reader.numDocs() == 0) {
            // asserting reader passes down a MultiReader during rewrite which makes this
            // blow up since for this query to work we have to have a DirectoryReader otherwise
            // we can't load global ordinals - for this to work we simply check if the reader has no leaves
            // and rewrite to match nothing
            return new MatchNoDocsQuery();
        }
        throw new IllegalStateException("can't load global ordinals for reader of type: " + reader.getClass() + " must be a DirectoryReader");
    }
}
项目:search    文件:LuceneTestCase.java   
/** 
 * checks that norms are the same across all fields 
 */
public void assertNormsEquals(String info, IndexReader leftReader, IndexReader rightReader) throws IOException {
  Fields leftFields = MultiFields.getFields(leftReader);
  Fields rightFields = MultiFields.getFields(rightReader);
  // Fields could be null if there are no postings,
  // but then it must be null for both
  if (leftFields == null || rightFields == null) {
    assertNull(info, leftFields);
    assertNull(info, rightFields);
    return;
  }

  for (String field : leftFields) {
    NumericDocValues leftNorms = MultiDocValues.getNormValues(leftReader, field);
    NumericDocValues rightNorms = MultiDocValues.getNormValues(rightReader, field);
    if (leftNorms != null && rightNorms != null) {
      assertDocValuesEquals(info, leftReader.maxDoc(), leftNorms, rightNorms);
    } else {
      assertNull(info, leftNorms);
      assertNull(info, rightNorms);
    }
  }
}
项目:elasticsearch_my    文件:HasChildQueryBuilder.java   
@Override
public Query rewrite(IndexReader reader) throws IOException {
    Query rewritten = super.rewrite(reader);
    if (rewritten != this) {
        return rewritten;
    }
    if (reader instanceof DirectoryReader) {
        String joinField = ParentFieldMapper.joinField(parentType);
        IndexSearcher indexSearcher = new IndexSearcher(reader);
        indexSearcher.setQueryCache(null);
        indexSearcher.setSimilarity(similarity);
        IndexParentChildFieldData indexParentChildFieldData = parentChildIndexFieldData.loadGlobal((DirectoryReader) reader);
        MultiDocValues.OrdinalMap ordinalMap = ParentChildIndexFieldData.getOrdinalMap(indexParentChildFieldData, parentType);
        return JoinUtil.createJoinQuery(joinField, innerQuery, toQuery, indexSearcher, scoreMode,
                ordinalMap, minChildren, maxChildren);
    } else {
        if (reader.leaves().isEmpty() && reader.numDocs() == 0) {
            // asserting reader passes down a MultiReader during rewrite which makes this
            // blow up since for this query to work we have to have a DirectoryReader otherwise
            // we can't load global ordinals - for this to work we simply check if the reader has no leaves
            // and rewrite to match nothing
            return new MatchNoDocsQuery();
        }
        throw new IllegalStateException("can't load global ordinals for reader of type: " +
                reader.getClass() + " must be a DirectoryReader");
    }
}
项目:elasticsearch_my    文件:ParentChildIndexFieldData.java   
/**
 * Returns the global ordinal map for the specified type
 */
// TODO: OrdinalMap isn't expose in the field data framework, because it is an implementation detail.
// However the JoinUtil works directly with OrdinalMap, so this is a hack to get access to OrdinalMap
// I don't think we should expose OrdinalMap in IndexFieldData, because only parent/child relies on it and for the
// rest of the code OrdinalMap is an implementation detail, but maybe we can expose it in IndexParentChildFieldData interface?
public static MultiDocValues.OrdinalMap getOrdinalMap(IndexParentChildFieldData indexParentChildFieldData, String type) {
    if (indexParentChildFieldData instanceof ParentChildIndexFieldData.GlobalFieldData) {
        return ((GlobalFieldData) indexParentChildFieldData).ordinalMapPerType.get(type).ordMap;
    } else {
        // one segment, local ordinals are global
        return null;
    }
}
项目:search    文件:DocumentDictionary.java   
/**
 * Creates an iterator over term, weight and payload fields from the lucene
 * index. setting <code>withPayload</code> to false, implies an iterator
 * over only term and weight.
 */
public DocumentInputIterator(boolean hasPayloads, boolean hasContexts) throws IOException {
  this.hasPayloads = hasPayloads;
  this.hasContexts = hasContexts;
  docCount = reader.maxDoc() - 1;
  weightValues = (weightField != null) ? MultiDocValues.getNumericValues(reader, weightField) : null;
  liveDocs = (reader.leaves().size() > 0) ? MultiFields.getLiveDocs(reader) : null;
  relevantFields = getRelevantFields(new String [] {field, weightField, payloadField, contextsField});
}
项目:search    文件:TestOrdinalMappingAtomicReader.java   
private void verifyResults(Directory indexDir, Directory taxoDir) throws IOException {
  DirectoryReader indexReader = DirectoryReader.open(indexDir);
  DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
  IndexSearcher searcher = newSearcher(indexReader);

  FacetsCollector collector = new FacetsCollector();
  FacetsCollector.search(searcher, new MatchAllDocsQuery(), 10, collector);

  // tag facets
  Facets tagFacets = new FastTaxonomyFacetCounts("$tags", taxoReader, facetConfig, collector);
  FacetResult result = tagFacets.getTopChildren(10, "tag");
  for (LabelAndValue lv: result.labelValues) {
    if (VERBOSE) {
      System.out.println(lv);
    }
    assertEquals(NUM_DOCS, lv.value.intValue());
  }

  // id facets
  Facets idFacets = new FastTaxonomyFacetCounts(taxoReader, facetConfig, collector);
  FacetResult idResult = idFacets.getTopChildren(10, "id");
  assertEquals(NUM_DOCS, idResult.childCount);
  assertEquals(NUM_DOCS * 2, idResult.value); // each "id" appears twice

  BinaryDocValues bdv = MultiDocValues.getBinaryValues(indexReader, "bdv");
  BinaryDocValues cbdv = MultiDocValues.getBinaryValues(indexReader, "cbdv");
  for (int i = 0; i < indexReader.maxDoc(); i++) {
    assertEquals(Integer.parseInt(cbdv.get(i).utf8ToString()), Integer.parseInt(bdv.get(i).utf8ToString())*2);
  }
  IOUtils.close(indexReader, taxoReader);
}
项目:search    文件:SortingResponseWriter.java   
public StringValue(SortedDocValues vals, String field, IntComp comp)  {
  this.vals = vals;
  if(vals instanceof  MultiDocValues.MultiSortedDocValues) {
    this.segmentVals = ((MultiDocValues.MultiSortedDocValues) vals).values;
    this.ordinalMap = ((MultiDocValues.MultiSortedDocValues) vals).mapping;
  }
  this.field = field;
  this.comp = comp;
  this.currentOrd = comp.resetValue();
}
项目:read-open-source-code    文件:DocumentDictionary.java   
/**
 * Creates an iterator over term, weight and payload fields from the lucene
 * index. setting <code>withPayload</code> to false, implies an iterator
 * over only term and weight.
 */
public DocumentInputIterator(boolean hasPayloads) throws IOException {
  this.hasPayloads = hasPayloads;
  docCount = reader.maxDoc() - 1;
  weightValues = (weightField != null) ? MultiDocValues.getNumericValues(reader, weightField) : null;
  liveDocs = (reader.leaves().size() > 0) ? MultiFields.getLiveDocs(reader) : null;
  relevantFields = getRelevantFields(new String [] {field, weightField, payloadField});
}
项目:read-open-source-code    文件:DocumentDictionary.java   
/**
 * Creates an iterator over term, weight and payload fields from the lucene
 * index. setting <code>withPayload</code> to false, implies an iterator
 * over only term and weight.
 */
public DocumentInputIterator(boolean hasPayloads) throws IOException {
  this.hasPayloads = hasPayloads;
  docCount = reader.maxDoc() - 1;
  weightValues = (weightField != null) ? MultiDocValues.getNumericValues(reader, weightField) : null;
  liveDocs = (reader.leaves().size() > 0) ? MultiFields.getLiveDocs(reader) : null;
  relevantFields = getRelevantFields(new String [] {field, weightField, payloadField});
}
项目:read-open-source-code    文件:DocumentDictionary.java   
/**
 * Creates an iterator over term, weight and payload fields from the lucene
 * index. setting <code>withPayload</code> to false, implies an iterator
 * over only term and weight.
 */
public DocumentInputIterator(boolean hasPayloads, boolean hasContexts) throws IOException {
  this.hasPayloads = hasPayloads;
  this.hasContexts = hasContexts;
  docCount = reader.maxDoc() - 1;
  weightValues = (weightField != null) ? MultiDocValues.getNumericValues(reader, weightField) : null;
  liveDocs = (reader.leaves().size() > 0) ? MultiFields.getLiveDocs(reader) : null;
  relevantFields = getRelevantFields(new String [] {field, weightField, payloadField, contextsField});
}
项目:read-open-source-code    文件:SortingResponseWriter.java   
public StringValue(SortedDocValues vals, String field, IntComp comp)  {
  this.vals = vals;
  if(vals instanceof  MultiDocValues.MultiSortedDocValues) {
    this.segmentVals = ((MultiDocValues.MultiSortedDocValues) vals).values;
    this.ordinalMap = ((MultiDocValues.MultiSortedDocValues) vals).mapping;
  }
  this.field = field;
  this.comp = comp;
  this.currentOrd = comp.resetValue();
}