本文整理汇总了Java中org.apache.lucene.search.WildcardQuery类的典型用法代码示例。如果您正苦于以下问题:Java WildcardQuery类的具体用法?Java WildcardQuery怎么用?Java WildcardQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WildcardQuery类属于org.apache.lucene.search包,在下文中一共展示了WildcardQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: binaryNameQuery
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
static Query binaryNameQuery (final String resourceName) {
final BooleanQuery query = new BooleanQuery ();
int index = resourceName.lastIndexOf(BinaryName.PKG_SEPARATOR); // NOI18N
String pkgName, sName;
if (index < 0) {
pkgName = ""; // NOI18N
sName = resourceName;
}
else {
pkgName = resourceName.substring(0,index);
sName = resourceName.substring(index+1);
}
sName = sName + WILDCARD_QUERY_WILDCARD; //Type of type element (Enum, Class, Interface, Annotation)
query.add (new TermQuery (new Term (FIELD_PACKAGE_NAME, pkgName)),BooleanClause.Occur.MUST);
query.add (new WildcardQuery (new Term (FIELD_BINARY_NAME, sName)),BooleanClause.Occur.MUST);
return query;
}
示例2: createFQNQuery
import org.apache.lucene.search.WildcardQuery; //导入依赖的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;
}
示例3: findPosts
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
private List<Post> findPosts() {
try {
FullTextSession fullTextSession = getFullTextSession((Session) entityManager.getDelegate());
Builder builder = new Builder();
String[] fields = new String[] { "message.text", "topic.subject" };
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer());
builder.add(parser.parse(POST_TEXT), MUST);
builder.add(new TermQuery(new Term("topic.forum.id", "0")), MUST);
builder.add(new TermQuery(new Term("topic.forum.category.id", "0")), MUST);
builder.add(new WildcardQuery(new Term("poster.userId", "root")), MUST);
addPostTimeQuery(builder);
FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(builder.build(), Post.class);
fullTextQuery.setSort(getSort());
fullTextQuery.setFirstResult(0);
fullTextQuery.setMaxResults(15);
@SuppressWarnings("unchecked")
List<Post> posts = fullTextQuery.list();
return posts;
} catch (ParseException e) {
logger.severe("error");
return null;
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:24,代码来源:SearchTestCase.java
示例4: testDisabledFieldNamesField
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
public void testDisabledFieldNamesField() throws Exception {
QueryShardContext context = createShardContext();
context.getMapperService().merge("new_type",
new CompressedXContent(
PutMappingRequest.buildFromSimplifiedDef("new_type",
"foo", "type=text",
"_field_names", "enabled=false").string()),
MapperService.MergeReason.MAPPING_UPDATE, true);
QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder("foo:*");
Query query = queryBuilder.toQuery(context);
Query expected = new WildcardQuery(new Term("foo", "*"));
assertThat(query, equalTo(expected));
context.getMapperService().merge("new_type",
new CompressedXContent(
PutMappingRequest.buildFromSimplifiedDef("new_type",
"foo", "type=text",
"_field_names", "enabled=true").string()),
MapperService.MergeReason.MAPPING_UPDATE, true);
}
示例5: prepareWildcardQueryForSingleToken
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
private static BooleanQuery prepareWildcardQueryForSingleToken(String token,
List<String> fieldNames, String locale, String defaultLocale,
boolean isDefaultLocaleHandling) {
BooleanQuery queryPart = new BooleanQuery();
for (String fieldName : fieldNames) {
if (isDefaultLocaleHandling) {
if (locale.equals(defaultLocale)) {
throw new IllegalArgumentException(
"For default locale handling, locale and default locale must be different");
}
BooleanQuery localeHandlingQuery = constructDefaultLocaleHandlingQuery(
fieldName, locale, defaultLocale, token);
queryPart.add(localeHandlingQuery, Occur.SHOULD);
} else {
WildcardQuery wildcardQuery = new WildcardQuery(new Term(
fieldName + locale, "*" + token.toLowerCase() + "*"));
queryPart.add(wildcardQuery, Occur.SHOULD);
}
}
return queryPart;
}
示例6: constructDefaultLocaleHandlingQuery
import org.apache.lucene.search.WildcardQuery; //导入依赖的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;
}
示例7: applyConstraints
import org.apache.lucene.search.WildcardQuery; //导入依赖的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();
}
示例8: applyConstraints
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
@Override
protected void applyConstraints(BooleanQuery query) {
boolean tooGeneral = true;
for (char ch: fileNames.toCharArray()) {
if (ch != '?' && ch != '*' && ch != ',' && ch != '.') {
tooGeneral = false;
break;
}
}
if (tooGeneral)
throw new TooGeneralQueryException();
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);
else
throw new TooGeneralQueryException();
}
示例9: likeTest
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
@Test
public void likeTest() throws Exception {
String bql = "select * from linden by field1 like \"aa*\" source boost by 2";
LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest();
Query query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
Assert.assertTrue(query instanceof WildcardQuery);
Assert.assertEquals("field1:aa*^2.0", query.toString());
LindenResult result = lindenCore.search(request);
Assert.assertEquals(1, result.getTotalHits());
bql = "select * from linden by field1 not like \"aaa*\" source";
request = bqlCompiler.compile(bql).getSearchRequest();
query = QueryConstructor.constructQuery(request.getQuery(), lindenConfig);
Assert.assertTrue(query instanceof BooleanQuery);
Assert.assertEquals("+*:* -field1:aaa*", query.toString());
result = lindenCore.search(request);
Assert.assertEquals(5, result.getTotalHits());
}
示例10: buildKeywordsQuery
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
private Query buildKeywordsQuery(String keywords, Query trackFilter) {
Builder builder = new BooleanQuery.Builder();
if ("*".equals(keywords)) {
builder.add(new WildcardQuery(new Term(TrackField.KEYWORDS.name(), keywords)), BooleanClause.Occur.MUST);
} else {
// Split into whole words with the last word having
// a wildcard '*' on the end
for (StringTokenizer tokens = new StringTokenizer(keywords, " "); tokens.hasMoreTokens();) {
String token = tokens.nextToken();
if (tokens.hasMoreElements()) {
builder.add(new TermQuery(new Term(TrackField.KEYWORDS.name(), token)), BooleanClause.Occur.MUST);
} else {
builder.add(new WildcardQuery(new Term(TrackField.KEYWORDS.name(), (token + "*"))),
BooleanClause.Occur.MUST);
}
}
}
if (trackFilter != null) {
builder.add(trackFilter, BooleanClause.Occur.MUST);
}
return builder.build();
}
示例11: preparePatternAndQuery
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
protected Pair<String, Query> preparePatternAndQuery(String pattern) {
pattern = pattern.toLowerCase();
if (pattern.trim().length() == 0) {
return new Pair<String, Query>(pattern, new MatchAllDocsQuery());
}
List<String> parts = StringUtil.split(pattern, ".");
StringBuilder newPattern = new StringBuilder();
for (int i = 0; i < parts.size() - 1; i++) {
String each = parts.get(i);
newPattern.append(each.trim());
newPattern.append("*.");
}
String className = parts.get(parts.size() - 1);
boolean exactSearch = className.endsWith(" ");
newPattern.append(className.trim());
if (!exactSearch) newPattern.append("*");
pattern = newPattern.toString();
String queryPattern = "*/" + pattern.replaceAll("\\.", "/");
return new Pair<String, Query>(pattern, new WildcardQuery(new Term(TERM, queryPattern)));
}
示例12: testWildcardStarWithCollection
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
@Test
public void testWildcardStarWithCollection () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// meine*
WildcardQuery wcquery =
new WildcardQuery(new Term("tokens", "s:meine*"));
SpanMultiTermQueryWrapper<WildcardQuery> mtq =
new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
// meine* /+w1:2,s0 &Erfahrung
SpanQuery mdsq = new SpanMultipleDistanceQuery(
new SpanClassQuery(mtq, (byte) 129),
new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(4, kr.getMatches().size());
}
示例13: testWildcardQuestionMark1
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
@Test
public void testWildcardQuestionMark1 () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// Wildcard ? means regex . (expects exactly one character)
SpanMultiTermQueryWrapper<WildcardQuery> mtq =
new SpanMultiTermQueryWrapper<WildcardQuery>(
new WildcardQuery(new Term("tokens", "s:meine?")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(
new SpanClassQuery(mtq, (byte) 129),
new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(3, kr.getMatches().size());
}
示例14: testWildcardQuestionMark2
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
@Test
public void testWildcardQuestionMark2 () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// Wildcard ? means regex . (expects exactly one character)
SpanMultiTermQueryWrapper<WildcardQuery> mtq =
new SpanMultiTermQueryWrapper<WildcardQuery>(
new WildcardQuery(new Term("tokens", "s:mein?")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(
new SpanClassQuery(mtq, (byte) 129),
new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(1, kr.getMatches().size());
}
示例15: keySet
import org.apache.lucene.search.WildcardQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public synchronized Set<K> keySet() {
Set<K> set = new HashSet<K>();
if (isEmpty()) {
return set;
}
try {
Term term = new Term(KEYSTRING, "*");
WildcardQuery query = new WildcardQuery(term);
TopDocs docs = getIndexSearcher().search(query, MAXSEARCHSIZE);
for (ScoreDoc sd : docs.scoreDocs) {
Document d = getIndexSearcher().doc(sd.doc);
set.add((K) SerializationUtil.deserialize(d.getBinaryValue(KEYDATA).bytes));
}
return set;
} catch (Exception e) {
throw new RuntimeException("could not search documents", e);
}
}