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

Java TermsQuery类代码示例

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

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



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

示例1: getFilter

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
public Query getFilter() {
    boolean hasFilters = false;
    List<Term> termsList = new ArrayList<>();

    if (genre != null && genre.trim().length() > 0) {
        hasFilters = true;
        termsList.add(new Term(TrackField.GENRE.name(), genre.trim()));
    }

    if (year != null && year.trim().length() > 0) {
        hasFilters = true;
        termsList.add(new Term(TrackField.YEAR.name(), year.trim()));
    }

    if (hasFilters) {
        return new TermsQuery(termsList);
    }

    return null;
}
 
开发者ID:mpcontracting,项目名称:rpmjukebox,代码行数:21,代码来源:TrackFilter.java


示例2: shouldUseTermsQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Test
public void shouldUseTermsQuery() throws SyntaxError, IOException {
  when(localParamsMock.get("command")).thenReturn("smembers");
  when(localParamsMock.get("key")).thenReturn("simpleKey");
  when(localParamsMock.get("ignoreScore")).thenReturn("true");
  when(localParamsMock.getBool("useAnalyzer", false)).thenReturn(true);
  when(localParamsMock.get(QueryParsing.V)).thenReturn("string_field");
  when(requestMock.getSchema()).thenReturn(schema);
  when(schema.getQueryAnalyzer()).thenReturn(new WhitespaceAnalyzer());
  when(jedisMock.smembers(anyString())).thenReturn(new HashSet<>(Arrays.asList("123 124", "321", "322", "323", "324",
          "325", "326", "327", "328", "329", "330", "331", "332", "333", "334", "335", "336", "337", "338")));
  redisQParser = new RedisQParser("string_field", localParamsMock, paramsMock, requestMock, commandHandler);
  final Query query = redisQParser.parse();
  verify(jedisMock).smembers("simpleKey");
  IndexSearcher searcher = new IndexSearcher(new MultiReader());
  Query rewrittenQuery = searcher.rewrite(query);
  assertTrue(rewrittenQuery instanceof TermsQuery);
}
 
开发者ID:sematext,项目名称:solr-redis,代码行数:19,代码来源:TestRedisQParser.java


