本文整理匯總了Java中org.apache.lucene.search.BooleanQuery.add方法的典型用法代碼示例。如果您正苦於以下問題:Java BooleanQuery.add方法的具體用法?Java BooleanQuery.add怎麽用?Java BooleanQuery.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.search.BooleanQuery
的用法示例。
在下文中一共展示了BooleanQuery.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
/**
* @deprecated Use {@link #parse(String, String[], BooleanClause.Occur[], Analyzer)}
*/
@Deprecated
public static Query parse(Version matchVersion, String query, String[] fields,
BooleanClause.Occur[] flags, Analyzer analyzer) throws ParseException {
if (fields.length != flags.length)
throw new IllegalArgumentException("fields.length != flags.length");
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.length; i++) {
QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
Query q = qp.parse(query);
if (q!=null && // q never null, just being defensive
(!(q instanceof BooleanQuery) || ((BooleanQuery)q).getClauses().length>0)) {
bQuery.add(q, flags[i]);
}
}
return bQuery;
}
示例2: applyConstraints
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
@Override
protected void applyConstraints(BooleanQuery query) {
if (fileNames != null) {
BooleanQuery subQuery = new BooleanQuery(true);
for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
if (subQuery.getClauses().length != 0)
query.add(subQuery, Occur.MUST);
}
if (regex)
query.add(new RegexLiterals(term).asNGramQuery(BLOB_TEXT.name(), NGRAM_SIZE), Occur.MUST);
else if (term.length() >= NGRAM_SIZE)
query.add(new NGramLuceneQuery(BLOB_TEXT.name(), term, NGRAM_SIZE), Occur.MUST);
else
throw new TooGeneralQueryException();
}
示例3: getQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
@Override
public Query getQuery(Element e) throws ParserException {
BooleanQuery bq = new BooleanQuery(DOMUtils.getAttribute(e, "disableCoord", false));
bq.setMinimumNumberShouldMatch(DOMUtils.getAttribute(e, "minimumNumberShouldMatch", 0));
bq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
NodeList nl = e.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node.getNodeName().equals("Clause")) {
Element clauseElem = (Element) node;
BooleanClause.Occur occurs = getOccursValue(clauseElem);
Element clauseQuery = DOMUtils.getFirstChildOrFail(clauseElem);
Query q = factory.getQuery(clauseQuery);
bq.add(new BooleanClause(q, occurs));
}
}
return bq;
}
示例4: addSearchTermQueries
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的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);
}
}
示例5: prefixSearch
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的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;
}
示例6: getLuceneQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
/**
* Returns the Lucene query for the given locale and query text.
*
* @param searchString
* the text query for the Lucene query parser
* @param mId
* the marketplace id
* @param locale
* the locale for the analyzer to use
* @param isDefaultLocaleHandling
* @return the Lucene query for the given locale and query text
* @throws ParseException
* in case the query cannot be parsed
*/
private org.apache.lucene.search.Query getLuceneQuery(String searchString,
String mId, String locale, boolean isDefaultLocaleHandling)
throws SyntaxError, QueryNodeException {
// construct wildcard query for the actual search part
org.apache.lucene.search.Query textQuery = LuceneQueryBuilder
.getServiceQuery(searchString, locale, DEFAULT_LOCALE,
isDefaultLocaleHandling);
// build mId part
TermQuery mIdQuery = new TermQuery(new Term(ProductClassBridge.MP_ID,
QueryParser.escape(mId).toLowerCase()));
// now construct final query
BooleanQuery query = new BooleanQuery();
query.add(mIdQuery, Occur.MUST);
query.add(textQuery, Occur.MUST);
return query;
}
示例7: constructWildcardQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的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;
}
示例8: addUniqueIdClauseToQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
private Query addUniqueIdClauseToQuery(Query query, SearchResults<T> itemResults, IndexReader reader)
{
List<T> results = itemResults.getResults();
BooleanQuery orQuery = new BooleanQuery();
for( T t : results )
{
ItemIdKey itemIdKey = t.getItemIdKey();
String[] split = itemIdKey.toString().split("/");
String uniqueId = split[1] + "/" + split[2];
FreeTextBooleanQuery bquery = new FreeTextBooleanQuery(false, true);
bquery.add(new FreeTextFieldQuery(FreeTextQuery.FIELD_UNIQUE, uniqueId));
BooleanClause convertBoolean = convertToBooleanClause(bquery, reader);
convertBoolean.setOccur(Occur.SHOULD);
orQuery.add(convertBoolean);
}
BooleanQuery newQuery = new BooleanQuery();
newQuery.add(query, Occur.MUST);
newQuery.add(orQuery, Occur.MUST);
return newQuery;
}
示例9: constructDefaultLocaleHandlingQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
private static BooleanQuery constructDefaultLocaleHandlingQuery(
String fieldName, String locale, String defaultLocale,
String searchPhrase) {
BooleanQuery bq1 = new BooleanQuery();
TermQuery tq1 = new TermQuery(
new Term(fieldName + ProductClassBridge.DEFINED_LOCALES_SUFFIX,
defaultLocale));
TermQuery tq2 = new TermQuery(new Term(
fieldName + ProductClassBridge.DEFINED_LOCALES_SUFFIX, locale));
bq1.add(tq1, Occur.MUST);
bq1.add(tq2, Occur.MUST_NOT);
BooleanQuery bq2 = new BooleanQuery();
WildcardQuery wq1 = new WildcardQuery(
new Term(fieldName + defaultLocale,
"*" + searchPhrase.toLowerCase() + "*"));
bq2.add(wq1, Occur.SHOULD);
BooleanQuery finalQuery = new BooleanQuery();
finalQuery.add(bq1, Occur.MUST);
finalQuery.add(bq2, Occur.MUST);
return finalQuery;
}
示例10: applyConstraints
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
@Override
protected void applyConstraints(BooleanQuery query) {
if (fileNames != null) {
BooleanQuery subQuery = new BooleanQuery(true);
for (String pattern: Splitter.on(",").omitEmptyStrings().trimResults().split(fileNames.toLowerCase()))
subQuery.add(new WildcardQuery(new Term(BLOB_NAME.name(), pattern)), Occur.SHOULD);
if (subQuery.getClauses().length != 0)
query.add(subQuery, Occur.MUST);
}
boolean tooGeneral = true;
for (char ch: term.toCharArray()) {
if (ch != '?' && ch != '*') {
tooGeneral = false;
break;
}
}
if (tooGeneral)
throw new TooGeneralQueryException();
if (primary != null) {
String fieldName;
if (primary)
fieldName = BLOB_PRIMARY_SYMBOLS.name();
else
fieldName = BLOB_SECONDARY_SYMBOLS.name();
query.add(new WildcardQuery(new Term(fieldName, term.toLowerCase())), Occur.MUST);
}
}
示例11: createClassWithEnclosedQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
private static Query createClassWithEnclosedQuery (final String resourceName, final String sourceName) {
final BooleanQuery query = createFQNQuery(resourceName);
if (sourceName != null) {
query.add (new TermQuery(new Term (DocumentUtil.FIELD_SOURCE,sourceName)), Occur.MUST);
}
return query;
}
示例12: newPhraseQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
/**
* Factory method to generate a phrase query with slop.
*/
protected Query newPhraseQuery(String text, int slop) {
BooleanQuery bq = new BooleanQuery(true);
for (Map.Entry<String,Float> entry : weights.entrySet()) {
Query q = createPhraseQuery(entry.getKey(), text, slop);
if (q != null) {
q.setBoost(entry.getValue());
bq.add(q, BooleanClause.Occur.SHOULD);
}
}
return simplify(bq);
}
示例13: delete
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
/**
* Deletes the given {@link IIndexElement} from the index.
* @param element the {@link IIndexElement} to remove.
* @throws IOException if an error occurred in the index.
*/
private void delete(final IIndexElement element) throws IOException {
final IIndexTypeConf conf = indexData.getConf();
// build query for deletion
final BooleanQuery query = new BooleanQuery();
query.add(new TermQuery(new Term(IIndexElement.FIELD_ID, element.getId())), Occur.MUST);
query.add(new TermQuery(new Term(IIndexElement.FIELD_INDEX_TYPE, conf.getName())), Occur.MUST);
index.deleteDocuments(query);
}
示例14: fiterSafeToQuery
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
private void fiterSafeToQuery(BooleanQuery query, Boolean bNoAds, Boolean bOfficial) {
NumericRangeQuery<Integer> catalogNumQuery = NumericRangeQuery.newIntRange("catalog",
(int) EnumCatalog.SOFT.getCatalog(), (int) EnumCatalog.GAME.getCatalog(), true, true);
;
query.add(catalogNumQuery, Occur.MUST);
if (bNoAds != null && bNoAds.booleanValue()) {
NumericRangeQuery<Integer> noAdsQuery = NumericRangeQuery.newIntRange("noAds", 1, 1, true, true);
query.add(noAdsQuery, Occur.MUST);
}
if (bOfficial != null && bOfficial.booleanValue()) {
NumericRangeQuery<Integer> officialQuery = NumericRangeQuery.newIntRange("official", 1, 1, true, true);
query.add(officialQuery, Occur.MUST);
}
}
示例15: makeLuceneQueryFieldNoBoost
import org.apache.lucene.search.BooleanQuery; //導入方法依賴的package包/類
@Override
public Query makeLuceneQueryFieldNoBoost(String fieldName, BasicQueryFactory qf) {
List<Query> luceneSubQueries = makeLuceneSubQueriesField(fieldName, qf);
BooleanQuery bq = new BooleanQuery();
bq.add( luceneSubQueries.get(0), BooleanClause.Occur.MUST);
SrndBooleanQuery.addQueriesToBoolean(bq,
// FIXME: do not allow weights on prohibited subqueries.
luceneSubQueries.subList(1, luceneSubQueries.size()),
// later subqueries: not required, prohibited
BooleanClause.Occur.MUST_NOT);
return bq;
}