List of usage examples for org.apache.lucene.search.join ScoreMode Avg
ScoreMode Avg
To view the source code for org.apache.lucene.search.join ScoreMode Avg.
Click Source Link
From source file:de.mpg.imeji.logic.search.elasticsearch.factory.ElasticQueryFactory.java
/** * Create a {@link QueryBuilder} - used to sarch for metadata which are defined with a statement * * @param index// www .j av a2 s . co m * @param value * @param operator * @param statement * @return */ private QueryBuilder metadataQuery(QueryBuilder valueQuery, String statement) { return QueryBuilders.nestedQuery(ElasticFields.METADATA.field(), QueryBuilders.boolQuery().must(valueQuery) .must(fieldQuery(ElasticFields.METADATA_INDEX, statement, SearchOperators.EQUALS, false)), ScoreMode.Avg); }
From source file:de.mpg.imeji.logic.search.elasticsearch.factory.ElasticQueryFactory.java
/** * Query for technical metadata//from ww w . jav a2s. c om * * @param label * @param value * @param not * @return */ private QueryBuilder technicalMetadataQuery(SearchTechnicalMetadata tmd) { return contentQuery(QueryBuilders.nestedQuery(ElasticFields.TECHNICAL.field(), QueryBuilders.boolQuery() .must(fieldQuery(ElasticFields.TECHNICAL_NAME, tmd.getLabel(), SearchOperators.EQUALS, false)) .must(fieldQuery(ElasticFields.TECHNICAL_VALUE, tmd.getValue(), tmd.getOperator(), tmd.isNot())), ScoreMode.Avg)); }
From source file:de.mpg.mpdl.inge.pubman.web.search.criterions.standard.ClassificationSearchCriterion.java
License:Open Source License
@Override public QueryBuilder toElasticSearchQuery() { BoolQueryBuilder bq = QueryBuilders.boolQuery(); bq.must(baseElasticSearchQueryBuilder(PubItemServiceDbImpl.INDEX_METADATA_SUBJECTS_TYPE, getClassificationType()));//from ww w. ja v a2s . com bq.must(super.toElasticSearchQuery()); return QueryBuilders.nestedQuery("metadata.subjects", bq, ScoreMode.Avg); }
From source file:de.mpg.mpdl.inge.pubman.web.search.criterions.standard.FulltextSearchCriterion.java
License:Open Source License
@Override public QueryBuilder toElasticSearchQuery() { HasChildQueryBuilder childQueryBuilder = JoinQueryBuilders.hasChildQuery("file", SearchCriterionBase .baseElasticSearchQueryBuilder(PubItemServiceDbImpl.INDEX_FULLTEXT_CONTENT, getSearchString()), ScoreMode.Avg); HighlightBuilder hb = new HighlightBuilder().field(PubItemServiceDbImpl.INDEX_FULLTEXT_CONTENT) .preTags("<span class=\"searchHit\">").postTags("</span>"); FetchSourceContext fs = new FetchSourceContext(true, null, new String[] { PubItemServiceDbImpl.INDEX_FULLTEXT_CONTENT }); childQueryBuilder.innerHit(new InnerHitBuilder().setHighlightBuilder(hb).setFetchSourceContext(fs)); return childQueryBuilder; }
From source file:de.mpg.mpdl.inge.pubman.web.search.criterions.standard.IdentifierSearchCriterion.java
License:Open Source License
@Override public QueryBuilder toElasticSearchQuery() { if (getSelectedIdentifierType() == null) { return super.toElasticSearchQuery(); } else {/*from w ww . j av a 2 s . c om*/ BoolQueryBuilder idQueryBuilder = QueryBuilders.boolQuery(); idQueryBuilder.must(baseElasticSearchQueryBuilder(PubItemServiceDbImpl.INDEX_METADATA_IDENTIFIERS_TYPE, getSelectedIdentifierType().name())); idQueryBuilder.must(baseElasticSearchQueryBuilder(PubItemServiceDbImpl.INDEX_METADATA_IDENTIFIERS_ID, getSearchString())); BoolQueryBuilder sourceIdQueryBuilder = QueryBuilders.boolQuery(); sourceIdQueryBuilder.must( baseElasticSearchQueryBuilder(PubItemServiceDbImpl.INDEX_METADATA_SOURCES_IDENTIFIERS_TYPE, getSelectedIdentifierType().name())); sourceIdQueryBuilder.must(baseElasticSearchQueryBuilder( PubItemServiceDbImpl.INDEX_METADATA_SOURCES_IDENTIFIERS_ID, getSearchString())); return QueryBuilders.boolQuery() .should(QueryBuilders.nestedQuery("metadata.identifiers", idQueryBuilder, ScoreMode.Avg)) .should(QueryBuilders.nestedQuery("metadata.sources.identifiers", sourceIdQueryBuilder, ScoreMode.Avg)); } }
From source file:de.mpg.mpdl.inge.pubman.web.search.criterions.stringOrHiddenId.PersonSearchCriterion.java
License:Open Source License
@Override public QueryBuilder toElasticSearchQuery() { if (selectedRole == null) { if (this.getHiddenId() != null && !this.getHiddenId().trim().isEmpty()) { return SearchCriterionBase.baseElasticSearchQueryBuilder(this.getElasticSearchFieldForHiddenId(), this.getHiddenId()); } else {// w w w .j av a 2 s .com return QueryBuilders .multiMatchQuery(this.getSearchString(), this.getElasticSearchFieldForSearchString()) .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).operator(Operator.AND); } } else { BoolQueryBuilder bq = QueryBuilders.boolQuery().must(SearchCriterionBase.baseElasticSearchQueryBuilder( PubItemServiceDbImpl.INDEX_METADATA_CREATOR_ROLE, selectedRole.name())); if (this.getHiddenId() != null && !this.getHiddenId().trim().isEmpty()) { bq = bq.must(SearchCriterionBase.baseElasticSearchQueryBuilder( this.getElasticSearchFieldForHiddenId(), this.getHiddenId())); } else { bq = bq.must(QueryBuilders .multiMatchQuery(this.getSearchString(), this.getElasticSearchFieldForSearchString()) .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).operator(Operator.AND)); } return QueryBuilders.nestedQuery("metadata.creators", (QueryBuilder) bq, ScoreMode.Avg); } }
From source file:io.hops.hopsworks.common.elastic.ElasticController.java
License:Open Source License
/** * Creates the query that is applied on the text fields of a document. Hits * the xattr fields/* ww w . jav a 2s . com*/ * <p/> * @param searchTerm * @return */ private QueryBuilder getMetadataQuery(String searchTerm) { QueryBuilder metadataQuery = queryStringQuery(String.format("*%s*", searchTerm)).lenient(Boolean.TRUE) .field(Settings.META_DATA_FIELDS); QueryBuilder nestedQuery = nestedQuery(Settings.META_DATA_NESTED_FIELD, metadataQuery, ScoreMode.Avg); return nestedQuery; }
From source file:org.apache.solr.handler.dataimport.TestHierarchicalDocBuilder.java
License:Apache License
@Test public void testThreeLevelHierarchy() throws Exception { int parentsNum = 3; //fixed for simplicity of test int childrenNum = 0; int grandChildrenNum = 0; final String parentType = "parent"; final String childType = "child"; final String grandChildType = "grand_child"; List<String> parentIds = createDataIterator("select * from PARENT", parentType, parentType, parentsNum); Collections.shuffle(parentIds, random()); String parentId1 = parentIds.get(0); String parentId2 = parentIds.get(1); //parent 1 children int firstParentChildrenNum = 3; //fixed for simplicity of test String select = "select * from CHILD where parent_id='" + parentId1 + "'"; List<String> childrenIds = createDataIterator(select, childType, "child of first parent", firstParentChildrenNum);/*from ww w .j a v a 2s . c o m*/ List<String> firstParentChildrenIds = new ArrayList<String>(childrenIds); childrenNum += childrenIds.size(); // grand children of first parent first child String childId = childrenIds.get(0); String description = "grandchild of first parent, child of " + childId + " child"; select = "select * from GRANDCHILD where parent_id='" + childId + "'"; List<String> grandChildrenIds = createDataIterator(select, grandChildType, description, atLeast(2)); grandChildrenNum += grandChildrenIds.size(); // grand children of first parent second child childId = childrenIds.get(1); description = "grandchild of first parent, child of " + childId + " child"; select = "select * from GRANDCHILD where parent_id='" + childId + "'"; List<String> grandChildrenIds2 = createDataIterator(select, grandChildType, description, atLeast(2)); grandChildrenNum += grandChildrenIds2.size(); grandChildrenIds.addAll(grandChildrenIds2); // third children of first parent has no grand children // parent 2 children (no grand children) select = "select * from CHILD where parent_id='" + parentId2 + "'"; childrenIds = createDataIterator(select, childType, "child of second parent", atLeast(2)); childrenNum += childrenIds.size(); // parent 3 has no children and grand children int totalDocsNum = parentsNum + childrenNum + grandChildrenNum; runFullImport(threeLevelHierarchyConfig); assertTrue("Update request processor processAdd was not called", TestUpdateRequestProcessor.processAddCalled); assertTrue("Update request processor processCommit was not callled", TestUpdateRequestProcessor.processCommitCalled); assertTrue("Update request processor finish was not called", TestUpdateRequestProcessor.finishCalled); // very simple asserts to check that we at least have correct num of docs indexed assertQ(req("*:*"), "//*[@numFound='" + totalDocsNum + "']"); assertQ(req("type_s:parent"), "//*[@numFound='" + parentsNum + "']"); assertQ(req("type_s:child"), "//*[@numFound='" + childrenNum + "']"); assertQ(req("type_s:grand_child"), "//*[@numFound='" + grandChildrenNum + "']"); // let's check BlockJoin // get first parent by any grand children String randomGrandChildId = grandChildrenIds.get(random().nextInt(grandChildrenIds.size())); Query query = createToParentQuery(parentType, FIELD_ID, randomGrandChildId); assertSearch(query, FIELD_ID, parentId1); // get first parent by any children String randomChildId = firstParentChildrenIds.get(random().nextInt(firstParentChildrenIds.size())); query = createToParentQuery(parentType, FIELD_ID, randomChildId); assertSearch(query, FIELD_ID, parentId1); // get parent by children by grand children randomGrandChildId = grandChildrenIds.get(random().nextInt(grandChildrenIds.size())); ToParentBlockJoinQuery childBlockJoinQuery = createToParentQuery(childType, FIELD_ID, randomGrandChildId); ToParentBlockJoinQuery blockJoinQuery = new ToParentBlockJoinQuery(childBlockJoinQuery, createParentFilter(parentType), ScoreMode.Avg); assertSearch(blockJoinQuery, FIELD_ID, parentId1); }
From source file:org.apache.solr.handler.dataimport.TestHierarchicalDocBuilder.java
License:Apache License
private ToParentBlockJoinQuery createToParentQuery(String parentType, Query childQuery) { ToParentBlockJoinQuery blockJoinQuery = new ToParentBlockJoinQuery(childQuery, createParentFilter(parentType), ScoreMode.Avg); return blockJoinQuery; }
From source file:org.apache.solr.search.join.TestScoreJoinQPScore.java
License:Apache License
public void testCacheHit() throws Exception { indexDataForScorring();/*from w w w. ja va2 s . c om*/ SolrCache cache = (SolrCache) h.getCore().getInfoRegistry().get("queryResultCache"); { final NamedList statPre = cache.getStatistics(); h.query(req("q", "{!join from=movieId_s to=id score=Avg}title:first", "fl", "id", "omitHeader", "true")); assertHitOrInsert(cache, statPre); } { final NamedList statPre = cache.getStatistics(); h.query(req("q", "{!join from=movieId_s to=id score=Avg}title:first", "fl", "id", "omitHeader", "true")); assertHit(cache, statPre); } { NamedList statPre = cache.getStatistics(); Random r = random(); boolean changed = false; boolean x = false; String from = (x = r.nextBoolean()) ? "id" : "movieId_s"; changed |= x; String to = (x = r.nextBoolean()) ? "movieId_s" : "id"; changed |= x; String score = (x = r.nextBoolean()) ? not(ScoreMode.Avg).name() : "Avg"; changed |= x; /* till SOLR-7814 * String boost = (x = r.nextBoolean()) ? "23" : "1"; changed |= x; */ String q = (!changed) ? (r.nextBoolean() ? "title:first^67" : "title:night") : "title:first"; final String resp = h.query(req("q", "{!join from=" + from + " to=" + to + " score=" + score + //" b=" + boost + "}" + q, "fl", "id", "omitHeader", "true")); assertInsert(cache, statPre); statPre = cache.getStatistics(); final String repeat = h.query( req("q", "{!join from=" + from + " to=" + to + " score=" + score.toLowerCase(Locale.ROOT) + //" b=" + boost "}" + q, "fl", "id", "omitHeader", "true")); assertHit(cache, statPre); assertEquals("lowercase shouldn't change anything", resp, repeat); final String aMod = score.substring(0, score.length() - 1); assertQEx("exception on " + aMod, "ScoreMode", req("q", "{!join from=" + from + " to=" + to + " score=" + aMod + "}" + q, "fl", "id", "omitHeader", "true"), SolrException.ErrorCode.BAD_REQUEST); } // this queries are not overlap, with other in this test case. // however it might be better to extract this method into the separate suite // for a while let's nuke a cache content, in case of repetitions cache.clear(); }