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


Java TaxonomyReader.INVALID_ORDINAL属性代码示例

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


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

示例1: computeChildrenSiblings

private void computeChildrenSiblings(int first) {
  // reset the youngest child of all ordinals. while this should be done only
  // for the leaves, we don't know up front which are the leaves, so we reset
  // all of them.
  for (int i = first; i < parents.length; i++) {
    children[i] = TaxonomyReader.INVALID_ORDINAL;
  }
  
  // the root category has no parent, and therefore no siblings
  if (first == 0) {
    first = 1;
    siblings[0] = TaxonomyReader.INVALID_ORDINAL;
  }
  
  for (int i = first; i < parents.length; i++) {
    // note that parents[i] is always < i, so the right-hand-side of
    // the following line is already set when we get here
    siblings[i] = children[parents[i]];
    children[parents[i]] = i;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:TaxonomyIndexArrays.java

示例2: internalAddCategory

/**
 * Add a new category into the index (and the cache), and return its new
 * ordinal.
 * <p>
 * Actually, we might also need to add some of the category's ancestors
 * before we can add the category itself (while keeping the invariant that a
 * parent is always added to the taxonomy before its child). We do this by
 * recursion.
 */
private int internalAddCategory(FacetLabel cp) throws IOException {
  // Find our parent's ordinal (recursively adding the parent category
  // to the taxonomy if it's not already there). Then add the parent
  // ordinal as payloads (rather than a stored field; payloads can be
  // more efficiently read into memory in bulk by LuceneTaxonomyReader)
  int parent;
  if (cp.length > 1) {
    FacetLabel parentPath = cp.subpath(cp.length - 1);
    parent = findCategory(parentPath);
    if (parent < 0) {
      parent = internalAddCategory(parentPath);
    }
  } else if (cp.length == 1) {
    parent = TaxonomyReader.ROOT_ORDINAL;
  } else {
    parent = TaxonomyReader.INVALID_ORDINAL;
  }
  int id = addCategoryDocument(cp, parent);

  return id;
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:DirectoryTaxonomyWriter.java

示例3: addSiblings

@Override
protected final int addSiblings(int ordinal, int[] siblings, PriorityQueue<FacetResultNode> pq) {
  FacetResultNode top = pq.top();
  int numResults = 0;
  while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    int value = values[ordinal];
    if (value > top.value) {
      top.value = value;
      top.ordinal = ordinal;
      top = pq.updateTop();
      ++numResults;
    }
    ordinal = siblings[ordinal];
  }
  return numResults;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:16,代码来源:IntFacetResultsHandler.java

示例4: fetchPartitionResult

@Override
public IntermediateFacetResult fetchPartitionResult(int offset)
throws IOException {
  TopKFacetResult res = null;
  int ordinal = taxonomyReader.getOrdinal(facetRequest.categoryPath);
  if (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    double value = 0;  
    if (isSelfPartition(ordinal, facetArrays, offset)) {
      int partitionSize = facetArrays.arrayLength;
      value = facetRequest.getValueOf(facetArrays, ordinal % partitionSize);
    }
    
    FacetResultNode parentResultNode = new FacetResultNode(ordinal, value);
    
    Heap<FacetResultNode> heap = ResultSortUtils.createSuitableHeap(facetRequest);
    int totalFacets = heapDescendants(ordinal, heap, parentResultNode, offset);
    res = new TopKFacetResult(facetRequest, parentResultNode, totalFacets);
    res.setHeap(heap);
  }
  return res;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:TopKFacetResultsHandler.java

示例5: addSiblings

@Override
protected final int addSiblings(int ordinal, int[] siblings, PriorityQueue<FacetResultNode> pq) {
  FacetResultNode top = pq.top();
  int numResults = 0;
  while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    float value = values[ordinal];
    if (value > top.value) {
      top.value = value;
      top.ordinal = ordinal;
      top = pq.updateTop();
      ++numResults;
    }
    ordinal = siblings[ordinal];
  }
  return numResults;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:16,代码来源:FloatFacetResultsHandler.java

示例6: internalAddCategory

/**
 * Add a new category into the index (and the cache), and return its new
 * ordinal.
 * <p>
 * Actually, we might also need to add some of the category's ancestors
 * before we can add the category itself (while keeping the invariant that a
 * parent is always added to the taxonomy before its child). We do this by
 * recursion.
 */
private int internalAddCategory(CategoryPath cp) throws IOException {
  // Find our parent's ordinal (recursively adding the parent category
  // to the taxonomy if it's not already there). Then add the parent
  // ordinal as payloads (rather than a stored field; payloads can be
  // more efficiently read into memory in bulk by LuceneTaxonomyReader)
  int parent;
  if (cp.length > 1) {
    CategoryPath parentPath = cp.subpath(cp.length - 1);
    parent = findCategory(parentPath);
    if (parent < 0) {
      parent = internalAddCategory(parentPath);
    }
  } else if (cp.length == 1) {
    parent = TaxonomyReader.ROOT_ORDINAL;
  } else {
    parent = TaxonomyReader.INVALID_ORDINAL;
  }
  int id = addCategoryDocument(cp, parent);

  return id;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:DirectoryTaxonomyWriter.java

示例7: TaxonomyIndexArrays

public TaxonomyIndexArrays(IndexReader reader) throws IOException {
  parents = new int[reader.maxDoc()];
  if (parents.length > 0) {
    initParents(reader, 0);
    // Starting Lucene 2.9, following the change LUCENE-1542, we can
    // no longer reliably read the parent "-1" (see comment in
    // LuceneTaxonomyWriter.SinglePositionTokenStream). We have no way
    // to fix this in indexing without breaking backward-compatibility
    // with existing indexes, so what we'll do instead is just
    // hard-code the parent of ordinal 0 to be -1, and assume (as is
    // indeed the case) that no other parent can be -1.
    parents[0] = TaxonomyReader.INVALID_ORDINAL;
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:TaxonomyIndexArrays.java

示例8: rollupValues

private float rollupValues(int ordinal, int[] children, int[] siblings, float[] scores) {
  float Value = 0f;
  while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    float childValue = scores[ordinal];
    childValue += rollupValues(children[ordinal], children, siblings, scores);
    scores[ordinal] = childValue;
    Value += childValue;
    ordinal = siblings[ordinal];
  }
  return Value;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:11,代码来源:SumFloatAssociationFacetsAggregator.java

示例9: rollupValues

private int rollupValues(int ordinal, int[] children, int[] siblings, int[] values) {
  int value = 0;
  while (ordinal != TaxonomyReader.INVALID_ORDINAL) {
    int childValue = values[ordinal];
    childValue += rollupValues(children[ordinal], children, siblings, values);
    values[ordinal] = childValue;
    value += childValue;
    ordinal = siblings[ordinal];
  }
  return value;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:11,代码来源:IntRollupFacetsAggregator.java

示例10: renderFacetResult

@Override
public FacetResult renderFacetResult(IntermediateFacetResult tmpResult) throws IOException {
  IntermediateFacetResultWithHash tmp = (IntermediateFacetResultWithHash) tmpResult;
  int ordinal = this.taxonomyReader.getOrdinal(this.facetRequest.categoryPath);
  if ((tmp == null) || (ordinal == TaxonomyReader.INVALID_ORDINAL)) {
    return null;
  }
  double value = Double.NaN;
  if (tmp.isRootNodeIncluded) {
    value = tmp.rootNodeValue;
  }
  FacetResultNode root = generateNode(ordinal, value, tmp.mapToAACOs);
  return new FacetResult (tmp.facetRequest, root, tmp.totalNumOfFacetsConsidered); 

}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:15,代码来源:TopKInEachNodeHandler.java

示例11: getOrdinal

@Override
public int getOrdinal(FacetLabel cp) throws IOException {
  ensureOpen();
  if (cp.length == 0) {
    return ROOT_ORDINAL;
  }

  // First try to find the answer in the LRU cache:
  synchronized (ordinalCache) {
    Integer res = ordinalCache.get(cp);
    if (res != null) {
      if (res.intValue() < indexReader.maxDoc()) {
        // Since the cache is shared with DTR instances allocated from
        // doOpenIfChanged, we need to ensure that the ordinal is one that
        // this DTR instance recognizes.
        return res.intValue();
      } else {
        // if we get here, it means that the category was found in the cache,
        // but is not recognized by this TR instance. Therefore there's no
        // need to continue search for the path on disk, because we won't find
        // it there too.
        return TaxonomyReader.INVALID_ORDINAL;
      }
    }
  }

  // If we're still here, we have a cache miss. We need to fetch the
  // value from disk, and then also put it in the cache:
  int ret = TaxonomyReader.INVALID_ORDINAL;
  DocsEnum docs = MultiFields.getTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(FacetsConfig.pathToString(cp.components, cp.length)), 0);
  if (docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
    ret = docs.docID();
    
    // we only store the fact that a category exists, not its inexistence.
    // This is required because the caches are shared with new DTR instances
    // that are allocated from doOpenIfChanged. Therefore, if we only store
    // information about found categories, we cannot accidently tell a new
    // generation of DTR that a category does not exist.
    synchronized (ordinalCache) {
      ordinalCache.put(cp, Integer.valueOf(ret));
    }
  }

  return ret;
}
 
开发者ID:europeana,项目名称:search,代码行数:45,代码来源:DirectoryTaxonomyReader.java

示例12: testGetChildren

@Test
public void testGetChildren() throws Exception {
  Directory dir = newDirectory();
  DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(dir);
  int numCategories = atLeast(10);
  int numA = 0, numB = 0;
  Random random = random();
  // add the two categories for which we'll also add children (so asserts are simpler)
  taxoWriter.addCategory(new FacetLabel("a"));
  taxoWriter.addCategory(new FacetLabel("b"));
  for (int i = 0; i < numCategories; i++) {
    if (random.nextBoolean()) {
      taxoWriter.addCategory(new FacetLabel("a", Integer.toString(i)));
      ++numA;
    } else {
      taxoWriter.addCategory(new FacetLabel("b", Integer.toString(i)));
      ++numB;
    }
  }
  // add category with no children
  taxoWriter.addCategory(new FacetLabel("c"));
  taxoWriter.close();
  
  DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir);

  // non existing category
  ChildrenIterator it = taxoReader.getChildren(taxoReader.getOrdinal(new FacetLabel("invalid")));
  assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());

  // a category with no children
  it = taxoReader.getChildren(taxoReader.getOrdinal(new FacetLabel("c")));
  assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());

  // arbitrary negative ordinal
  it = taxoReader.getChildren(-2);
  assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());

  // root's children
  Set<String> roots = new HashSet<>(Arrays.asList("a", "b", "c"));
  it = taxoReader.getChildren(TaxonomyReader.ROOT_ORDINAL);
  while (!roots.isEmpty()) {
    FacetLabel root = taxoReader.getPath(it.next());
    assertEquals(1, root.length);
    assertTrue(roots.remove(root.components[0]));
  }
  assertEquals(TaxonomyReader.INVALID_ORDINAL, it.next());
  
  for (int i = 0; i < 2; i++) {
    FacetLabel cp = i == 0 ? new FacetLabel("a") : new FacetLabel("b");
    int ordinal = taxoReader.getOrdinal(cp);
    it = taxoReader.getChildren(ordinal);
    int numChildren = 0;
    int child;
    while ((child = it.next()) != TaxonomyReader.INVALID_ORDINAL) {
      FacetLabel path = taxoReader.getPath(child);
      assertEquals(2, path.length);
      assertEquals(path.components[0], i == 0 ? "a" : "b");
      ++numChildren;
    }
    int expected = i == 0 ? numA : numB;
    assertEquals("invalid num children", expected, numChildren);
  }
  taxoReader.close();
  
  dir.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:66,代码来源:TestDirectoryTaxonomyReader.java

示例13: getOrdinal

@Override
public int getOrdinal(CategoryPath cp) throws IOException {
  ensureOpen();
  if (cp.length == 0) {
    return ROOT_ORDINAL;
  }

  // First try to find the answer in the LRU cache:
  synchronized (ordinalCache) {
    Integer res = ordinalCache.get(cp);
    if (res != null) {
      if (res.intValue() < indexReader.maxDoc()) {
        // Since the cache is shared with DTR instances allocated from
        // doOpenIfChanged, we need to ensure that the ordinal is one that
        // this DTR instance recognizes.
        return res.intValue();
      } else {
        // if we get here, it means that the category was found in the cache,
        // but is not recognized by this TR instance. Therefore there's no
        // need to continue search for the path on disk, because we won't find
        // it there too.
        return TaxonomyReader.INVALID_ORDINAL;
      }
    }
  }

  // If we're still here, we have a cache miss. We need to fetch the
  // value from disk, and then also put it in the cache:
  int ret = TaxonomyReader.INVALID_ORDINAL;
  DocsEnum docs = MultiFields.getTermDocsEnum(indexReader, null, Consts.FULL, new BytesRef(cp.toString(delimiter)), 0);
  if (docs != null && docs.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
    ret = docs.docID();
    
    // we only store the fact that a category exists, not its inexistence.
    // This is required because the caches are shared with new DTR instances
    // that are allocated from doOpenIfChanged. Therefore, if we only store
    // information about found categories, we cannot accidently tell a new
    // generation of DTR that a category does not exist.
    synchronized (ordinalCache) {
      ordinalCache.put(cp, Integer.valueOf(ret));
    }
  }

  return ret;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:45,代码来源:DirectoryTaxonomyReader.java


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