本文整理汇总了Java中org.apache.lucene.search.PhraseQuery.setBoost方法的典型用法代码示例。如果您正苦于以下问题:Java PhraseQuery.setBoost方法的具体用法?Java PhraseQuery.setBoost怎么用?Java PhraseQuery.setBoost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.lucene.search.PhraseQuery
的用法示例。
在下文中一共展示了PhraseQuery.setBoost方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applySlop
import org.apache.lucene.search.PhraseQuery; //导入方法依赖的package包/类
private Query applySlop(Query q, int slop) {
if (q instanceof PhraseQuery) {
PhraseQuery pq = (PhraseQuery) q;
PhraseQuery.Builder builder = new PhraseQuery.Builder();
builder.setSlop(slop);
final Term[] terms = pq.getTerms();
final int[] positions = pq.getPositions();
for (int i = 0; i < terms.length; ++i) {
builder.add(terms[i], positions[i]);
}
pq = builder.build();
pq.setBoost(q.getBoost());
return pq;
} else if (q instanceof MultiPhraseQuery) {
((MultiPhraseQuery) q).setSlop(slop);
return q;
} else {
return q;
}
}
示例2: checkOverlap
import org.apache.lucene.search.PhraseQuery; //导入方法依赖的package包/类
private void checkOverlap( Collection<Query> expandQueries, Term[] src, Term[] dest, int slop, float boost ){
// beginning from 1 (not 0) is safe because that the PhraseQuery has multiple terms
// is guaranteed in flatten() method (if PhraseQuery has only one term, flatten()
// converts PhraseQuery to TermQuery)
for( int i = 1; i < src.length; i++ ){
boolean overlap = true;
for( int j = i; j < src.length; j++ ){
if( ( j - i ) < dest.length && !src[j].text().equals( dest[j-i].text() ) ){
overlap = false;
break;
}
}
if( overlap && src.length - i < dest.length ){
PhraseQuery pq = new PhraseQuery();
for( Term srcTerm : src )
pq.add( srcTerm );
for( int k = src.length - i; k < dest.length; k++ ){
pq.add( new Term( src[0].field(), dest[k].text() ) );
}
pq.setSlop( slop );
pq.setBoost( boost );
if(!expandQueries.contains( pq ) )
expandQueries.add( pq );
}
}
}
示例3: pq
import org.apache.lucene.search.PhraseQuery; //导入方法依赖的package包/类
protected Query pq( float boost, int slop, String field, String... texts ){
PhraseQuery query = new PhraseQuery();
for( String text : texts ){
query.add( new Term( field, text ) );
}
query.setBoost( boost );
query.setSlop( slop );
return query;
}
示例4: testCJKBoostedPhrase
import org.apache.lucene.search.PhraseQuery; //导入方法依赖的package包/类
public void testCJKBoostedPhrase() throws Exception {
// individual CJK chars as terms
SimpleCJKAnalyzer analyzer = new SimpleCJKAnalyzer();
PhraseQuery expected = new PhraseQuery();
expected.setBoost(0.5f);
expected.add(new Term("field", "中"));
expected.add(new Term("field", "国"));
assertEquals(expected, getQuery("\"中国\"^0.5", analyzer));
}
示例5: rewrite
import org.apache.lucene.search.PhraseQuery; //导入方法依赖的package包/类
/**
* Rewrite a term query. The base class rewrites the term itself.
*
* @param q The query to rewrite
* @return Rewritten version, or 'q' unchanged if no change needed.
*/
protected Query rewrite(TermQuery q)
{
Term oldTerm = q.getTerm();
Term newTerm = rewrite(oldTerm);
// If the term is unchanged, don't change the query.
if (oldTerm == newTerm)
return q;
// If the term is going away, inform the caller
if (newTerm == null)
return null;
// If the term is splitting, make it into two terms.
int spacePos = newTerm.text().indexOf(' ');
if (oldTerm.text().indexOf(' ') < 0 && spacePos >= 0) {
PhraseQuery pq = new PhraseQuery();
pq.add(new Term(newTerm.field(), newTerm.text().substring(0, spacePos)));
pq.add(new Term(newTerm.field(), newTerm.text().substring(spacePos+1)));
pq.setBoost(q.getBoost());
return pq;
}
// Make a new query for the new term.
TermQuery newQuery = new TermQuery(newTerm);
newQuery.setBoost(q.getBoost());
return newQuery;
}
示例6: buildQuery
import org.apache.lucene.search.PhraseQuery; //导入方法依赖的package包/类
public static BooleanQuery buildQuery(String text, String field) throws IOException {
BooleanQuery fullQuery = new BooleanQuery();
TokenStream tokStream = ANALYZER.tokenStream(field, text);
try {
tokStream.reset();
Term lastTerm = null;
while (tokStream.incrementToken()) {
String termStr = tokStream.getAttribute(CharTermAttribute.class).toString();
Term term = new Term(field, termStr);
TermQuery termQuery = new TermQuery(term);
termQuery.setBoost(0.8f);
fullQuery.add(termQuery, BooleanClause.Occur.SHOULD);
List<String> expansionWords = WordNetExpansion.getStrictExpansion(termStr);
if (expansionWords != null) {
for (String expTermStr : expansionWords) {
TermQuery expTermQuery = new TermQuery(new Term(field, expTermStr));
expTermQuery.setBoost(0.4f);
fullQuery.add(expTermQuery, BooleanClause.Occur.SHOULD);
}
}
if (lastTerm != null) {
PhraseQuery bigram = new PhraseQuery();
bigram.add(lastTerm);
bigram.add(term);
bigram.setBoost(0.1f);
fullQuery.add(bigram, BooleanClause.Occur.SHOULD);
if (USE_PROXIMITY_QUERY) {
SpanNearQuery spanNearQuery = new SpanNearQuery(new SpanQuery[]{
new SpanTermQuery(lastTerm),
new SpanTermQuery(term)},
6,
false);
spanNearQuery.setBoost(0.1f);
fullQuery.add(spanNearQuery, BooleanClause.Occur.SHOULD);
}
}
lastTerm = term;
}
tokStream.end();
} finally {
tokStream.close();
}
return fullQuery;
}