当前位置: 首页>>代码示例>>Java>>正文


Java Occur类代码示例

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


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

示例1: binaryNameQuery

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
static Query binaryNameQuery (final String resourceName) {
    final BooleanQuery query = new BooleanQuery ();
    int index = resourceName.lastIndexOf(BinaryName.PKG_SEPARATOR);  // NOI18N
    String pkgName, sName;
    if (index < 0) {
        pkgName = "";   // NOI18N
        sName = resourceName;
    }
    else {
        pkgName = resourceName.substring(0,index);
        sName = resourceName.substring(index+1);
    }
    sName = sName + WILDCARD_QUERY_WILDCARD;   //Type of type element (Enum, Class, Interface, Annotation)
    query.add (new TermQuery (new Term (FIELD_PACKAGE_NAME, pkgName)),BooleanClause.Occur.MUST);
    query.add (new WildcardQuery (new Term (FIELD_BINARY_NAME, sName)),BooleanClause.Occur.MUST);
    return query;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DocumentUtil.java

示例2: createFQNQuery

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
private static BooleanQuery createFQNQuery(final String resourceName) {
    String pkgName;
    String sName;
    int index = resourceName.lastIndexOf(BinaryName.PKG_SEPARATOR);
    if (index < 0) {
        pkgName = "";       //NOI18N
        sName = resourceName;
    } else {
        pkgName = resourceName.substring(0, index);
        sName = resourceName.substring(index+1);
    }
    final BooleanQuery snQuery = new BooleanQuery();
    snQuery.add (new WildcardQuery (new Term (DocumentUtil.FIELD_BINARY_NAME, sName + DocumentUtil.WILDCARD_QUERY_WILDCARD)),Occur.SHOULD);
    snQuery.add (new PrefixQuery (new Term (DocumentUtil.FIELD_BINARY_NAME, sName + '$')),Occur.SHOULD);   //NOI18N
    if (pkgName.length() == 0) {
        return snQuery;
    }
    final BooleanQuery fqnQuery = new BooleanQuery();
    fqnQuery.add(new TermQuery(new Term(DocumentUtil.FIELD_PACKAGE_NAME,pkgName)), Occur.MUST);
    fqnQuery.add(snQuery, Occur.MUST);
    return fqnQuery;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:DocumentUtil.java

示例3: dataFlushed

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
/**
 * This method is eventually called from the middle of BinaryAnalyser work, after it flushes some data from memory. The method
 * must check & store information that the data is NOT visible to IndexReaders yet
 */
private void dataFlushed(Index index) throws IOException, InterruptedException {
    Collection<String> names = new LinkedList<String>();
    // check using collected usages

    index.query(
            names,
            DocumentUtil.binaryNameConvertor(),
            DocumentUtil.declaredTypesFieldSelector(false, false),
            null,
            QueryUtil.createUsagesQuery("java.util.List", EnumSet.of(UsageType.TYPE_REFERENCE), Occur.SHOULD));
    names.retainAll(
            Arrays.asList(
            "usages.ClassAnnotations",
            "usages.ClassArrayAnnotations",
            "usages.MethodAnnotations",
            "usages.MethodArrayAnnotations",
            "usages.FieldAnnotations",
            "usages.FieldArrayAnnotations")
    );
    assertTrue(names.isEmpty());

    flushCount++;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:BinaryAnalyserTest.java

示例4: addSearchText

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
/**
 * Adds a filter for the given search text to the given {@link BooleanQuery}.
 * If the search text is blank, than the query will not modified.
 * For each part of the search text {@link #buildSearchTermQuery(IIndexTypeConf, String, float)}
 * will be called.
 *
 * @param query the {@link BooleanQuery} to add the sub queries.
 * @param searchText the search text. May be blank (null or contain only white spaces).
 * @param indexType the type in which should be searched.
 * @param baseBoost highest possible boost of the query. The more the match is exact
 * 			than a bigger boost will be used.
 */
public static void addSearchText(final BooleanQuery query,
		final String searchText, final IIndexTypeConf indexType, final float baseBoost) {

	if(StringUtils.isBlank(searchText)) {
		return;
	}

	query.setMinimumNumberShouldMatch(1); // at least one "should" should match
	query.add(buildSearchTermQuery(indexType, searchText, baseBoost), Occur.SHOULD);

	final BooleanQuery partsQuery = new BooleanQuery();
	query.add(partsQuery, Occur.SHOULD);

	final String[] searchTexts = searchText.toLowerCase().split("\\s");
	for (final String search : searchTexts) {
		partsQuery.add(buildSearchTermQuery(indexType, search, baseBoost), Occur.MUST); // each part has to match
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:31,代码来源:QueryUtil.java

示例5: addSearchTermQueries

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
/**
 * Adds for every field in {@link IIndexTypeConf} a {@link TermQuery}, {@link PrefixQuery} and
 * a {@link FuzzyQuery} with a suitable boost relative to the given base boost.
 *
 * @param indexType the type in which should be searched.
 * @param search the search text.
 * @param subQuery the {@link BooleanQuery} to add the sub queries.
 * @param baseBoost highest possible boost of the query. The more the match is exact
 * 			than a bigger boost will be used.
 */
private static void addSearchTermQueries(final IIndexTypeConf indexType, final String search,
		final BooleanQuery subQuery, final float baseBoost) {

	for(final IIndexFieldConf<?> field : indexType.getFields()) {
		final Term term = new Term(field.getName(), search);

		final TermQuery exactQuery = new TermQuery(term);
		exactQuery.setBoost(baseBoost);
		subQuery.add(exactQuery, Occur.SHOULD);

		final PrefixQuery pfQuery = new PrefixQuery(term);
		pfQuery.setBoost(0.7f*baseBoost);
		subQuery.add(pfQuery, Occur.SHOULD);

		final FuzzyQuery fuzzyQuery = new FuzzyQuery(term);
		fuzzyQuery.setBoost(0.5f*baseBoost);
		subQuery.add(fuzzyQuery, Occur.SHOULD);
	}
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:30,代码来源:QueryUtil.java

示例6: getNewsOfNewsGroup

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
/**
 * Returns all {@link News} of the given news group except the {@link News} with the given id.
 * @param newsGroupId the news group id
 * @param exceptId the news which should not be returned
 * @return a {@link List} with all {@link News} of the requested news group except the {@link News} with the exceptId.
 */
private List<News> getNewsOfNewsGroup(final long newsGroupId, final long exceptId) {
	final BooleanQuery query = new BooleanQuery();

	QueryUtil.addTypeConf(query, NewsIndexType.getInstance());

	final NumericRangeQuery<Long> groupQuery = NumericRangeQuery.newLongRange(
			NewsIndexType.FIELD_NEWSGROUPID, newsGroupId, newsGroupId, true, true);
	query.add(groupQuery, Occur.MUST);

	// exclude news
	query.add(new TermQuery(new Term(IIndexElement.FIELD_ID, String.valueOf(exceptId))), Occur.MUST_NOT);

	final SearchOptions options = new SearchOptions();
	options.setSort(new Sort(ESortField.PUBLISH_DATE.getSortField(ESortOrder.DESC)));

	final DocumentsSearchResult result = IndexSearch.getInstance().search(query, options);
	return NewsIndexType.docsToNews(result.getResults());
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:25,代码来源:NewsDao.java

示例7: getAmountOfNewsInNewsGroups

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
/**
 * Returns the amount of {@link News} which are assigned to news groups (news group id > 0)
 * for the given {@link Query}.
 */
private int getAmountOfNewsInNewsGroups(final Query filterQuery) {
	final BooleanQuery query = new BooleanQuery();
	query.add(filterQuery, Occur.MUST);

	// get only news that are in real groups (newsGroupId > 0)
	final NumericRangeQuery<Long> newsGroupFilterQuery = NumericRangeQuery.newLongRange(
			NewsIndexType.FIELD_NEWSGROUPID, 0l, null, false, true);
	query.add(newsGroupFilterQuery, Occur.MUST);

	final SearchOptions options = new SearchOptions();
	options.setMaxResults(0); // we only want the totalHits, not the results.

	final TopDocs topDocs = IndexSearch.getInstance().getTopDocs(query, options);

	return topDocs.totalHits;
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:21,代码来源:NewsDao.java

示例8: testExtractTerms

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
public void testExtractTerms() throws Exception {
    addQueryMapping();
    BooleanQuery.Builder bq = new BooleanQuery.Builder();
    TermQuery termQuery1 = new TermQuery(new Term("field", "term1"));
    bq.add(termQuery1, BooleanClause.Occur.SHOULD);
    TermQuery termQuery2 = new TermQuery(new Term("field", "term2"));
    bq.add(termQuery2, BooleanClause.Occur.SHOULD);

    DocumentMapper documentMapper = mapperService.documentMapper(typeName);
    PercolatorFieldMapper fieldMapper = (PercolatorFieldMapper) documentMapper.mappers().getMapper(fieldName);
    ParseContext.InternalParseContext parseContext = new ParseContext.InternalParseContext(Settings.EMPTY,
            mapperService.documentMapperParser(), documentMapper, null, null);
    fieldMapper.processQuery(bq.build(), parseContext);
    ParseContext.Document document = parseContext.doc();

    PercolatorFieldMapper.FieldType fieldType = (PercolatorFieldMapper.FieldType) fieldMapper.fieldType();
    assertThat(document.getField(fieldType.extractionResultField.name()).stringValue(), equalTo(EXTRACTION_COMPLETE));
    List<IndexableField> fields = new ArrayList<>(Arrays.asList(document.getFields(fieldType.queryTermsField.name())));
    Collections.sort(fields, (field1, field2) -> field1.binaryValue().compareTo(field2.binaryValue()));
    assertThat(fields.size(), equalTo(2));
    assertThat(fields.get(0).binaryValue().utf8ToString(), equalTo("field\u0000term1"));
    assertThat(fields.get(1).binaryValue().utf8ToString(), equalTo("field\u0000term2"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:PercolatorFieldMapperTests.java

示例9: getBackgroundFrequency

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
private long getBackgroundFrequency(String value) throws IOException {
    Query query = fieldType.termQuery(value, context.getQueryShardContext());
    if (query instanceof TermQuery) {
        // for types that use the inverted index, we prefer using a caching terms
        // enum that will do a better job at reusing index inputs
        Term term = ((TermQuery) query).getTerm();
        FilterableTermsEnum termsEnum = getTermsEnum(term.field());
        if (termsEnum.seekExact(term.bytes())) {
            return termsEnum.docFreq();
        } else {
            return 0;
        }
    }
    // otherwise do it the naive way
    if (filter != null) {
        query = new BooleanQuery.Builder()
                .add(query, Occur.FILTER)
                .add(filter, Occur.FILTER)
                .build();
    }
    return context.searcher().count(query);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:SignificantTermsAggregatorFactory.java

示例10: doToQuery

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
    BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
    booleanQueryBuilder.setDisableCoord(disableCoord);
    addBooleanClauses(context, booleanQueryBuilder, mustClauses, BooleanClause.Occur.MUST);
    addBooleanClauses(context, booleanQueryBuilder, mustNotClauses, BooleanClause.Occur.MUST_NOT);
    addBooleanClauses(context, booleanQueryBuilder, shouldClauses, BooleanClause.Occur.SHOULD);
    addBooleanClauses(context, booleanQueryBuilder, filterClauses, BooleanClause.Occur.FILTER);
    BooleanQuery booleanQuery = booleanQueryBuilder.build();
    if (booleanQuery.clauses().isEmpty()) {
        return new MatchAllDocsQuery();
    }

    final String minimumShouldMatch;
    if (context.isFilter() && this.minimumShouldMatch == null && shouldClauses.size() > 0) {
        minimumShouldMatch = "1";
    } else {
        minimumShouldMatch = this.minimumShouldMatch;
    }
    Query query = Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
    return adjustPureNegative ? fixNegativeQueryIfNeeded(query) : query;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:BoolQueryBuilder.java

示例11: addBooleanClauses

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
private static void addBooleanClauses(QueryShardContext context, BooleanQuery.Builder booleanQueryBuilder,
                                      List<QueryBuilder> clauses, Occur occurs) throws IOException {
    for (QueryBuilder query : clauses) {
        Query luceneQuery = null;
        switch (occurs) {
            case MUST:
            case SHOULD:
                luceneQuery = query.toQuery(context);
                break;
            case FILTER:
            case MUST_NOT:
                luceneQuery = query.toFilter(context);
                break;
        }
        booleanQueryBuilder.add(new BooleanClause(luceneQuery, occurs));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:BoolQueryBuilder.java

示例12: applyMinimumShouldMatch

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
    if (minimumShouldMatch == null) {
        return query;
    }
    int optionalClauses = 0;
    for (BooleanClause c : query.clauses()) {
        if (c.getOccur() == BooleanClause.Occur.SHOULD) {
            optionalClauses++;
        }
    }

    int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
    if (0 < msm) {
        BooleanQuery.Builder builder = new BooleanQuery.Builder();
        builder.setDisableCoord(query.isCoordDisabled());
        for (BooleanClause clause : query) {
            builder.add(clause);
        }
        builder.setMinimumNumberShouldMatch(msm);
        return builder.build();
    } else {
        return query;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:Queries.java

示例13: testCrossFieldMultiMatchQuery

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
public void testCrossFieldMultiMatchQuery() throws IOException {
    QueryShardContext queryShardContext = indexService.newQueryShardContext(
            randomInt(20), null, () -> { throw new UnsupportedOperationException(); });
    queryShardContext.setAllowUnmappedFields(true);
    Query parsedQuery = multiMatchQuery("banon").field("name.first", 2).field("name.last", 3).field("foobar").type(MultiMatchQueryBuilder.Type.CROSS_FIELDS).toQuery(queryShardContext);
    try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) {
        Query rewrittenQuery = searcher.searcher().rewrite(parsedQuery);

        BooleanQuery.Builder expected = new BooleanQuery.Builder();
        expected.add(new TermQuery(new Term("foobar", "banon")), BooleanClause.Occur.SHOULD);
        Query tq1 = new BoostQuery(new TermQuery(new Term("name.first", "banon")), 2);
        Query tq2 = new BoostQuery(new TermQuery(new Term("name.last", "banon")), 3);
        expected.add(new DisjunctionMaxQuery(Arrays.<Query>asList(tq1, tq2), 0f), BooleanClause.Occur.SHOULD);
        assertEquals(expected.build(), rewrittenQuery);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:MultiMatchQueryTests.java

示例14: testBlendNoTermQuery

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
public void testBlendNoTermQuery() {
    FakeFieldType ft1 = new FakeFieldType();
    ft1.setName("foo");
    FakeFieldType ft2 = new FakeFieldType() {
        @Override
        public Query termQuery(Object value, QueryShardContext context) {
            return new MatchAllDocsQuery();
        }
    };
    ft2.setName("bar");
    Term[] terms = new Term[] { new Term("foo", "baz") };
    float[] boosts = new float[] {2};
    Query expectedClause1 = BlendedTermQuery.booleanBlendedQuery(terms, boosts, false);
    Query expectedClause2 = new BoostQuery(new MatchAllDocsQuery(), 3);
    Query expected = new BooleanQuery.Builder().setDisableCoord(true)
            .add(expectedClause1, Occur.SHOULD)
            .add(expectedClause2, Occur.SHOULD)
            .build();
    Query actual = MultiMatchQuery.blendTerm(
            indexService.newQueryShardContext(randomInt(20), null, () -> { throw new UnsupportedOperationException(); }),
            new BytesRef("baz"), null, 1f, new FieldAndFieldType(ft1, 2), new FieldAndFieldType(ft2, 3));
    assertEquals(expected, actual);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:MultiMatchQueryTests.java

示例15: constructWildcardQuery

import org.apache.lucene.search.BooleanClause.Occur; //导入依赖的package包/类
private static BooleanQuery constructWildcardQuery(String searchPhrase,
        List<String> fieldNames, String locale, String defaultLocale,
        boolean isDefaultLocaleHandling) {

    String[] splitStr = searchPhrase.split("\\s+");

    BooleanQuery booleanQuery = new BooleanQuery();

    for (String token : splitStr) {
        booleanQuery.add(
                prepareWildcardQueryForSingleToken(token, fieldNames,
                        locale, defaultLocale, isDefaultLocaleHandling),
                Occur.MUST);
    }

    return booleanQuery;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:LuceneQueryBuilder.java


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