本文整理了Java中org.apache.lucene.search.BooleanQuery.setBoost()
方法的一些代码示例,展示了BooleanQuery.setBoost()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BooleanQuery.setBoost()
方法的具体详情如下:
包路径:org.apache.lucene.search.BooleanQuery
类名称:BooleanQuery
方法名:setBoost
暂无
代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene
public Query rewrite(IndexReader reader) {
if (termArrays.size() == 1) { // optimize one-term case
Term[] terms = (Term[])termArrays.get(0);
BooleanQuery boq = new BooleanQuery(true);
for (int i=0; i<terms.length; i++) {
boq.add(new TermQuery(terms[i]), BooleanClause.Occur.SHOULD);
}
boq.setBoost(getBoost());
return boq;
} else {
return this;
}
}
代码示例来源:origin: org.apache.lucene/lucene-core-jfrog
public Query rewrite(IndexReader reader) {
if (termArrays.size() == 1) { // optimize one-term case
Term[] terms = (Term[])termArrays.get(0);
BooleanQuery boq = new BooleanQuery(true);
for (int i=0; i<terms.length; i++) {
boq.add(new TermQuery(terms[i]), BooleanClause.Occur.SHOULD);
}
boq.setBoost(getBoost());
return boq;
} else {
return this;
}
}
代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core
ElevationObj( String qstr, List<String> elevate, List<String> exclude ) throws IOException
{
this.text = qstr;
this.analyzed = getAnalyzedQuery( this.text );
this.include = new BooleanQuery();
this.include.setBoost( 0 );
this.priority = new HashMap<String, Integer>();
int max = elevate.size()+5;
for( String id : elevate ) {
TermQuery tq = new TermQuery( new Term( idField, id ) );
include.add( tq, BooleanClause.Occur.SHOULD );
this.priority.put( id, max-- );
}
if( exclude == null || exclude.isEmpty() ) {
this.exclude = null;
}
else {
this.exclude = new BooleanClause[exclude.size()];
for( int i=0; i<exclude.size(); i++ ) {
TermQuery tq = new TermQuery( new Term( idField, exclude.get(i) ) );
this.exclude[i] = new BooleanClause( tq, BooleanClause.Occur.MUST_NOT );
}
}
this.comparatorSource = new ElevationComparatorSource(priority);
}
}
代码示例来源:origin: lucene/lucene
protected Weight createWeight(Searcher searcher) {
if (termArrays.size() == 1) { // optimize one-term case
Term[] terms = (Term[])termArrays.get(0);
BooleanQuery boq = new BooleanQuery();
for (int i=0; i<terms.length; i++) {
boq.add(new TermQuery(terms[i]), false, false);
}
boq.setBoost(getBoost());
return boq.createWeight(searcher);
}
return new PhrasePrefixWeight(searcher);
}
代码示例来源:origin: ajermakovics/eclipse-instasearch
private Query getFilterQuery(Query originalQuery, Field field, Set<String> values)
{
BooleanQuery boolQuery = new BooleanQuery();
if( originalQuery != null )
{
boolQuery.add(originalQuery, Occur.SHOULD); // original term
boolQuery.setBoost( originalQuery.getBoost() );
}
for(String value: values)
boolQuery.add(new TermQuery(field.createTerm(value)), Occur.SHOULD);
return boolQuery;
}
代码示例来源:origin: com.senseidb/sensei-core
query.setBoost((float) jsonQuery.optDouble(BOOST_PARAM, 1.0));
代码示例来源:origin: org.dspace.dependencies.solr/dspace-solr-core
} else {
BooleanQuery newBq = new BooleanQuery(bq.isCoordDisabled());
newBq.setBoost(bq.getBoost());
代码示例来源:origin: org.infinispan/infinispan-embedded-query
@Override
public BooleanQuery readObject(final ObjectInput input) throws IOException, ClassNotFoundException {
final boolean disableCoord = input.readBoolean();
final float boost = input.readFloat();
final int minimumNumberShouldMatch = UnsignedNumeric.readUnsignedInt(input);
final int numberOfClauses = UnsignedNumeric.readUnsignedInt(input);
BooleanQuery.Builder unserialized = new BooleanQuery.Builder()
.setDisableCoord(disableCoord)
.setMinimumNumberShouldMatch(minimumNumberShouldMatch);
assureNumberOfClausesLimit(numberOfClauses);
for (int i = 0; i < numberOfClauses; i++) {
appendReadClause(input, unserialized);
}
BooleanQuery booleanQuery = unserialized.build();
booleanQuery.setBoost(boost);
return booleanQuery;
}
代码示例来源:origin: org.infinispan/infinispan-query
@Override
public BooleanQuery readObject(final ObjectInput input) throws IOException, ClassNotFoundException {
final boolean disableCoord = input.readBoolean();
final float boost = input.readFloat();
final int minimumNumberShouldMatch = UnsignedNumeric.readUnsignedInt(input);
final int numberOfClauses = UnsignedNumeric.readUnsignedInt(input);
BooleanQuery.Builder unserialized = new BooleanQuery.Builder()
.setDisableCoord(disableCoord)
.setMinimumNumberShouldMatch(minimumNumberShouldMatch);
assureNumberOfClausesLimit(numberOfClauses);
for (int i = 0; i < numberOfClauses; i++) {
appendReadClause(input, unserialized);
}
BooleanQuery booleanQuery = unserialized.build();
booleanQuery.setBoost(boost);
return booleanQuery;
}
代码示例来源:origin: ajermakovics/eclipse-instasearch
@Override
public Query visit(TermQuery termQuery, Field field) {
if( clauseCount == 0 ) { // at last query
Term term = termQuery.getTerm();
if( term.text().length() < minTermLength ) // exclude short queries to avoid clause overload
return termQuery;
PrefixQuery prefixQuery = new PrefixQuery(term);
prefixQuery.setBoost( termQuery.getBoost()/4f );
BooleanQuery boolQuery = new BooleanQuery();
boolQuery.add(termQuery, Occur.SHOULD);
boolQuery.add(prefixQuery, Occur.SHOULD);
boolQuery.setBoost( termQuery.getBoost() );
return boolQuery;
}
return termQuery;
}
代码示例来源:origin: rdelbru/SIREn
@Override
public org.apache.lucene.search.BooleanQuery toQuery(final boolean proxy) throws QueryNodeException {
final org.apache.lucene.search.BooleanQuery query = new org.apache.lucene.search.BooleanQuery(true);
// convert clauses
for (final QueryClause clause : clauses) {
// wrap node query into a lucene proxy query
final Query q = new LuceneProxyNodeQuery((org.sindice.siren.search.node.NodeQuery) clause.getQuery().toQuery(false));
query.add(q, clause.getBooleanOccur());
}
// add boost
if (this.hasBoost()) {
query.setBoost(this.getBoost());
}
return query;
}
代码示例来源:origin: hibernate/hibernate-search
@Test
@SuppressWarnings("unchecked")
public void testBooleanQueryWithBoost() {
try ( Session session = openSession() ) {
FullTextSession fullTextSession = Search.getFullTextSession( session );
TermQuery termQuery = new TermQuery( new Term( "message", "import" ) );
termQuery.setBoost( 3.0f );
BooleanQuery testedQuery = new BooleanQuery.Builder().add( termQuery, Occur.SHOULD ).build();
testedQuery.setBoost( 2.0f );
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(
testedQuery, Letter.class );
String queryString = fullTextQuery.getQueryString();
assertJsonEquals( "{'query':{'bool':{'should':{'term':{'message':{'value':'import','boost':3.0}}},'boost':2.0}}}", queryString );
List<Letter> letters = fullTextQuery.list();
assertThat( letters ).hasSize( 1 );
assertThat( letters ).extracting( "message" ).containsExactly( "Important letter" );
}
}
代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene
/**
* Substitutes one term in the term query for another.
*
* <p>This method only creates new query object if required; it does not modify the given query.
*
* @param query the query where the substitution should occur.
* @param original the original term to replace.
* @param replacement the term it should be replaced with.
*
* @return A new term query where the term has been substituted;
* or the same query if no substitution was needed.
*/
@Beta
public static Query substitute(BooleanQuery query, Term original, Term replacement) {
BooleanQuery q = new BooleanQuery();
for (BooleanClause clause : query.getClauses()) {
Query qx = substitute(clause.getQuery(), original, replacement);
q.add(qx, clause.getOccur());
}
q.setBoost(query.getBoost());
return q;
}
代码示例来源:origin: ajermakovics/eclipse-instasearch
bq.add(phraseQuery, Occur.SHOULD);
bq.add(boolQuery, Occur.SHOULD);
bq.setBoost(boolQuery.getBoost());
boolQuery.setBoost( phraseQuery.getBoost()*0.5f );
代码示例来源:origin: harbby/presto-connectors
private Query createQuery(XMoreLikeThis mlt) throws IOException {
BooleanQuery.Builder bqBuilder = new BooleanQuery.Builder();
if (this.likeFields != null) {
Query mltQuery = mlt.like(this.likeFields);
mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD);
}
if (this.likeText != null) {
Reader[] readers = new Reader[likeText.length];
for (int i = 0; i < readers.length; i++) {
readers[i] = new FastStringReader(likeText[i]);
}
//LUCENE 4 UPGRADE this mapps the 3.6 behavior (only use the first field)
Query mltQuery = mlt.like(moreLikeFields[0], readers);
mltQuery = Queries.applyMinimumShouldMatch((BooleanQuery) mltQuery, minimumShouldMatch);
bqBuilder.add(mltQuery, BooleanClause.Occur.SHOULD);
}
BooleanQuery bq = bqBuilder.build();
bq.setBoost(getBoost());
return bq;
}
代码示例来源:origin: harbby/presto-connectors
public static BooleanQuery 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);
BooleanQuery bq = builder.build();
bq.setBoost(query.getBoost());
query = bq;
}
return query;
}
代码示例来源:origin: com.atlassian.jira/jira-core
private BooleanQuery handleContainsMust(final QueryBucket queryBucket)
{
BooleanQuery query = new BooleanQuery();
// There is nothing to do here except complete a deep dive on each query
final BooleanQuery originalBooleanQuery = queryBucket.getOriginalBooleanQuery();
query.setBoost(originalBooleanQuery.getBoost());
query.setMinimumNumberShouldMatch(originalBooleanQuery.getMinimumNumberShouldMatch());
final BooleanClause[] booleanClauses = originalBooleanQuery.getClauses();
for (BooleanClause booleanClause : booleanClauses)
{
final Query subQuery = booleanClause.getQuery();
final BooleanClause.Occur subOccur = booleanClause.getOccur();
if (subQuery instanceof BooleanQuery)
{
query.add(transformBooleanQuery((BooleanQuery) subQuery), subOccur);
}
else
{
query.add((Query) subQuery.clone(), subOccur);
}
}
return query;
}
代码示例来源:origin: com.atlassian.jira/jira-core
private BooleanQuery handleOnlyNot(final QueryBucket queryBucket)
{
BooleanQuery query = new BooleanQuery();
BooleanQuery originalQuery = queryBucket.getOriginalBooleanQuery();
query.setBoost(originalQuery.getBoost());
query.setMinimumNumberShouldMatch(originalQuery.getMinimumNumberShouldMatch());
// We always add a match all in this case
query.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
for (Query origNotQuery : queryBucket.getNotQueries())
{
Query notQuery = (Query) origNotQuery.clone();
// Make sure we continue to dive the tree if we need to
if (notQuery instanceof BooleanQuery)
{
query.add(transformBooleanQuery((BooleanQuery) notQuery), BooleanClause.Occur.MUST_NOT);
}
else
{
query.add(notQuery, BooleanClause.Occur.MUST_NOT);
}
}
return query;
}
代码示例来源:origin: com.atlassian.jira/jira-core
query.setBoost(originalQuery.getBoost());
query.setMinimumNumberShouldMatch(originalQuery.getMinimumNumberShouldMatch());
notWithMatchAll.setBoost(notQuery.getBoost());
notWithMatchAll.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
代码示例来源:origin: ajermakovics/eclipse-instasearch
@Override
public Query visit(TermQuery termQuery, Field field) {
if( field != Field.CONTENTS )
return termQuery;
// turn term query into: (term* OR *term* OR term~)
Term term = termQuery.getTerm();
PrefixQuery prefixQuery = new PrefixQuery(term);
prefixQuery.setBoost( termQuery.getBoost() );
Term wildcardTerm = Field.CONTENTS.createTerm("*" + term.text() + "*");
WildcardQuery wildcardQuery = new WildcardQuery(wildcardTerm);
wildcardQuery.setBoost( termQuery.getBoost() * 0.75f );
FuzzyQuery fuzzyQuery = new FuzzyQuery( term );
fuzzyQuery.setBoost( termQuery.getBoost() * 0.5f );
BooleanQuery boolQuery = new BooleanQuery();
boolQuery.add(prefixQuery, Occur.SHOULD);
boolQuery.add(wildcardQuery, Occur.SHOULD);
boolQuery.add(fuzzyQuery, Occur.SHOULD);
boolQuery.setBoost( termQuery.getBoost() );
return boolQuery;
}
内容来源于网络,如有侵权,请联系作者删除!