示例3: termsQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
private static Query termsQuery(String columnName, Literal arrayLiteral) {
    List<Term> terms = getTerms(columnName, arrayLiteral);
    if (terms.isEmpty()) {
        return new MatchNoDocsQuery();
    }
    return new TermsQuery(terms);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:LuceneQueryBuilder.java


示例4: apply

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Override
public Query apply(Function input, Context context) {
    Tuple<Reference, Literal> tuple = super.prepare(input);
    if (tuple == null) {
        return null;
    }
    Reference reference = tuple.v1();
    Literal literal = tuple.v2();
    String columnName = reference.info().ident().columnIdent().fqn();
    if (DataTypes.isCollectionType(reference.valueType()) && DataTypes.isCollectionType(literal.valueType())) {
        List<Term> terms = getTerms(columnName, literal);
        if (terms.isEmpty()) {
            return genericFunctionFilter(input, context);
        }
        Query termsQuery = new TermsQuery(terms);

        // wrap boolTermsFilter and genericFunction filter in an additional BooleanFilter to control the ordering of the filters
        // termsFilter is applied first
        // afterwards the more expensive genericFunctionFilter
        BooleanQuery.Builder filterClauses = new BooleanQuery.Builder();
        filterClauses.add(termsQuery, BooleanClause.Occur.MUST);
        filterClauses.add(genericFunctionFilter(input, context), BooleanClause.Occur.MUST);
        return filterClauses.build();
    }
    QueryBuilderHelper builder = QueryBuilderHelper.forType(tuple.v1().valueType());
    return builder.eq(columnName, tuple.v2().value());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:28,代码来源:LuceneQueryBuilder.java


示例5: isCostly

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
static boolean isCostly(Query query) {
  // This does not measure the cost of iterating over the filter (for this we
  // already have the DocIdSetIterator#cost API) but the cost to build the
  // DocIdSet in the first place
  // ========== BEGIN EDIT ==========
  /*return query instanceof MultiTermQuery ||
      query instanceof MultiTermQueryConstantScoreWrapper;*/
  return query instanceof MultiTermQuery ||
      query instanceof MultiTermQueryConstantScoreWrapper ||
      query instanceof TermsQuery;
  // ========== END EDIT ==========
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:XUsageTrackingQueryCachingPolicy.java


示例6: handleExclude

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
private static void handleExclude(BooleanQuery boolQuery, List<Item> likeItems) {
    // artificial docs get assigned a random id and should be disregarded
    List<BytesRef> uids = new ArrayList<>();
    for (Item item : likeItems) {
        if (item.doc() != null) {
            continue;
        }
        uids.add(createUidAsBytes(item.type(), item.id()));
    }
    if (!uids.isEmpty()) {
        TermsQuery query = new TermsQuery(UidFieldMapper.NAME, uids.toArray(new BytesRef[0]));
        boolQuery.add(query, BooleanClause.Occur.MUST_NOT);
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:15,代码来源:MoreLikeThisQueryParser.java


示例7: termQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Override
public Query termQuery(Object value, @Nullable QueryParseContext context) {
    if (indexOptions() != IndexOptions.NONE || context == null) {
        return super.termQuery(value, context);
    }
    final BytesRef[] uids = Uid.createUidsForTypesAndId(context.queryTypes(), value);
    return new TermsQuery(UidFieldMapper.NAME, uids);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:IdFieldMapper.java


示例8: termsQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Override
public Query termsQuery(List values, @Nullable QueryParseContext context) {
    if (indexOptions() != IndexOptions.NONE || context == null) {
        return super.termsQuery(values, context);
    }
    return new TermsQuery(UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values));
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:IdFieldMapper.java


示例9: termsQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
public Query termsQuery(List values, @Nullable QueryParseContext context) {
    BytesRef[] bytesRefs = new BytesRef[values.size()];
    for (int i = 0; i < bytesRefs.length; i++) {
        bytesRefs[i] = indexedValueForSearch(values.get(i));
    }
    return new TermsQuery(names.indexName(), bytesRefs);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:MappedFieldType.java


示例10: addChromosomeFilter

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
private void addChromosomeFilter(BooleanQuery.Builder builder) {
    if (CollectionUtils.isNotEmpty(chromosomeIds)) {
        List<Term> chromosomeTerms = chromosomeIds.stream().map(id -> new Term(FeatureIndexFields.CHROMOSOME_ID
                        .getFieldName(), id.toString())).collect(Collectors.toList());
        builder.add(new TermsQuery(chromosomeTerms), BooleanClause.Occur.MUST);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:8,代码来源:VcfFilterForm.java


示例11: addVcfFileFilter

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
private void addVcfFileFilter(BooleanQuery.Builder builder) {
    if (vcfFileIds != null && !vcfFileIds.isEmpty()) {
        List<Term> terms = vcfFileIds.stream()
                .map(vcfFileId -> new Term(FeatureIndexFields.FILE_ID.getFieldName(), vcfFileId.toString()))
                .collect(Collectors.toList());
        TermsQuery termsQuery = new TermsQuery(terms);
        builder.add(termsQuery, BooleanClause.Occur.MUST);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:10,代码来源:VcfFilterForm.java


示例12: shouldInitialiseWithGenre

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Test
public void shouldInitialiseWithGenre() {
    TrackFilter trackFilter = new TrackFilter("Genre", null);
    TermsQuery termsQuery = (TermsQuery)trackFilter.getFilter();

    assertThat("Filter query should have 1 term", termsQuery.getTermData().size(), equalTo(1l));
}
 
开发者ID:mpcontracting,项目名称:rpmjukebox,代码行数:8,代码来源:TrackFilterTest.java


示例13: shouldInitialiseWithYear

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Test
public void shouldInitialiseWithYear() {
    TrackFilter trackFilter = new TrackFilter(null, "2000");
    TermsQuery termsQuery = (TermsQuery)trackFilter.getFilter();

    assertThat("Filter query should have 1 term", termsQuery.getTermData().size(), equalTo(1l));
}
 
开发者ID:mpcontracting,项目名称:rpmjukebox,代码行数:8,代码来源:TrackFilterTest.java


示例14: shouldInitialiseWithGenreAndYear

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Test
public void shouldInitialiseWithGenreAndYear() {
    TrackFilter trackFilter = new TrackFilter("Genre", "2000");
    TermsQuery termsQuery = (TermsQuery)trackFilter.getFilter();

    assertThat("Filter query should have 2 terms", termsQuery.getTermData().size(), equalTo(2l));
}
 
开发者ID:mpcontracting,项目名称:rpmjukebox,代码行数:8,代码来源:TrackFilterTest.java


示例15: termsQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Override
public Query termsQuery(List<?> values, QueryShardContext context) {
    failIfNotIndexed();
    BytesRef[] bytesRefs = new BytesRef[values.size()];
    for (int i = 0; i < bytesRefs.length; i++) {
        bytesRefs[i] = indexedValueForSearch(values.get(i));
    }
    return new TermsQuery(name(), bytesRefs);
}
 
开发者ID:jprante,项目名称:elasticsearch-analysis-reference,代码行数:10,代码来源:ReferenceMapper.java


示例16: testSearchIndex

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Test
public void testSearchIndex() throws Exception {
  try (LuceneSearchIndex index = new LuceneSearchIndex("", "test", true)) {

    final Document doc1 = new Document();
    doc1.add(new StringField(IndexedStore.ID_FIELD_NAME, new BytesRef("1".getBytes()), Store.YES));
    doc1.add(new StringField("ds", "space1.ds1", Field.Store.NO));
    doc1.add(new StringField("job", "job1", Field.Store.YES));
    // since we want to sort on version add docvalues
    doc1.add(new StringField("version", "v1", Field.Store.NO));
    doc1.add(new SortedDocValuesField("version", new BytesRef("v1")));
    doc1.add(new StringField("foo", "bar1", Store.NO));
    doc1.add(new SortedDocValuesField("foo", new BytesRef("bar1")));

    final Document doc2 = new Document();
    doc2.add(new StringField(IndexedStore.ID_FIELD_NAME, new BytesRef("2".getBytes()), Store.YES));
    doc2.add(new StringField("ds", "space1.ds1", Field.Store.NO));
    doc2.add(new StringField("job", "job3", Field.Store.YES));
    doc2.add(new StringField("version", "v2", Field.Store.NO));
    doc2.add(new SortedDocValuesField("version", new BytesRef("v2")));
    doc2.add(new StringField("foo", "bar2", Store.NO));
    doc2.add(new SortedDocValuesField("foo", new BytesRef("bar2")));

    final Document doc3 = new Document();
    doc3.add(new StringField(IndexedStore.ID_FIELD_NAME, new BytesRef("3".getBytes()), Store.YES));
    doc3.add(new StringField("ds", "space2.ds2", Field.Store.NO));
    doc3.add(new StringField("job", "job2", Field.Store.YES));
    doc3.add(new StringField("version", "v1", Field.Store.NO));
    doc3.add(new SortedDocValuesField("version", new BytesRef("v1")));

    index.add(doc1);

    assertEquals(1, index.count(new TermQuery(new Term("ds", "space1.ds1"))));
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space1.ds1")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v1")), BooleanClause.Occur.MUST));
    assertEquals(1, index.count(builder.build()));

    assertEquals(0, index.count(new TermQuery(new Term("ds", "space2.ds2"))));
    assertEquals(0, index.count(new TermQuery(new Term("version", "v2"))));

    builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space1.ds1")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v2")), BooleanClause.Occur.MUST));
    assertEquals(0, index.count(builder.build()));
    assertEquals(1, index.count(new TermsQuery(new Term("ds", "space1.ds1"), new Term("version1", "v2"))));

    index.add(doc2);
    index.add(doc3);

    assertEquals(2, index.count(new TermQuery(new Term("ds", "space1.ds1"))));
    assertEquals(1, index.count(new TermQuery(new Term("ds", "space2.ds2"))));

    builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space2.ds2")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v1")), BooleanClause.Occur.MUST));
    assertEquals(1, index.count(builder.build()));

    builder = new BooleanQuery.Builder();
    builder.add(new BooleanClause(new TermQuery(new Term("ds", "space1.ds1")), BooleanClause.Occur.MUST));
    builder.add(new BooleanClause(new TermQuery(new Term("version", "v1")), BooleanClause.Occur.MUST));
    assertEquals(1, index.count(builder.build()));

    Sort sorter = new Sort();
    sorter.setSort(new SortField("version", SortField.Type.STRING));
    Collection<Document> documents = index.searchForDocuments(new TermQuery(new Term("ds", "space1.ds1")), 1000, sorter);
    assertEquals(2, documents.size());

    // exists queries
    assertEquals(2, index.count(LuceneQueryConverter.INSTANCE.toLuceneQuery(SearchQueryUtils.newExistsQuery("foo"))));
    assertEquals(1, index.count(LuceneQueryConverter.INSTANCE.toLuceneQuery(SearchQueryUtils.newDoesNotExistQuery("foo"))));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:74,代码来源:TestLuceneIndexer.java


示例17: searchGenesInVcfFilesInProject

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
/**
 * Searches gene IDs, affected by variations in specified VCF files in a specified project
 *
 * @param projectId an ID of a project to search genes
 * @param gene a prefix of a gene ID to search
 * @param vcfFileIds a {@code List} of IDs of VCF files in project to search for gene IDs
 * @return a {@code Set} of gene IDs, that are affected by some variations in specified VCf files
 * @throws IOException
 */
public Set<String> searchGenesInVcfFilesInProject(long projectId, String gene, List<Long> vcfFileIds) throws
        IOException {
    if (vcfFileIds == null || vcfFileIds.isEmpty()) {
        return Collections.emptySet();
    }

    BooleanQuery.Builder builder = new BooleanQuery.Builder();

    PrefixQuery geneIdPrefixQuery = new PrefixQuery(new Term(FeatureIndexFields.GENE_ID.getFieldName(),
            gene.toLowerCase()));
    PrefixQuery geneNamePrefixQuery = new PrefixQuery(new Term(FeatureIndexFields.GENE_NAME.getFieldName(),
                                                               gene.toLowerCase()));
    BooleanQuery.Builder geneIdOrNameQuery = new BooleanQuery.Builder();
    geneIdOrNameQuery.add(geneIdPrefixQuery, BooleanClause.Occur.SHOULD);
    geneIdOrNameQuery.add(geneNamePrefixQuery, BooleanClause.Occur.SHOULD);

    builder.add(geneIdOrNameQuery.build(), BooleanClause.Occur.MUST);

    List<Term> terms = vcfFileIds.stream()
            .map(vcfFileId -> new Term(FeatureIndexFields.FILE_ID.getFieldName(), vcfFileId.toString()))
            .collect(Collectors.toList());
    TermsQuery termsQuery = new TermsQuery(terms);
    builder.add(termsQuery, BooleanClause.Occur.MUST);
    BooleanQuery query =  builder.build();

    Set<String> geneIds;

    try (
        Directory index = fileManager.getIndexForProject(projectId);
        IndexReader reader = DirectoryReader.open(index)
    ) {
        if (reader.numDocs() == 0) {
            return Collections.emptySet();
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        final TopDocs docs = searcher.search(query, reader.numDocs());
        final ScoreDoc[] hits = docs.scoreDocs;

        geneIds = fetchGeneIds(hits, searcher);
    } catch (IOException e) {
        LOGGER.error(MessageHelper.getMessage(MessagesConstants.ERROR_FEATURE_INDEX_SEARCH_FAILED), e);
        return Collections.emptySet();
    }

    return geneIds;
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:57,代码来源:FeatureIndexDao.java


示例18: searchGenesInVcfFilesInProject

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
/**
 * Searches gene IDs, affected by variations in specified VCF files in a specified project
 *
 * @param projectId an ID of a project to search genes
 * @param gene a prefix of a gene ID to search
 * @param vcfFileIds a {@code List} of IDs of VCF files in project to search for gene IDs
 * @return a {@code Set} of gene IDs, that are affected by some variations in specified VCf files
 * @throws IOException
 */
public Set<String> searchGenesInVcfFilesInProject(long projectId, String gene, List<Long> vcfFileIds) throws
        IOException {
    if (vcfFileIds == null || vcfFileIds.isEmpty()) {
        return Collections.emptySet();
    }

    BooleanQuery.Builder builder = new BooleanQuery.Builder();

    PrefixQuery geneIdPrefixQuery = new PrefixQuery(new Term(FeatureIndexFields.GENE_ID.getFieldName(),
            gene.toLowerCase()));
    PrefixQuery geneNamePrefixQuery = new PrefixQuery(new Term(FeatureIndexFields.GENE_NAME.getFieldName(),
            gene.toLowerCase()));
    BooleanQuery.Builder geneIdOrNameQuery = new BooleanQuery.Builder();
    geneIdOrNameQuery.add(geneIdPrefixQuery, BooleanClause.Occur.SHOULD);
    geneIdOrNameQuery.add(geneNamePrefixQuery, BooleanClause.Occur.SHOULD);

    builder.add(geneIdOrNameQuery.build(), BooleanClause.Occur.MUST);

    List<Term> terms = vcfFileIds.stream()
            .map(vcfFileId -> new Term(FeatureIndexFields.FILE_ID.getFieldName(), vcfFileId.toString()))
            .collect(Collectors.toList());
    TermsQuery termsQuery = new TermsQuery(terms);
    builder.add(termsQuery, BooleanClause.Occur.MUST);
    BooleanQuery query =  builder.build();

    Set<String> geneIds;

    try (
            Directory index = fileManager.getIndexForProject(projectId);
            IndexReader reader = DirectoryReader.open(index)
    ) {
        if (reader.numDocs() == 0) {
            return Collections.emptySet();
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        final TopDocs docs = searcher.search(query, reader.numDocs());
        final ScoreDoc[] hits = docs.scoreDocs;

        geneIds = fetchGeneIds(hits, searcher);
    } catch (IOException e) {
        LOGGER.error(getMessage(MessagesConstants.ERROR_FEATURE_INDEX_SEARCH_FAILED), e);
        return Collections.emptySet();
    }

    return geneIds;
}
 
开发者ID:epam,项目名称:NGB,代码行数:57,代码来源:FeatureIndexDao.java


示例19: makeQuery

import org.apache.lucene.queries.TermsQuery; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
Query makeQuery(String fname, Iterator<BytesRef> it) {
  return new TermsQuery(fname, IteratorUtils.toList(it));
}
 
开发者ID:flaxsearch,项目名称:BioSolr,代码行数:6,代码来源:XJoinQParserPlugin.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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