當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。