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


Java MultiSpansWrapper类代码示例

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


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

示例1: test

import org.apache.lucene.search.spans.MultiSpansWrapper; //导入依赖的package包/类
public void test() throws IOException {
  PayloadTermQuery query = new PayloadTermQuery(new Term("field", "seventy"),
          new MaxPayloadFunction());
  TopDocs hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);

  //they should all have the exact same score, because they all contain seventy once, and we set
  //all the other similarity factors to be 1

  assertTrue(hits.getMaxScore() + " does not equal: " + 1, hits.getMaxScore() == 1);
  for (int i = 0; i < hits.scoreDocs.length; i++) {
    ScoreDoc doc = hits.scoreDocs[i];
    assertTrue(doc.score + " does not equal: " + 1, doc.score == 1);
  }
  CheckHits.checkExplanations(query, PayloadHelper.FIELD, searcher, true);
  Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), query);
  assertTrue("spans is null and it shouldn't be", spans != null);
  /*float score = hits.score(0);
  for (int i =1; i < hits.length(); i++)
  {
    assertTrue("scores are not equal and they should be", score == hits.score(i));
  }*/

}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:TestPayloadTermQuery.java

示例2: testMultipleMatchesPerDoc

import org.apache.lucene.search.spans.MultiSpansWrapper; //导入依赖的package包/类
public void testMultipleMatchesPerDoc() throws Exception {
  PayloadTermQuery query = new PayloadTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"),
          new MaxPayloadFunction());
  TopDocs hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);

  //they should all have the exact same score, because they all contain seventy once, and we set
  //all the other similarity factors to be 1

  //System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash);
  assertTrue(hits.getMaxScore() + " does not equal: " + 4.0, hits.getMaxScore() == 4.0);
  //there should be exactly 10 items that score a 4, all the rest should score a 2
  //The 10 items are: 70 + i*100 where i in [0-9]
  int numTens = 0;
  for (int i = 0; i < hits.scoreDocs.length; i++) {
    ScoreDoc doc = hits.scoreDocs[i];
    if (doc.doc % 10 == 0) {
      numTens++;
      assertTrue(doc.score + " does not equal: " + 4.0, doc.score == 4.0);
    } else {
      assertTrue(doc.score + " does not equal: " + 2, doc.score == 2);
    }
  }
  assertTrue(numTens + " does not equal: " + 10, numTens == 10);
  CheckHits.checkExplanations(query, "field", searcher, true);
  Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), query);
  assertTrue("spans is null and it shouldn't be", spans != null);
  //should be two matches per document
  int count = 0;
  //100 hits times 2 matches per hit, we should have 200 in count
  while (spans.next()) {
    count++;
  }
  assertTrue(count + " does not equal: " + 200, count == 200);
}
 
开发者ID:europeana,项目名称:search,代码行数:37,代码来源:TestPayloadTermQuery.java

示例3: testIgnoreSpanScorer

import org.apache.lucene.search.spans.MultiSpansWrapper; //导入依赖的package包/类
public void testIgnoreSpanScorer() throws Exception {
  PayloadTermQuery query = new PayloadTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"),
          new MaxPayloadFunction(), false);

  IndexReader reader = DirectoryReader.open(directory);
  IndexSearcher theSearcher = newSearcher(reader);
  theSearcher.setSimilarity(new FullSimilarity());
  TopDocs hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);

  //they should all have the exact same score, because they all contain seventy once, and we set
  //all the other similarity factors to be 1

  //System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash);
  assertTrue(hits.getMaxScore() + " does not equal: " + 4.0, hits.getMaxScore() == 4.0);
  //there should be exactly 10 items that score a 4, all the rest should score a 2
  //The 10 items are: 70 + i*100 where i in [0-9]
  int numTens = 0;
  for (int i = 0; i < hits.scoreDocs.length; i++) {
    ScoreDoc doc = hits.scoreDocs[i];
    if (doc.doc % 10 == 0) {
      numTens++;
      assertTrue(doc.score + " does not equal: " + 4.0, doc.score == 4.0);
    } else {
      assertTrue(doc.score + " does not equal: " + 2, doc.score == 2);
    }
  }
  assertTrue(numTens + " does not equal: " + 10, numTens == 10);
  CheckHits.checkExplanations(query, "field", searcher, true);
  Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), query);
  assertTrue("spans is null and it shouldn't be", spans != null);
  //should be two matches per document
  int count = 0;
  //100 hits times 2 matches per hit, we should have 200 in count
  while (spans.next()) {
    count++;
  }
  reader.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:41,代码来源:TestPayloadTermQuery.java

示例4: testIgnoreSpanScorer

import org.apache.lucene.search.spans.MultiSpansWrapper; //导入依赖的package包/类
public void testIgnoreSpanScorer() throws Exception {
  PayloadTermQuery query = new PayloadTermQuery(new Term(PayloadHelper.MULTI_FIELD, "seventy"),
          new MaxPayloadFunction(), false);

  IndexReader reader = DirectoryReader.open(directory);
  IndexSearcher theSearcher = new IndexSearcher(reader);
  theSearcher.setSimilarity(new FullSimilarity());
  TopDocs hits = searcher.search(query, null, 100);
  assertTrue("hits is null and it shouldn't be", hits != null);
  assertTrue("hits Size: " + hits.totalHits + " is not: " + 100, hits.totalHits == 100);

  //they should all have the exact same score, because they all contain seventy once, and we set
  //all the other similarity factors to be 1

  //System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash);
  assertTrue(hits.getMaxScore() + " does not equal: " + 4.0, hits.getMaxScore() == 4.0);
  //there should be exactly 10 items that score a 4, all the rest should score a 2
  //The 10 items are: 70 + i*100 where i in [0-9]
  int numTens = 0;
  for (int i = 0; i < hits.scoreDocs.length; i++) {
    ScoreDoc doc = hits.scoreDocs[i];
    if (doc.doc % 10 == 0) {
      numTens++;
      assertTrue(doc.score + " does not equal: " + 4.0, doc.score == 4.0);
    } else {
      assertTrue(doc.score + " does not equal: " + 2, doc.score == 2);
    }
  }
  assertTrue(numTens + " does not equal: " + 10, numTens == 10);
  CheckHits.checkExplanations(query, "field", searcher, true);
  Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), query);
  assertTrue("spans is null and it shouldn't be", spans != null);
  //should be two matches per document
  int count = 0;
  //100 hits times 2 matches per hit, we should have 200 in count
  while (spans.next()) {
    count++;
  }
  reader.close();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:41,代码来源:TestPayloadTermQuery.java


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