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


Java FacetsConfig.stringToPath方法代码示例

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


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

示例1: addTaxonomy

import org.apache.lucene.facet.FacetsConfig; //导入方法依赖的package包/类
/**
 * Takes the categories from the given taxonomy directory, and adds the
 * missing ones to this taxonomy. Additionally, it fills the given
 * {@link OrdinalMap} with a mapping from the original ordinal to the new
 * ordinal.
 */
public void addTaxonomy(Directory taxoDir, OrdinalMap map) throws IOException {
  ensureOpen();
  DirectoryReader r = DirectoryReader.open(taxoDir);
  try {
    final int size = r.numDocs();
    final OrdinalMap ordinalMap = map;
    ordinalMap.setSize(size);
    int base = 0;
    TermsEnum te = null;
    DocsEnum docs = null;
    for (final AtomicReaderContext ctx : r.leaves()) {
      final AtomicReader ar = ctx.reader();
      final Terms terms = ar.terms(Consts.FULL);
      te = terms.iterator(te);
      while (te.next() != null) {
        FacetLabel cp = new FacetLabel(FacetsConfig.stringToPath(te.term().utf8ToString()));
        final int ordinal = addCategory(cp);
        docs = te.docs(null, docs, DocsEnum.FLAG_NONE);
        ordinalMap.addMapping(docs.nextDoc() + base, ordinal);
      }
      base += ar.maxDoc(); // no deletions, so we're ok
    }
    ordinalMap.addDone();
  } finally {
    r.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:DirectoryTaxonomyWriter.java

示例2: getPath

import org.apache.lucene.facet.FacetsConfig; //导入方法依赖的package包/类
@Override
public FacetLabel getPath(int ordinal) throws IOException {
  ensureOpen();
  
  // 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. Therefore we do this check up front, before we hit
  // the cache.
  if (ordinal < 0 || ordinal >= indexReader.maxDoc()) {
    return null;
  }
  
  // TODO: can we use an int-based hash impl, such as IntToObjectMap,
  // wrapped as LRU?
  Integer catIDInteger = Integer.valueOf(ordinal);
  synchronized (categoryCache) {
    FacetLabel res = categoryCache.get(catIDInteger);
    if (res != null) {
      return res;
    }
  }
  
  Document doc = indexReader.document(ordinal);
  FacetLabel ret = new FacetLabel(FacetsConfig.stringToPath(doc.get(Consts.FULL)));
  synchronized (categoryCache) {
    categoryCache.put(catIDInteger, ret);
  }
  
  return ret;
}
 
开发者ID:europeana,项目名称:search,代码行数:31,代码来源:DirectoryTaxonomyReader.java

示例3: DefaultSortedSetDocValuesReaderState

import org.apache.lucene.facet.FacetsConfig; //导入方法依赖的package包/类
/** Creates this, pulling doc values from the specified
 *  field. */
public DefaultSortedSetDocValuesReaderState(IndexReader reader, String field) throws IOException {
  this.field = field;
  this.origReader = reader;

  // We need this to create thread-safe MultiSortedSetDV
  // per collector:
  topReader = SlowCompositeReaderWrapper.wrap(reader);
  SortedSetDocValues dv = topReader.getSortedSetDocValues(field);
  if (dv == null) {
    throw new IllegalArgumentException("field \"" + field + "\" was not indexed with SortedSetDocValues");
  }
  if (dv.getValueCount() > Integer.MAX_VALUE) {
    throw new IllegalArgumentException("can only handle valueCount < Integer.MAX_VALUE; got " + dv.getValueCount());
  }
  valueCount = (int) dv.getValueCount();

  // TODO: we can make this more efficient if eg we can be
  // "involved" when OrdinalMap is being created?  Ie see
  // each term/ord it's assigning as it goes...
  String lastDim = null;
  int startOrd = -1;

  // TODO: this approach can work for full hierarchy?;
  // TaxoReader can't do this since ords are not in
  // "sorted order" ... but we should generalize this to
  // support arbitrary hierarchy:
  for(int ord=0;ord<valueCount;ord++) {
    final BytesRef term = dv.lookupOrd(ord);
    String[] components = FacetsConfig.stringToPath(term.utf8ToString());
    if (components.length != 2) {
      throw new IllegalArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.toString(components) + " " + term.utf8ToString());
    }
    if (!components[0].equals(lastDim)) {
      if (lastDim != null) {
        prefixToOrdRange.put(lastDim, new OrdRange(startOrd, ord-1));
      }
      startOrd = ord;
      lastDim = components[0];
    }
  }

  if (lastDim != null) {
    prefixToOrdRange.put(lastDim, new OrdRange(startOrd, valueCount-1));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:48,代码来源:DefaultSortedSetDocValuesReaderState.java

示例4: DefaultSortedSetDocValuesReaderState

import org.apache.lucene.facet.FacetsConfig; //导入方法依赖的package包/类
/** Creates this, pulling doc values from the specified
 *  field. */
public DefaultSortedSetDocValuesReaderState(IndexReader reader, String field) throws IOException {
  this.field = field;
  this.origReader = reader;

  // We need this to create thread-safe MultiSortedSetDV
  // per collector:
  topReader = SlowCompositeReaderWrapper.wrap(reader);
  SortedSetDocValues dv = topReader.getSortedSetDocValues(field);
  if (dv == null) {
    throw new IllegalArgumentException("field \"" + field + "\" was not indexed with SortedSetDocValues");
  }
  if (dv.getValueCount() > Integer.MAX_VALUE) {
    throw new IllegalArgumentException("can only handle valueCount < Integer.MAX_VALUE; got " + dv.getValueCount());
  }
  valueCount = (int) dv.getValueCount();

  // TODO: we can make this more efficient if eg we can be
  // "involved" when OrdinalMap is being created?  Ie see
  // each term/ord it's assigning as it goes...
  String lastDim = null;
  int startOrd = -1;
  BytesRef spare = new BytesRef();

  // TODO: this approach can work for full hierarchy?;
  // TaxoReader can't do this since ords are not in
  // "sorted order" ... but we should generalize this to
  // support arbitrary hierarchy:
  for(int ord=0;ord<valueCount;ord++) {
    dv.lookupOrd(ord, spare);
    String[] components = FacetsConfig.stringToPath(spare.utf8ToString());
    if (components.length != 2) {
      throw new IllegalArgumentException("this class can only handle 2 level hierarchy (dim/value); got: " + Arrays.toString(components) + " " + spare.utf8ToString());
    }
    if (!components[0].equals(lastDim)) {
      if (lastDim != null) {
        prefixToOrdRange.put(lastDim, new OrdRange(startOrd, ord-1));
      }
      startOrd = ord;
      lastDim = components[0];
    }
  }

  if (lastDim != null) {
    prefixToOrdRange.put(lastDim, new OrdRange(startOrd, valueCount-1));
  }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:49,代码来源:DefaultSortedSetDocValuesReaderState.java


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