• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ToParentBlockJoinQuery类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: rewrite

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
@Override
public Query rewrite(IndexReader reader) throws IOException {
    Query innerRewrite = query.rewrite(reader);
    if (innerRewrite != query) {
        // Right now ToParentBlockJoinQuery always rewrites to a ToParentBlockJoinQuery
        // so the else block will never be used. It is useful in the case that
        // ToParentBlockJoinQuery one day starts to rewrite to a different query, eg.
        // a MatchNoDocsQuery if it realizes that it cannot match any docs and rewrites
        // to a MatchNoDocsQuery. In that case it would be fine to lose information
        // about the nested path.
        if (innerRewrite instanceof ToParentBlockJoinQuery) {
            return new ESToParentBlockJoinQuery((ToParentBlockJoinQuery) innerRewrite, path);
        } else {
            return innerRewrite;
        }
    }
    return super.rewrite(reader);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:ESToParentBlockJoinQuery.java


示例2: assertAvgScoreMode

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
@Override
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DoubleNestedSortingTests.java


示例3: assertAvgScoreMode

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher, IndexFieldData.XFieldComparatorSource innerFieldComparator) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:FloatNestedSortingTests.java


示例4: assertAvgScoreMode

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
protected void assertAvgScoreMode(Query parentFilter, IndexSearcher searcher) throws IOException {
    MultiValueMode sortMode = MultiValueMode.AVG;
    Query childFilter = Queries.not(parentFilter);
    XFieldComparatorSource nestedComparatorSource = createFieldComparator("field2", sortMode, -127, createNested(searcher, parentFilter, childFilter));
    Query query = new ToParentBlockJoinQuery(new ConstantScoreQuery(childFilter), new QueryBitSetProducer(parentFilter), ScoreMode.None);
    Sort sort = new Sort(new SortField("field2", nestedComparatorSource));
    TopDocs topDocs = searcher.search(query, 5, sort);
    assertThat(topDocs.totalHits, equalTo(7));
    assertThat(topDocs.scoreDocs.length, equalTo(5));
    assertThat(topDocs.scoreDocs[0].doc, equalTo(11));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[0]).fields[0]).intValue(), equalTo(2));
    assertThat(topDocs.scoreDocs[1].doc, equalTo(3));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[1]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[2].doc, equalTo(7));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[2]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[3].doc, equalTo(15));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[3]).fields[0]).intValue(), equalTo(3));
    assertThat(topDocs.scoreDocs[4].doc, equalTo(19));
    assertThat(((Number) ((FieldDoc) topDocs.scoreDocs[4]).fields[0]).intValue(), equalTo(4));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractNumberNestedSortingTestCase.java


示例5: limitingFilter

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
private Optional<Query> limitingFilter(Query query, boolean isNegated) {
    if (query instanceof SpanQuery) {
        return limitingFilterForSpan((SpanQuery) query, isNegated);
    } else if (query instanceof Filter) {
        return Optional.of(query);
    } else if (query instanceof BooleanQuery) {
        return boolQuery((BooleanQuery) query, isNegated);
    } else if (query instanceof TermQuery) {
        return Optional.of(query);
    } else if (query instanceof PhraseQuery) {
        return phraseFilter((PhraseQuery) query, isNegated);
    } else if (query instanceof MultiTermQuery) {
        return Optional.of(query);
    } else if (query instanceof WildcardPhraseQuery) {
        return wildcardPhraseFilter((WildcardPhraseQuery) query, isNegated);
    } else if (query instanceof ToParentBlockJoinQuery) {
        //This can be really bad for performance, if the nested query contains expensive operations (phrases/spans)
        //On the other hand, it is only slow if the field actually has any data, and we currently do not have
        // any data in the only nested text field (enrichments.sentences)
        return Optional.of(query);
    } else {
        //This should never happen, but if it does, it might be really bad for performance
        //logger.warn("failed to limit query, this should never happen. Query : [{}]", query.toString());
        return Optional.of(query);
    }
}
 
开发者ID:meltwater,项目名称:meltwater-elasticsearch-queries,代码行数:27,代码来源:LimitingFilterFactory.java


