當前位置: 首頁>>代碼示例>>Java>>正文


Java PhraseQuery.getPositions方法代碼示例

本文整理匯總了Java中org.apache.lucene.search.PhraseQuery.getPositions方法的典型用法代碼示例。如果您正苦於以下問題:Java PhraseQuery.getPositions方法的具體用法?Java PhraseQuery.getPositions怎麽用?Java PhraseQuery.getPositions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.lucene.search.PhraseQuery的用法示例。


在下文中一共展示了PhraseQuery.getPositions方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: applySlop

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
private Query applySlop(Query q, int slop) {
    if (q instanceof PhraseQuery) {
        PhraseQuery pq = (PhraseQuery) q;
        PhraseQuery.Builder builder = new PhraseQuery.Builder();
        builder.setSlop(slop);
        final Term[] terms = pq.getTerms();
        final int[] positions = pq.getPositions();
        for (int i = 0; i < terms.length; ++i) {
            builder.add(terms[i], positions[i]);
        }
        pq = builder.build();
        pq.setBoost(q.getBoost());
        return pq;
    } else if (q instanceof MultiPhraseQuery) {
        ((MultiPhraseQuery) q).setSlop(slop);
        return q;
    } else {
        return q;
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:MapperQueryParser.java

示例2: testPositionIncrement

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
public void testPositionIncrement() throws Exception {
  StandardQueryParser qp = new StandardQueryParser();
  qp.setAnalyzer(
      new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET));

  qp.setEnablePositionIncrements(true);

  String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
  // 0 2 5 7 8
  int expectedPositions[] = { 1, 3, 4, 6, 9 };
  PhraseQuery pq = (PhraseQuery) qp.parse(qtxt, "a");
  // System.out.println("Query text: "+qtxt);
  // System.out.println("Result: "+pq);
  Term t[] = pq.getTerms();
  int pos[] = pq.getPositions();
  for (int i = 0; i < t.length; i++) {
    // System.out.println(i+". "+t[i]+"  pos: "+pos[i]);
    assertEquals("term " + i + " = " + t[i] + " has wrong term-position!",
        expectedPositions[i], pos[i]);
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:22,代碼來源:TestQPHelper.java

示例3: testPositionIncrement

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
@Test
public void testPositionIncrement() throws Exception {
	QueryParser qp = getParserConfig(
			new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET));
	qp.setEnablePositionIncrements(true);
	String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
	// 0 2 5 7 8
	int expectedPositions[] = { 1, 3, 4, 6, 9 };
	PhraseQuery pq = (PhraseQuery) getQuery(qtxt, qp);
	// System.out.println("Query text: "+qtxt);
	// System.out.println("Result: "+pq);
	Term t[] = pq.getTerms();
	int pos[] = pq.getPositions();
	for (int i = 0; i < t.length; i++) {
		// System.out.println(i+". "+t[i]+" pos: "+pos[i]);
		Assert.assertEquals("term " + i + " = " + t[i] + " has wrong term-position!", expectedPositions[i], pos[i]);
	}
}
 
開發者ID:easynet-cn,項目名稱:resource-query-parser,代碼行數:19,代碼來源:QueryParserTestBase.java

示例4: testPositionIncrement

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
public void testPositionIncrement() throws Exception {
  StandardQueryParser qp = new StandardQueryParser();
  qp.setAnalyzer(
      new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET, true));

  qp.setEnablePositionIncrements(true);

  String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
  // 0 2 5 7 8
  int expectedPositions[] = { 1, 3, 4, 6, 9 };
  PhraseQuery pq = (PhraseQuery) qp.parse(qtxt, "a");
  // System.out.println("Query text: "+qtxt);
  // System.out.println("Result: "+pq);
  Term t[] = pq.getTerms();
  int pos[] = pq.getPositions();
  for (int i = 0; i < t.length; i++) {
    // System.out.println(i+". "+t[i]+"  pos: "+pos[i]);
    assertEquals("term " + i + " = " + t[i] + " has wrong term-position!",
        expectedPositions[i], pos[i]);
  }
}
 
開發者ID:pkarmstr,項目名稱:NYBC,代碼行數:22,代碼來源:TestQPHelper.java

示例5: applySlop

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
private Query applySlop(Query q, int slop) {
	if (q instanceof PhraseQuery) {
		PhraseQuery.Builder builder = new PhraseQuery.Builder();
		builder.setSlop(slop);
		PhraseQuery pq = (PhraseQuery) q;
		org.apache.lucene.index.Term[] terms = pq.getTerms();
		int[] positions = pq.getPositions();
		for (int i = 0; i < terms.length; ++i) {
			builder.add(terms[i], positions[i]);
		}
		q = builder.build();
	}
	else if (q instanceof MultiPhraseQuery) {
		MultiPhraseQuery mpq = (MultiPhraseQuery) q;

		if (slop != mpq.getSlop()) {
			q = new MultiPhraseQuery.Builder(mpq).setSlop(slop).build();
		}
	}
	return q;
}
 
開發者ID:lumongo,項目名稱:lumongo,代碼行數:22,代碼來源:LumongoMultiFieldQueryParser.java

示例6: testPositionIncrement

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
public void testPositionIncrement() throws Exception {
  CommonQueryParserConfiguration qp = getParserConfig( new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET));
  qp.setEnablePositionIncrements(true);
  String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\"";
  //               0         2                      5           7  8
  int expectedPositions[] = {1,3,4,6,9};
  PhraseQuery pq = (PhraseQuery) getQuery(qtxt,qp);
  //System.out.println("Query text: "+qtxt);
  //System.out.println("Result: "+pq);
  Term t[] = pq.getTerms();
  int pos[] = pq.getPositions();
  for (int i = 0; i < t.length; i++) {
    //System.out.println(i+". "+t[i]+"  pos: "+pos[i]);
    assertEquals("term "+i+" = "+t[i]+" has wrong term-position!",expectedPositions[i],pos[i]);
  }
}
 
開發者ID:tballison,項目名稱:lucene-addons,代碼行數:17,代碼來源:QueryParserTestBase.java

示例7: addSlopToPhrase

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
/**
 * Rebuild a phrase query with a slop value
 */
private PhraseQuery addSlopToPhrase(PhraseQuery query, int slop) {
    PhraseQuery.Builder builder = new PhraseQuery.Builder();
    builder.setSlop(slop);
    final Term[] terms = query.getTerms();
    final int[] positions = query.getPositions();
    for (int i = 0; i < terms.length; ++i) {
        builder.add(terms[i], positions[i]);
    }

    return builder.build();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:15,代碼來源:MapperQueryParser.java

示例8: addSlopToPhrase

import org.apache.lucene.search.PhraseQuery; //導入方法依賴的package包/類
/**
 * Rebuild a phrase query with a slop value
 */
private PhraseQuery addSlopToPhrase(PhraseQuery query, int slop) {
	PhraseQuery.Builder builder = new PhraseQuery.Builder();
	builder.setSlop(slop);
	org.apache.lucene.index.Term[] terms = query.getTerms();
	int[] positions = query.getPositions();
	for (int i = 0; i < terms.length; ++i) {
		builder.add(terms[i], positions[i]);
	}

	return builder.build();
}
 
開發者ID:easynet-cn,項目名稱:resource-query-parser,代碼行數:15,代碼來源:QueryParserBase.java


注:本文中的org.apache.lucene.search.PhraseQuery.getPositions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。