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


Java Query.rewrite方法代碼示例

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


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

示例1: checkGeoQueryHighlighting

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
public void checkGeoQueryHighlighting(Query geoQuery) throws IOException, InvalidTokenOffsetsException {
    Map analysers = new HashMap<String, Analyzer>();
    analysers.put("text", new StandardAnalyzer());
    FieldNameAnalyzer fieldNameAnalyzer = new FieldNameAnalyzer(analysers);
    Query termQuery = new TermQuery(new Term("text", "failure"));
    Query boolQuery = new BooleanQuery.Builder().add(new BooleanClause(geoQuery, BooleanClause.Occur.SHOULD))
        .add(new BooleanClause(termQuery, BooleanClause.Occur.SHOULD)).build();
    org.apache.lucene.search.highlight.Highlighter highlighter =
        new org.apache.lucene.search.highlight.Highlighter(new CustomQueryScorer(boolQuery));
    String fragment = highlighter.getBestFragment(fieldNameAnalyzer.tokenStream("text", "Arbitrary text field which should not cause " +
        "a failure"), "Arbitrary text field which should not cause a failure");
    assertThat(fragment, equalTo("Arbitrary text field which should not cause a <B>failure</B>"));
    Query rewritten = boolQuery.rewrite(null);
    highlighter = new org.apache.lucene.search.highlight.Highlighter(new CustomQueryScorer(rewritten));
    fragment = highlighter.getBestFragment(fieldNameAnalyzer.tokenStream("text", "Arbitrary text field which should not cause " +
        "a failure"), "Arbitrary text field which should not cause a failure");
    assertThat(fragment, equalTo("Arbitrary text field which should not cause a <B>failure</B>"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:PlainHighlighterTests.java

示例2: searchIndex

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
/**
 * 查詢索引
 * 
 * @param keywords
 * @return
 * @throws Exception
 */
public List<Document> searchIndex(Integer typeId, String keywords) throws Exception {
    // 1.init searcher
    Analyzer analyzer = new PaodingAnalyzer();
    IndexReader reader = IndexReader.open(typeId == appConfig.getGameTypeId() ? appConfig.getGameIndexDir()
            : appConfig.getSoftIndexDir());
    BooleanClause.Occur[] flags = new BooleanClause.Occur[] { BooleanClause.Occur.SHOULD,
            BooleanClause.Occur.SHOULD };
    Query query = MultiFieldQueryParser.parse(keywords, appConfig.getQueryFields(), flags, analyzer);
    query = query.rewrite(reader);

    // 2.search
    List<Document> docs = new ArrayList<Document>();
    Hits hits = (typeId == appConfig.getGameTypeId() ? gameSearcher.search(query, Sort.RELEVANCE) : softSearcher
            .search(query, Sort.RELEVANCE));// searcher.search(query,
                                            // Sort.RELEVANCE);
    for (int i = 0; i < hits.length(); i++) {
        docs.add(hits.doc(i));
    }

    // 3.return
    reader.close();
    return docs;
}
 
開發者ID:zhaoxi1988,項目名稱:sjk,代碼行數:31,代碼來源:SearchServiceImpl.java

示例3: testRewrite

import org.apache.lucene.search.Query; //導入方法依賴的package包/類
public void testRewrite() throws IOException {
    Query q = new ESToParentBlockJoinQuery(
            new PhraseQuery("body", "term"), // rewrites to a TermQuery
            new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))),
            ScoreMode.Avg, "nested");
    Query expected = new ESToParentBlockJoinQuery(
             new TermQuery(new Term("body", "term")),
             new QueryBitSetProducer(new TermQuery(new Term("is", "parent"))),
             ScoreMode.Avg, "nested");
     Query rewritten = q.rewrite(new MultiReader());
     assertEquals(expected, rewritten);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:13,代碼來源:ESToParentBlockJoinQueryTests.java


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