示例6: ESToParentBlockJoinQuery

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
public ESToParentBlockJoinQuery(Query childQuery, BitSetProducer parentsFilter, ScoreMode scoreMode, String path) {
    this(new ToParentBlockJoinQuery(childQuery, parentsFilter, scoreMode), path);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:4,代码来源:ESToParentBlockJoinQuery.java


示例7: parse

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
    XContentParser parser = parseContext.parser();
    final ToBlockJoinQueryBuilder builder = new ToBlockJoinQueryBuilder(parseContext);

    float boost = 1.0f;
    ScoreMode scoreMode = ScoreMode.Avg;
    String queryName = null;

    String currentFieldName = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.START_OBJECT) {
            if ("query".equals(currentFieldName)) {
                builder.query();
            } else if (parseContext.parseFieldMatcher().match(currentFieldName, FILTER_FIELD)) {
                builder.filter();
            } else if ("inner_hits".equals(currentFieldName)) {
                builder.setInnerHits(innerHitsQueryParserHelper.parse(parseContext));
            } else {
                throw new QueryParsingException(parseContext, "[nested] query does not support [" + currentFieldName + "]");
            }
        } else if (token.isValue()) {
            if ("path".equals(currentFieldName)) {
                builder.setPath(parser.text());
            } else if ("boost".equals(currentFieldName)) {
                boost = parser.floatValue();
            } else if ("score_mode".equals(currentFieldName) || "scoreMode".equals(currentFieldName)) {
                String sScoreMode = parser.text();
                if ("avg".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Avg;
                } else if ("min".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Min;
                } else if ("max".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Max;
                } else if ("total".equals(sScoreMode) || "sum".equals(sScoreMode)) {
                    scoreMode = ScoreMode.Total;
                } else if ("none".equals(sScoreMode)) {
                    scoreMode = ScoreMode.None;
                } else {
                    throw new QueryParsingException(parseContext, "illegal score_mode for nested query [" + sScoreMode + "]");
                }
            } else if ("_name".equals(currentFieldName)) {
                queryName = parser.text();
            } else {
                throw new QueryParsingException(parseContext, "[nested] query does not support [" + currentFieldName + "]");
            }
        }
    }

    builder.setScoreMode(scoreMode);
    ToParentBlockJoinQuery joinQuery = builder.build();
    if (joinQuery != null) {
        joinQuery.setBoost(boost);
        if (queryName != null) {
            parseContext.addNamedQuery(queryName, joinQuery);
        }
    }
    return joinQuery;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:63,代码来源:NestedQueryParser.java


示例8: main

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  Directory dir = new RAMDirectory();
  Analyzer analyzer = new StandardAnalyzer();
  IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
  iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
  IndexWriter writer = new IndexWriter(dir, iwc);

  // first block
  final Document sku1_1 = new Document();
  sku1_1.add(new TextField("color", "red", Field.Store.YES));
  sku1_1.add(new TextField("size", "xl", Field.Store.YES));
  sku1_1.add(new TextField("type", "sku", Field.Store.YES));

  final Document sku1_2 = new Document();
  sku1_2.add(new TextField("color", "blue", Field.Store.YES));
  sku1_2.add(new TextField("size", "m", Field.Store.YES));
  sku1_2.add(new TextField("type", "sku", Field.Store.YES));

  final Document product1 = new Document();
  product1.add(new TextField("brand", "adidas", Field.Store.YES));
  product1.add(new TextField("title", "dress", Field.Store.YES));
  product1.add(new TextField("type", "product", Field.Store.YES));

  writer.addDocuments(Arrays.asList(new Document[] {sku1_1, sku1_2, product1}));

  // second block
  final Document sku2_1 = new Document();
  sku2_1.add(new TextField("color", "red", Field.Store.YES));
  sku2_1.add(new TextField("size", "m", Field.Store.YES));
  sku2_1.add(new TextField("type", "sku", Field.Store.YES));

  final Document sk2_2 = new Document();
  sk2_2.add(new TextField("color", "blue", Field.Store.YES));
  sk2_2.add(new TextField("size", "xl", Field.Store.YES));
  sk2_2.add(new TextField("type", "sku", Field.Store.YES));

  final Document product2 = new Document();
  product2.add(new TextField("brand", "puma", Field.Store.YES));
  product2.add(new TextField("title", "dress", Field.Store.YES));
  product2.add(new TextField("type", "product", Field.Store.YES));

  writer.addDocuments(Arrays.asList(new Document[] {sku2_1, sk2_2, product2}));

  writer.close();

  IndexReader reader = DirectoryReader.open(dir);
  IndexSearcher searcher = new IndexSearcher(reader);

  // i want to find out all products of the query red m dress
  BooleanQuery.Builder builder = new BooleanQuery.Builder();
  BooleanQuery childQuery = builder.build();
  ToParentBlockJoinQuery parentQuery =
      new ToParentBlockJoinQuery(
          childQuery,
          new QueryBitSetProducer(new TermQuery(new Term("type", "product"))),
          ScoreMode.Avg);

  System.out.println("query: " + parentQuery);

  TopDocs results = searcher.search(parentQuery, 100);
  ScoreDoc[] scoreDocs = results.scoreDocs;
  for (int i = 0; i < scoreDocs.length; ++i) {
    System.out.println(searcher.explain(parentQuery, scoreDocs[i].doc));
  }
}
 
开发者ID:MysterionRise,项目名称:information-retrieval-adventure,代码行数:66,代码来源:ExactMatchBJQTest.java


示例9: createQuery

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
protected Query createQuery(Query parentList, Query query) {
  return new ToParentBlockJoinQuery(query, getFilter(parentList), ScoreMode.None);
}
 
开发者ID:europeana,项目名称:search,代码行数:4,代码来源:BlockJoinParentQParser.java


示例10: join

import org.apache.lucene.search.join.ToParentBlockJoinQuery; //导入依赖的package包/类
protected ToParentBlockJoinQuery join(final String childTerm) {
  return new ToParentBlockJoinQuery(
      new TermQuery(new Term(child, childTerm)), new TermRangeFilter(parent,
          null, null, false, false), ScoreMode.None);
}
 
开发者ID:europeana,项目名称:search,代码行数:6,代码来源:AddBlockUpdateTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java XMLStreamWriterFactory类代码示例发布时间:2022-05-22
下一篇:
Java DefaultPermissionFactory类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap