• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SeekStatus类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.lucene.index.TermsEnum.SeekStatus的典型用法代码示例。如果您正苦于以下问题:Java SeekStatus类的具体用法?Java SeekStatus怎么用?Java SeekStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SeekStatus类属于org.apache.lucene.index.TermsEnum包,在下文中一共展示了SeekStatus类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testSeeking

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
/** seeks to every term accepted by some automata */
public void testSeeking() throws Exception {
  for (int i = 0; i < numIterations; i++) {
    String reg = AutomatonTestUtil.randomRegexp(random());
    Automaton automaton = Operations.determinize(new RegExp(reg, RegExp.NONE).toAutomaton(),
      DEFAULT_MAX_DETERMINIZED_STATES);
    TermsEnum te = MultiFields.getTerms(reader, "field").iterator(null);
    ArrayList<BytesRef> unsortedTerms = new ArrayList<>(terms);
    Collections.shuffle(unsortedTerms, random());

    for (BytesRef term : unsortedTerms) {
      if (Operations.run(automaton, term.utf8ToString())) {
        // term is accepted
        if (random().nextBoolean()) {
          // seek exact
          assertTrue(te.seekExact(term));
        } else {
          // seek ceil
          assertEquals(SeekStatus.FOUND, te.seekCeil(term));
          assertEquals(term, te.term());
        }
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestTermsEnum2.java


示例2: testSeekingAndNexting

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
/** mixes up seek and next for all terms */
public void testSeekingAndNexting() throws Exception {
  for (int i = 0; i < numIterations; i++) {
    TermsEnum te = MultiFields.getTerms(reader, "field").iterator(null);

    for (BytesRef term : terms) {
      int c = random().nextInt(3);
      if (c == 0) {
        assertEquals(term, te.next());
      } else if (c == 1) {
        assertEquals(SeekStatus.FOUND, te.seekCeil(term));
        assertEquals(term, te.term());
      } else {
        assertTrue(te.seekExact(term));
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestTermsEnum2.java


示例3: testSeeking

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
/** seeks to every term accepted by some automata */
public void testSeeking() throws Exception {
  for (int i = 0; i < numIterations; i++) {
    String reg = AutomatonTestUtil.randomRegexp(random());
    Automaton automaton = new RegExp(reg, RegExp.NONE).toAutomaton();
    TermsEnum te = MultiFields.getTerms(reader, "field").iterator(null);
    ArrayList<BytesRef> unsortedTerms = new ArrayList<BytesRef>(terms);
    Collections.shuffle(unsortedTerms, random());

    for (BytesRef term : unsortedTerms) {
      if (BasicOperations.run(automaton, term.utf8ToString())) {
        // term is accepted
        if (random().nextBoolean()) {
          // seek exact
          assertTrue(te.seekExact(term, random().nextBoolean()));
        } else {
          // seek ceil
          assertEquals(SeekStatus.FOUND, te.seekCeil(term, random().nextBoolean()));
          assertEquals(term, te.term());
        }
      }
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:TestTermsEnum2.java


示例4: testSeekingAndNexting

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
/** mixes up seek and next for all terms */
public void testSeekingAndNexting() throws Exception {
  for (int i = 0; i < numIterations; i++) {
    TermsEnum te = MultiFields.getTerms(reader, "field").iterator(null);

    for (BytesRef term : terms) {
      int c = random().nextInt(3);
      if (c == 0) {
        assertEquals(term, te.next());
      } else if (c == 1) {
        assertEquals(SeekStatus.FOUND, te.seekCeil(term, random().nextBoolean()));
        assertEquals(term, te.term());
      } else {
        assertTrue(te.seekExact(term, random().nextBoolean()));
      }
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:19,代码来源:TestTermsEnum2.java


示例5: testSeeking

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
/** seeks to every term accepted by some automata */
public void testSeeking() throws Exception {
  for (int i = 0; i < numIterations; i++) {
    String reg = AutomatonTestUtil.randomRegexp(random());
    Automaton automaton = new RegExp(reg, RegExp.NONE).toAutomaton();
    TermsEnum te = MultiFields.getTerms(reader, "field").iterator(null);
    ArrayList<BytesRef> unsortedTerms = new ArrayList<BytesRef>(terms);
    Collections.shuffle(unsortedTerms, random());

    for (BytesRef term : unsortedTerms) {
      if (BasicOperations.run(automaton, term.utf8ToString())) {
        // term is accepted
        if (random().nextBoolean()) {
          // seek exact
          assertTrue(te.seekExact(term));
        } else {
          // seek ceil
          assertEquals(SeekStatus.FOUND, te.seekCeil(term));
          assertEquals(term, te.term());
        }
      }
    }
  }
}
 
开发者ID:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:25,代码来源:TestTermsEnum2.java


示例6: lookupTerm

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
long lookupTerm(BytesRef key) {
  try {
    SeekStatus status = termsEnum.seekCeil(key);
    if (status == SeekStatus.END) {
      return -numValues-1;
    } else if (status == SeekStatus.FOUND) {
      return termsEnum.ord();
    } else {
      return -termsEnum.ord()-1;
    }
  } catch (IOException bogus) {
    throw new RuntimeException(bogus);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:Lucene45DocValuesProducer.java


示例7: testDocsEnum

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
@Test
public void testDocsEnum() throws Exception {
  Bits mappedLiveDocs = randomLiveDocs(reader.maxDoc());
  TermsEnum termsEnum = reader.terms(DOCS_ENUM_FIELD).iterator(null);
  assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef(DOCS_ENUM_TERM)));
  DocsEnum docs = termsEnum.docs(mappedLiveDocs, null);

  int doc;
  int prev = -1;
  while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    assertTrue("document " + doc + " marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(doc));
    assertEquals("incorrect value; doc " + doc, sortedValues[doc].intValue(), Integer.parseInt(reader.document(doc).get(ID_FIELD)));
    while (++prev < doc) {
      assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
    }
  }
  while (++prev < reader.maxDoc()) {
    assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
  }

  DocsEnum reuse = docs;
  docs = termsEnum.docs(mappedLiveDocs, reuse);
  if (docs instanceof SortingDocsEnum) {
    assertTrue(((SortingDocsEnum) docs).reused(reuse)); // make sure reuse worked
  }
  doc = -1;
  prev = -1;
  while ((doc = docs.advance(doc + 1)) != DocIdSetIterator.NO_MORE_DOCS) {
    assertTrue("document " + doc + " marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(doc));
    assertEquals("incorrect value; doc " + doc, sortedValues[doc].intValue(), Integer.parseInt(reader.document(doc).get(ID_FIELD)));
    while (++prev < doc) {
      assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
    }
  }
  while (++prev < reader.maxDoc()) {
    assertFalse("document " + prev + " not marked as deleted", mappedLiveDocs == null || mappedLiveDocs.get(prev));
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:SorterTestBase.java


示例8: lookupTerm

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
@Override
public long lookupTerm(BytesRef key) {
  try {
    if (te.seekCeil(key) == SeekStatus.FOUND) {
      return te.ord();
    } else {
      return -te.ord()-1;
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:13,代码来源:DocTermOrds.java


示例9: getTermWithSeekCount

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
private int getTermWithSeekCount(Fields fields, String field) throws IOException {
  Terms terms = fields.terms(field);
  TermsEnum termsEnum = terms.iterator(null);
  SeekStatus seekStatus = termsEnum.seekCeil(new BytesRef(""));
  if (seekStatus == SeekStatus.END) {
    return 0;
  }
  System.out.println(termsEnum.term().utf8ToString());
  int count = 1;
  while (termsEnum.next() != null) {
    count++;
  }
  return count;
}
 
开发者ID:apache,项目名称:incubator-blur,代码行数:15,代码来源:SecureAtomicReaderTestBase.java


示例10: scanToTerm

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
public SeekStatus scanToTerm(BytesRef target, boolean exactOnly) throws IOException {
  return isLeafBlock ? scanToTermLeaf(target, exactOnly) : scanToTermNonLeaf(target, exactOnly);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:4,代码来源:SegmentTermsEnumFrame.java


示例11: seekCeil

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
@Override
public SeekStatus seekCeil(BytesRef target) throws IOException {

  // already here
  if (term != null && term.equals(target)) {
    return SeekStatus.FOUND;
  }

  int startIdx = Arrays.binarySearch(indexedTermsArray, target);

  if (startIdx >= 0) {
    // we hit the term exactly... lucky us!
    TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(target);
    assert seekStatus == TermsEnum.SeekStatus.FOUND;
    ord = startIdx << indexIntervalBits;
    setTerm();
    assert term != null;
    return SeekStatus.FOUND;
  }

  // we didn't hit the term exactly
  startIdx = -startIdx-1;

  if (startIdx == 0) {
    // our target occurs *before* the first term
    TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(target);
    assert seekStatus == TermsEnum.SeekStatus.NOT_FOUND;
    ord = 0;
    setTerm();
    assert term != null;
    return SeekStatus.NOT_FOUND;
  }

  // back up to the start of the block
  startIdx--;

  if ((ord >> indexIntervalBits) == startIdx && term != null && term.compareTo(target) <= 0) {
    // we are already in the right block and the current term is before the term we want,
    // so we don't need to seek.
  } else {
    // seek to the right block
    TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(indexedTermsArray[startIdx]);
    assert seekStatus == TermsEnum.SeekStatus.FOUND;
    ord = startIdx << indexIntervalBits;
    setTerm();
    assert term != null;  // should be non-null since it's in the index
  }

  while (term != null && term.compareTo(target) < 0) {
    next();
  }

  if (term == null) {
    return SeekStatus.END;
  } else if (term.compareTo(target) == 0) {
    return SeekStatus.FOUND;
  } else {
    return SeekStatus.NOT_FOUND;
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:61,代码来源:DocTermOrds.java


示例12: testSortedTermsEnum

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
public void testSortedTermsEnum() throws IOException {
  Directory directory = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
  iwconfig.setMergePolicy(newLogMergePolicy());
  RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
  
  Document doc = new Document();
  doc.add(new SortedDocValuesField("field", new BytesRef("hello")));
  iwriter.addDocument(doc);
  
  doc = new Document();
  doc.add(new SortedDocValuesField("field", new BytesRef("world")));
  iwriter.addDocument(doc);

  doc = new Document();
  doc.add(new SortedDocValuesField("field", new BytesRef("beer")));
  iwriter.addDocument(doc);
  iwriter.forceMerge(1);
  
  DirectoryReader ireader = iwriter.getReader();
  iwriter.close();

  SortedDocValues dv = getOnlySegmentReader(ireader).getSortedDocValues("field");
  assertEquals(3, dv.getValueCount());
  
  TermsEnum termsEnum = dv.termsEnum();
  
  // next()
  assertEquals("beer", termsEnum.next().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals("hello", termsEnum.next().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals("world", termsEnum.next().utf8ToString());
  assertEquals(2, termsEnum.ord());
  
  // seekCeil()
  assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(new BytesRef("ha!")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals(SeekStatus.END, termsEnum.seekCeil(new BytesRef("zzz")));
  assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(new BytesRef("aba")));
  assertEquals(0, termsEnum.ord());
  
  // seekExact()
  assertTrue(termsEnum.seekExact(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("hello")));
  assertEquals(Codec.getDefault().toString(), "hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("world")));
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  assertFalse(termsEnum.seekExact(new BytesRef("bogus")));

  // seek(ord)
  termsEnum.seekExact(0);
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  termsEnum.seekExact(1);
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  termsEnum.seekExact(2);
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  ireader.close();
  directory.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:73,代码来源:BaseDocValuesFormatTestCase.java


示例13: testSortedSetTermsEnum

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
public void testSortedSetTermsEnum() throws IOException {
  assumeTrue("Codec does not support SORTED_SET", defaultCodecSupportsSortedSet());
  Directory directory = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
  iwconfig.setMergePolicy(newLogMergePolicy());
  RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
  
  Document doc = new Document();
  doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
  doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
  doc.add(new SortedSetDocValuesField("field", new BytesRef("beer")));
  iwriter.addDocument(doc);
  
  DirectoryReader ireader = iwriter.getReader();
  iwriter.close();

  SortedSetDocValues dv = getOnlySegmentReader(ireader).getSortedSetDocValues("field");
  assertEquals(3, dv.getValueCount());
  
  TermsEnum termsEnum = dv.termsEnum();
  
  // next()
  assertEquals("beer", termsEnum.next().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals("hello", termsEnum.next().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals("world", termsEnum.next().utf8ToString());
  assertEquals(2, termsEnum.ord());
  
  // seekCeil()
  assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(new BytesRef("ha!")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals(SeekStatus.END, termsEnum.seekCeil(new BytesRef("zzz")));
  
  // seekExact()
  assertTrue(termsEnum.seekExact(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("hello")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("world")));
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  assertFalse(termsEnum.seekExact(new BytesRef("bogus")));

  // seek(ord)
  termsEnum.seekExact(0);
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  termsEnum.seekExact(1);
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  termsEnum.seekExact(2);
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  ireader.close();
  directory.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:65,代码来源:BaseDocValuesFormatTestCase.java


示例14: assertTermsSeekingEquals

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
private void assertTermsSeekingEquals(String info, Terms leftTerms, Terms rightTerms) throws IOException {
  TermsEnum leftEnum = null;
  TermsEnum rightEnum = null;

  // just an upper bound
  int numTests = atLeast(20);
  Random random = random();

  // collect this number of terms from the left side
  HashSet<BytesRef> tests = new HashSet<>();
  int numPasses = 0;
  while (numPasses < 10 && tests.size() < numTests) {
    leftEnum = leftTerms.iterator(leftEnum);
    BytesRef term = null;
    while ((term = leftEnum.next()) != null) {
      int code = random.nextInt(10);
      if (code == 0) {
        // the term
        tests.add(BytesRef.deepCopyOf(term));
      } else if (code == 1) {
        // truncated subsequence of term
        term = BytesRef.deepCopyOf(term);
        if (term.length > 0) {
          // truncate it
          term.length = random.nextInt(term.length);
        }
      } else if (code == 2) {
        // term, but ensure a non-zero offset
        byte newbytes[] = new byte[term.length+5];
        System.arraycopy(term.bytes, term.offset, newbytes, 5, term.length);
        tests.add(new BytesRef(newbytes, 5, term.length));
      } else if (code == 3) {
        switch (random().nextInt(3)) {
          case 0:
            tests.add(new BytesRef()); // before the first term
            break;
          case 1:
            tests.add(new BytesRef(new byte[] {(byte) 0xFF, (byte) 0xFF})); // past the last term
            break;
          case 2:
            tests.add(new BytesRef(TestUtil.randomSimpleString(random()))); // random term
            break;
          default:
            throw new AssertionError();
        }
      }
    }
    numPasses++;
  }

  rightEnum = rightTerms.iterator(rightEnum);

  ArrayList<BytesRef> shuffledTests = new ArrayList<>(tests);
  Collections.shuffle(shuffledTests, random);

  for (BytesRef b : shuffledTests) {
    if (rarely()) {
      // reuse the enums
      leftEnum = leftTerms.iterator(leftEnum);
      rightEnum = rightTerms.iterator(rightEnum);
    }

    final boolean seekExact = random().nextBoolean();

    if (seekExact) {
      assertEquals(info, leftEnum.seekExact(b), rightEnum.seekExact(b));
    } else {
      SeekStatus leftStatus = leftEnum.seekCeil(b);
      SeekStatus rightStatus = rightEnum.seekCeil(b);
      assertEquals(info, leftStatus, rightStatus);
      if (leftStatus != SeekStatus.END) {
        assertEquals(info, leftEnum.term(), rightEnum.term());
        assertTermStatsEquals(info, leftEnum, rightEnum);
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:78,代码来源:LuceneTestCase.java


示例15: assertTermsSeeking

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
private void assertTermsSeeking(Terms leftTerms, Terms rightTerms) throws Exception {
  TermsEnum leftEnum = null;
  TermsEnum rightEnum = null;
  
  // just an upper bound
  int numTests = atLeast(20);
  Random random = random();
  
  // collect this number of terms from the left side
  HashSet<BytesRef> tests = new HashSet<>();
  int numPasses = 0;
  while (numPasses < 10 && tests.size() < numTests) {
    leftEnum = leftTerms.iterator(leftEnum);
    BytesRef term = null;
    while ((term = leftEnum.next()) != null) {
      int code = random.nextInt(10);
      if (code == 0) {
        // the term
        tests.add(BytesRef.deepCopyOf(term));
      } else if (code == 1) {
        // truncated subsequence of term
        term = BytesRef.deepCopyOf(term);
        if (term.length > 0) {
          // truncate it
          term.length = random.nextInt(term.length);
        }
      } else if (code == 2) {
        // term, but ensure a non-zero offset
        byte newbytes[] = new byte[term.length+5];
        System.arraycopy(term.bytes, term.offset, newbytes, 5, term.length);
        tests.add(new BytesRef(newbytes, 5, term.length));
      }
    }
    numPasses++;
  }
  
  ArrayList<BytesRef> shuffledTests = new ArrayList<>(tests);
  Collections.shuffle(shuffledTests, random);
  
  for (BytesRef b : shuffledTests) {
    leftEnum = leftTerms.iterator(leftEnum);
    rightEnum = rightTerms.iterator(rightEnum);
    
    assertEquals(leftEnum.seekExact(b), rightEnum.seekExact(b));
    assertEquals(leftEnum.seekExact(b), rightEnum.seekExact(b));
    
    SeekStatus leftStatus;
    SeekStatus rightStatus;
    
    leftStatus = leftEnum.seekCeil(b);
    rightStatus = rightEnum.seekCeil(b);
    assertEquals(leftStatus, rightStatus);
    if (leftStatus != SeekStatus.END) {
      assertEquals(leftEnum.term(), rightEnum.term());
    }
    
    leftStatus = leftEnum.seekCeil(b);
    rightStatus = rightEnum.seekCeil(b);
    assertEquals(leftStatus, rightStatus);
    if (leftStatus != SeekStatus.END) {
      assertEquals(leftEnum.term(), rightEnum.term());
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:65,代码来源:TestBlockPostingsFormat3.java


示例16: testSortedTermsEnum

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
public void testSortedTermsEnum() throws IOException {
  Directory directory = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriterConfig iwconfig = newIndexWriterConfig(analyzer);
  iwconfig.setMergePolicy(newLogMergePolicy());
  RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
  
  Document doc = new Document();
  doc.add(new StringField("field", "hello", Field.Store.NO));
  iwriter.addDocument(doc);
  
  doc = new Document();
  doc.add(new StringField("field", "world", Field.Store.NO));
  iwriter.addDocument(doc);

  doc = new Document();
  doc.add(new StringField("field", "beer", Field.Store.NO));
  iwriter.addDocument(doc);
  iwriter.forceMerge(1);
  
  DirectoryReader ireader = iwriter.getReader();
  iwriter.close();

  AtomicReader ar = getOnlySegmentReader(ireader);
  SortedSetDocValues dv = FieldCache.DEFAULT.getDocTermOrds(ar, "field");
  assertEquals(3, dv.getValueCount());
  
  TermsEnum termsEnum = dv.termsEnum();
  
  // next()
  assertEquals("beer", termsEnum.next().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals("hello", termsEnum.next().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals("world", termsEnum.next().utf8ToString());
  assertEquals(2, termsEnum.ord());
  
  // seekCeil()
  assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(new BytesRef("ha!")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals(SeekStatus.END, termsEnum.seekCeil(new BytesRef("zzz")));
  
  // seekExact()
  assertTrue(termsEnum.seekExact(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("hello")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("world")));
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  assertFalse(termsEnum.seekExact(new BytesRef("bogus")));
  
  // seek(ord)
  termsEnum.seekExact(0);
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  termsEnum.seekExact(1);
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  termsEnum.seekExact(2);
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  
  // lookupTerm(BytesRef) 
  assertEquals(-1, dv.lookupTerm(new BytesRef("apple")));
  assertEquals(0, dv.lookupTerm(new BytesRef("beer")));
  assertEquals(-2, dv.lookupTerm(new BytesRef("car")));
  assertEquals(1, dv.lookupTerm(new BytesRef("hello")));
  assertEquals(-3, dv.lookupTerm(new BytesRef("matter")));
  assertEquals(2, dv.lookupTerm(new BytesRef("world")));
  assertEquals(-4, dv.lookupTerm(new BytesRef("zany")));

  ireader.close();
  directory.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:82,代码来源:TestDocTermOrds.java


示例17: testSortedTermsEnum

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
public void testSortedTermsEnum() throws IOException {
  Directory directory = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriterConfig iwconfig = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
  iwconfig.setMergePolicy(newLogMergePolicy());
  RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
  
  Document doc = new Document();
  doc.add(new SortedDocValuesField("field", new BytesRef("hello")));
  iwriter.addDocument(doc);
  
  doc = new Document();
  doc.add(new SortedDocValuesField("field", new BytesRef("world")));
  iwriter.addDocument(doc);

  doc = new Document();
  doc.add(new SortedDocValuesField("field", new BytesRef("beer")));
  iwriter.addDocument(doc);
  iwriter.forceMerge(1);
  
  DirectoryReader ireader = iwriter.getReader();
  iwriter.close();

  SortedDocValues dv = getOnlySegmentReader(ireader).getSortedDocValues("field");
  assertEquals(3, dv.getValueCount());
  
  TermsEnum termsEnum = dv.termsEnum();
  
  // next()
  assertEquals("beer", termsEnum.next().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals("hello", termsEnum.next().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals("world", termsEnum.next().utf8ToString());
  assertEquals(2, termsEnum.ord());
  
  // seekCeil()
  assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(new BytesRef("ha!")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals(SeekStatus.END, termsEnum.seekCeil(new BytesRef("zzz")));
  
  // seekExact()
  assertTrue(termsEnum.seekExact(new BytesRef("beer"), true));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("hello"), true));
  assertEquals(Codec.getDefault().toString(), "hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("world"), true));
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  assertFalse(termsEnum.seekExact(new BytesRef("bogus"), true));

  // seek(ord)
  termsEnum.seekExact(0);
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  termsEnum.seekExact(1);
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  termsEnum.seekExact(2);
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  ireader.close();
  directory.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:71,代码来源:BaseDocValuesFormatTestCase.java


示例18: testSortedSetTermsEnum

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
public void testSortedSetTermsEnum() throws IOException {
  assumeTrue("Codec does not support SORTED_SET", defaultCodecSupportsSortedSet());
  Directory directory = newDirectory();
  Analyzer analyzer = new MockAnalyzer(random());
  IndexWriterConfig iwconfig = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
  iwconfig.setMergePolicy(newLogMergePolicy());
  RandomIndexWriter iwriter = new RandomIndexWriter(random(), directory, iwconfig);
  
  Document doc = new Document();
  doc.add(new SortedSetDocValuesField("field", new BytesRef("hello")));
  doc.add(new SortedSetDocValuesField("field", new BytesRef("world")));
  doc.add(new SortedSetDocValuesField("field", new BytesRef("beer")));
  iwriter.addDocument(doc);
  
  DirectoryReader ireader = iwriter.getReader();
  iwriter.close();

  SortedSetDocValues dv = getOnlySegmentReader(ireader).getSortedSetDocValues("field");
  assertEquals(3, dv.getValueCount());
  
  TermsEnum termsEnum = dv.termsEnum();
  
  // next()
  assertEquals("beer", termsEnum.next().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals("hello", termsEnum.next().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals("world", termsEnum.next().utf8ToString());
  assertEquals(2, termsEnum.ord());
  
  // seekCeil()
  assertEquals(SeekStatus.NOT_FOUND, termsEnum.seekCeil(new BytesRef("ha!")));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertEquals(SeekStatus.FOUND, termsEnum.seekCeil(new BytesRef("beer")));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertEquals(SeekStatus.END, termsEnum.seekCeil(new BytesRef("zzz")));
  
  // seekExact()
  assertTrue(termsEnum.seekExact(new BytesRef("beer"), true));
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("hello"), true));
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  assertTrue(termsEnum.seekExact(new BytesRef("world"), true));
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  assertFalse(termsEnum.seekExact(new BytesRef("bogus"), true));

  // seek(ord)
  termsEnum.seekExact(0);
  assertEquals("beer", termsEnum.term().utf8ToString());
  assertEquals(0, termsEnum.ord());
  termsEnum.seekExact(1);
  assertEquals("hello", termsEnum.term().utf8ToString());
  assertEquals(1, termsEnum.ord());
  termsEnum.seekExact(2);
  assertEquals("world", termsEnum.term().utf8ToString());
  assertEquals(2, termsEnum.ord());
  ireader.close();
  directory.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:65,代码来源:BaseDocValuesFormatTestCase.java


示例19: seekCeil

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
@Override
public SeekStatus seekCeil(BytesRef target, boolean useCache) throws IOException {

  // already here
  if (term != null && term.equals(target)) {
    return SeekStatus.FOUND;
  }

  int startIdx = Arrays.binarySearch(indexedTermsArray, target);

  if (startIdx >= 0) {
    // we hit the term exactly... lucky us!
    TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(target);
    assert seekStatus == TermsEnum.SeekStatus.FOUND;
    ord = startIdx << indexIntervalBits;
    setTerm();
    assert term != null;
    return SeekStatus.FOUND;
  }

  // we didn't hit the term exactly
  startIdx = -startIdx-1;

  if (startIdx == 0) {
    // our target occurs *before* the first term
    TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(target);
    assert seekStatus == TermsEnum.SeekStatus.NOT_FOUND;
    ord = 0;
    setTerm();
    assert term != null;
    return SeekStatus.NOT_FOUND;
  }

  // back up to the start of the block
  startIdx--;

  if ((ord >> indexIntervalBits) == startIdx && term != null && term.compareTo(target) <= 0) {
    // we are already in the right block and the current term is before the term we want,
    // so we don't need to seek.
  } else {
    // seek to the right block
    TermsEnum.SeekStatus seekStatus = termsEnum.seekCeil(indexedTermsArray[startIdx]);
    assert seekStatus == TermsEnum.SeekStatus.FOUND;
    ord = startIdx << indexIntervalBits;
    setTerm();
    assert term != null;  // should be non-null since it's in the index
  }

  while (term != null && term.compareTo(target) < 0) {
    next();
  }

  if (term == null) {
    return SeekStatus.END;
  } else if (term.compareTo(target) == 0) {
    return SeekStatus.FOUND;
  } else {
    return SeekStatus.NOT_FOUND;
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:61,代码来源:DocTermOrds.java


示例20: assertTermsSeeking

import org.apache.lucene.index.TermsEnum.SeekStatus; //导入依赖的package包/类
private void assertTermsSeeking(Terms leftTerms, Terms rightTerms) throws Exception {
  TermsEnum leftEnum = null;
  TermsEnum rightEnum = null;
  
  // just an upper bound
  int numTests = atLeast(20);
  Random random = random();
  
  // collect this number of terms from the left side
  HashSet<BytesRef> tests = new HashSet<BytesRef>();
  int numPasses = 0;
  while (numPasses < 10 && tests.size() < numTests) {
    leftEnum = leftTerms.iterator(leftEnum);
    BytesRef term = null;
    while ((term = leftEnum.next()) != null) {
      int code = random.nextInt(10);
      if (code == 0) {
        // the term
        tests.add(BytesRef.deepCopyOf(term));
      } else if (code == 1) {
        // truncated subsequence of term
        term = BytesRef.deepCopyOf(term);
        if (term.length > 0) {
          // truncate it
          term.length = random.nextInt(term.length);
        }
      } else if (code == 2) {
        // term, but ensure a non-zero offset
        byte newbytes[] = new byte[term.length+5];
        System.arraycopy(term.bytes, term.offset, newbytes, 5, term.length);
        tests.add(new BytesRef(newbytes, 5, term.length));
      }
    }
    numPasses++;
  }
  
  ArrayList<BytesRef> shuffledTests = new ArrayList<BytesRef>(tests);
  Collections.shuffle(shuffledTests, random);
  
  for (BytesRef b : shuffledTests) {
    leftEnum = leftTerms.iterator(leftEnum);
    rightEnum = rightTerms.iterator(rightEnum);
    
    assertEquals(leftEnum.seekExact(b, false), rightEnum.seekExact(b, false));
    assertEquals(leftEnum.seekExact(b, true), rightEnum.seekExact(b, true));
    
    SeekStatus leftStatus;
    SeekStatus rightStatus;
    
    leftStatus = leftEnum.seekCeil(b, false);
    rightStatus = rightEnum.seekCeil(b, false);
    assertEquals(leftStatus, rightStatus);
    if (leftStatus != SeekStatus.END) {
      assertEquals(leftEnum.term(), rightEnum.term());
    }
    
    leftStatus = leftEnum.seekCeil(b, true);
    rightStatus = rightEnum.seekCeil(b, true);
    assertEquals(leftStatus, rightStatus);
    if (leftStatus != SeekStatus.END) {
      assertEquals(leftEnum.term(), rightEnum.term());
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:65,代码来源:TestBlockPostingsFormat3.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SentPacket类代码示例发布时间:2022-05-23
下一篇:
Java StreamSourceFrameChannel类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap