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


Java PrefixQuery类代码示例

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


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

示例1: createFQNQuery

import org.apache.lucene.search.PrefixQuery; //导入依赖的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

示例2: addSearchTermQueries

import org.apache.lucene.search.PrefixQuery; //导入依赖的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

示例3: newPrefixQuery

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
/**
 * Dispatches to Lucene's SimpleQueryParser's newPrefixQuery, optionally
 * lowercasing the term first or trying to analyze terms
 */
@Override
public Query newPrefixQuery(String text) {
    BooleanQuery.Builder bq = new BooleanQuery.Builder();
    bq.setDisableCoord(true);
    for (Map.Entry<String,Float> entry : weights.entrySet()) {
        final String fieldName = entry.getKey();
        try {
            if (settings.analyzeWildcard()) {
                Query analyzedQuery = newPossiblyAnalyzedQuery(fieldName, text);
                if (analyzedQuery != null) {
                    bq.add(wrapWithBoost(analyzedQuery, entry.getValue()), BooleanClause.Occur.SHOULD);
                }
            } else {
                Term term = new Term(fieldName, getAnalyzer().normalize(fieldName, text));
                Query query = new PrefixQuery(term);
                bq.add(wrapWithBoost(query, entry.getValue()), BooleanClause.Occur.SHOULD);
            }
        } catch (RuntimeException e) {
            return rethrowUnlessLenient(e);
        }
    }
    return super.simplify(bq.build());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:28,代码来源:SimpleQueryParser.java

示例4: testAnalyzeWildcard

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
public void testAnalyzeWildcard() {
    SimpleQueryParser.Settings settings = new SimpleQueryParser.Settings();
    settings.analyzeWildcard(true);
    Map<String, Float> weights = new HashMap<>();
    weights.put("field1", 1.0f);
    SimpleQueryParser parser = new MockSimpleQueryParser(new StandardAnalyzer(), weights, -1, settings);
    for (Operator op : Operator.values()) {
        BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
        parser.setDefaultOperator(defaultOp);
        Query query = parser.parse("first foo-bar-foobar* last");
        Query expectedQuery =
            new BooleanQuery.Builder()
                .add(new BooleanClause(new TermQuery(new Term("field1", "first")), defaultOp))
                .add(new BooleanQuery.Builder()
                    .add(new BooleanClause(new TermQuery(new Term("field1", "foo")), defaultOp))
                    .add(new BooleanClause(new TermQuery(new Term("field1", "bar")), defaultOp))
                    .add(new BooleanClause(new PrefixQuery(new Term("field1", "foobar")), defaultOp))
                    .build(), defaultOp)
                .add(new BooleanClause(new TermQuery(new Term("field1", "last")), defaultOp))
                .build();
        assertThat(query, equalTo(expectedQuery));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:SimpleQueryParserTests.java

示例5: addGeneFilter

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
private void addGeneFilter(BooleanQuery.Builder builder) {
    if (genes != null && !genes.field.isEmpty()) {
        BooleanQuery.Builder genesBuilder = new BooleanQuery.Builder();
        for (int i = 0; i < genes.field.size(); i++) {
            PrefixQuery geneIdPrefixQuery = new PrefixQuery(new Term(FeatureIndexFields.GENE_ID.getFieldName(),
                    genes.field.get(i).toLowerCase()));
            PrefixQuery geneNamePrefixQuery = new PrefixQuery(
                new Term(FeatureIndexFields.GENE_NAME.getFieldName(), genes.field.get(i).toLowerCase()));
            BooleanQuery.Builder geneIdOrNameQuery = new BooleanQuery.Builder();
            geneIdOrNameQuery.add(geneIdPrefixQuery, BooleanClause.Occur.SHOULD);
            geneIdOrNameQuery.add(geneNamePrefixQuery, BooleanClause.Occur.SHOULD);

            genesBuilder.add(geneIdOrNameQuery.build(), genes.conjunction ? BooleanClause.Occur.MUST :
                    BooleanClause.Occur.SHOULD);
        }

        builder.add(genesBuilder.build(), BooleanClause.Occur.MUST);
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:20,代码来源:VcfFilterForm.java

示例6: prefixSearch

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String keywords) throws IOException {
    if (StringUtils.isEmpty(keywords) || keywords.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", keywords);
        return null;
    }
    Sort sort = new Sort(new SortField("downloadRank", SortField.INT, true));

    Term nameFldTerm = new Term(fieldName, keywords);
    PrefixQuery nameFldQuery = new PrefixQuery(nameFldTerm);

    NumericRangeQuery<Integer> catalogQuery = NumericRangeQuery.newIntRange("catalog",
            (int) EnumCatalog.SOFT.getCatalog(), (int) EnumCatalog.GAME.getCatalog(), true, true);
    BooleanQuery booleanQuery = new BooleanQuery();
    booleanQuery.add(catalogQuery, Occur.MUST);
    booleanQuery.add(nameFldQuery, Occur.MUST);

    TopDocs topDocs = quickTipsSearcher.search(booleanQuery, appConfig.getQuickTipsNum() * 2, sort);
    ScoreDoc[] docs = topDocs.scoreDocs;
    return docs;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:22,代码来源:QuickTipsServiceImpl.java

示例7: prefixSearch

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String q) throws IOException {
    if (StringUtils.isEmpty(q) || q.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", q);
        return null;
    }

    final TopDocs[] rstTopDocs = new TopDocs[2];
    final Query nameFldQuery = new PrefixQuery(new Term(NAME.getName(), q));
    rstTopDocs[0] = indexSearcher.search(nameFldQuery, appConfig.getQuickTipsNum() * 2, sort);

    final Query downLoadRankQuery = NumericRangeQuery.newIntRange(DOWNOLOAD_RANK.getName(), MIN_DOWNLOAD_RANK,
            Integer.MAX_VALUE, true, false);
    // 从下载量最高的1000条记录中,再过滤符合关键字的记录
    rstTopDocs[1] = indexSearcher.search(downLoadRankQuery, MAX_TOP, sort);
    TopDocs rst = TopDocsUtil.mergeDuplicateDocId(TopDocs.merge(sort, MAX_TOP + appConfig.getQuickTipsNum() * 2,
            rstTopDocs));
    if (rst != null) {
        return rst.scoreDocs;
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:23,代码来源:QuickTipsService1Impl.java

示例8: prefixSearch

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
@Override
public ScoreDoc[] prefixSearch(String q) throws IOException {
    if (StringUtils.isEmpty(q) || q.length() > appConfig.getKeywordMaxLength()) {
        logger.error("empty keywords or over-length! {}", q);
        return null;
    }
    
    final TopDocs[] rstTopDocs = new TopDocs[2];
    final Query nameFldQuery = new PrefixQuery(new Term(NAME.getName(), q));
    rstTopDocs[0] = indexSearcher.search(nameFldQuery, appConfig.getQuickTipsNum() * 2, sort);

    final Query downLoadRankQuery = NumericRangeQuery.newIntRange(DOWNOLOAD_RANK.getName(), MIN_DOWNLOAD_RANK, Integer.MAX_VALUE, true, false);
    //从下载量最高的1000条记录中,再过滤符合关键字的记录
    rstTopDocs[1] = indexSearcher.search(downLoadRankQuery, MAX_TOP, sort);
    TopDocs rst = TopDocsUtil.mergeDuplicateDocId(TopDocs.merge(sort, MAX_TOP + appConfig.getQuickTipsNum() * 2, rstTopDocs));
    if(rst != null) {
        return rst.scoreDocs;
    }
    return null;
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:21,代码来源:QuickTipsServiceImpl.java

示例9: execute

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
@Override
public void execute(boolean interactive) throws CommandException {
	logger.debug("Executing search command");
	try (IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(indexPath)))) {
		IndexSearcher searcher = new IndexSearcher(reader);
		QueryParser queryParser = new QueryParser("contents", new StandardAnalyzer());
		BooleanQuery booleanQuery = new BooleanQuery.Builder()
		        .add(new PrefixQuery(new Term("contributor", queryString)), BooleanClause.Occur.SHOULD)
		        .add(queryParser.parse(String.format("%s*", queryString)), BooleanClause.Occur.SHOULD).build();
		doPagingSearch(new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)), searcher,
		        booleanQuery, 10, interactive);

	} catch (IOException | ParseException e) {
		logger.error("Exception while executing search command.", e);
		throw new CommandException("Error while executing command. Excution failed.", e);
	}

}
 
开发者ID:Abd4llA,项目名称:wikisearch,代码行数:19,代码来源:LuceneSearchCommand.java

示例10: testNoSuchMultiTermsInSpanFirst

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
public void testNoSuchMultiTermsInSpanFirst() throws Exception {
  //this hasn't been a problem  
  FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
  SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
  SpanQuery spanFirst = new SpanFirstQuery(spanNoSuch, 10);
 
  assertEquals(0, searcher.search(spanFirst, 10).totalHits);
  
  WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
  SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
  spanFirst = new SpanFirstQuery(spanWCNoSuch, 10);
  assertEquals(0, searcher.search(spanFirst, 10).totalHits);

  RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
  SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
  spanFirst = new SpanFirstQuery(spanRgxNoSuch, 10);
  assertEquals(0, searcher.search(spanFirst, 10).totalHits);
  
  PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
  SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
  spanFirst = new SpanFirstQuery(spanPrfxNoSuch, 10);
  assertEquals(0, searcher.search(spanFirst, 10).totalHits);
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestSpanMultiTermQueryWrapper.java

示例11: getLOINCMatches

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
/**
 * Enhancements: match any LOINC term (includes synonyms)? permit any loinc code (not just chemistries)
 * @param search
 * @return
 */
private Map<String,String> getLOINCMatches(String search) {
	// try to match the search terms against a narrow portion of the LOINC higherarchy
	BooleanQuery q1 = new BooleanQuery();
	q1.add(new TermQuery(new Term("parent", LNC_CHEM)), BooleanClause.Occur.MUST);
	q1.add(new PrefixQuery(new Term("term", search)), BooleanClause.Occur.MUST);
	
	// match any exact loinc code
	BooleanQuery q2 = new BooleanQuery();
	q2.add(new TermQuery(new Term("sab", "lnc")), BooleanClause.Occur.MUST);
	q2.add(new TermQuery(new Term("code", search)), BooleanClause.Occur.MUST);
	
	BooleanQuery q = new BooleanQuery();
	q.add(q1, BooleanClause.Occur.SHOULD);
	q.add(q2, BooleanClause.Occur.SHOULD);
	
	Map<String,String> ret = new HashMap<>();
	for (String urn : eng.search(q)) {
		String desc = eng.getDescription(urn);
		ret.put(urn, desc);
	}
	return ret;
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:28,代码来源:LOINCSearchFrame.java

示例12: addTextAndImageLinks

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
private void addTextAndImageLinks(List<Link> links, DocumentIndex reindexingIndex, UserDomainObject user,
                                  HttpServletRequest request, IntRange range) {
    BooleanQuery query = new BooleanQuery();
    query.add(new PrefixQuery(new Term(DocumentIndex.FIELD__NONSTRIPPED_TEXT, "http")), Occur.SHOULD);
    query.add(new PrefixQuery(new Term(DocumentIndex.FIELD__NONSTRIPPED_TEXT, "href")), Occur.SHOULD);
    query.add(new PrefixQuery(new Term(DocumentIndex.FIELD__IMAGE_LINK_URL, "http")), Occur.SHOULD);

    List textDocuments = reindexingIndex.search(new SimpleDocumentQuery(query), user);

    for (Object textDocument1 : textDocuments) {
        TextDocumentDomainObject textDocument = (TextDocumentDomainObject) textDocument1;
        if (!range.containsInteger(textDocument.getId())) {
            continue;
        }
        addTextLinks(links, textDocument, request);
        addImageLinks(links, textDocument, request);
    }
}
 
开发者ID:imCodePartnerAB,项目名称:imcms,代码行数:19,代码来源:LinkCheck.java

示例13: rewrite

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
public static Query rewrite(org.apache.lucene.search.Query q, Set<String> intFields) {
    if (q instanceof TermQuery) {
        return rewrite((TermQuery)q, intFields);
    } else if (q instanceof BooleanQuery) {
        return rewrite((BooleanQuery)q, intFields);
    } else if (q instanceof RangeQuery) {
        return rewrite((RangeQuery)q, intFields);
    } else if (q instanceof ConstantScoreRangeQuery) {
        return rewrite((ConstantScoreRangeQuery)q, intFields);
    } else if (q instanceof PrefixQuery) {
        return rewrite((PrefixQuery)q, intFields);
    } else if (q instanceof PhraseQuery) {
        return rewrite((PhraseQuery)q, intFields);
    }
    throw new IllegalArgumentException("unsupported lucene query type: " + q.getClass().getSimpleName());
}
 
开发者ID:indeedeng,项目名称:imhotep,代码行数:17,代码来源:LuceneQueryTranslator.java

示例14: testString

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
@Test
public void testString() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperString());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    PrefixCondition prefixCondition = new PrefixCondition(0.5f, "name", "tr");
    Query query = prefixCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("tr", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:18,代码来源:PrefixConditionTest.java

示例15: testInetV4

import org.apache.lucene.search.PrefixQuery; //导入依赖的package包/类
@Test
public void testInetV4() {

    Map<String, ColumnMapper> map = new HashMap<>();
    map.put("name", new ColumnMapperInet());
    Schema mappers = new Schema(map, null, EnglishAnalyzer.class.getName());

    PrefixCondition wildcardCondition = new PrefixCondition(0.5f, "name", "192.168.");
    Query query = wildcardCondition.query(mappers);

    Assert.assertNotNull(query);
    Assert.assertEquals(PrefixQuery.class, query.getClass());
    PrefixQuery luceneQuery = (PrefixQuery) query;
    Assert.assertEquals("name", luceneQuery.getField());
    Assert.assertEquals("192.168.", luceneQuery.getPrefix().text());
    Assert.assertEquals(0.5f, query.getBoost(), 0);
}
 
开发者ID:Stratio,项目名称:stratio-cassandra,代码行数:18,代码来源:PrefixConditionTest.java


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