当前位置: 首页>>代码示例>>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;未经允许,请勿转载。