當前位置: 首頁>>代碼示例>>Java>>正文


Java WildcardQuery類代碼示例

本文整理匯總了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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:DocumentUtil.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:DocumentUtil.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:QueryStringQueryBuilderTests.java

示例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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:LuceneQueryBuilder.java

示例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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:23,代碼來源:LuceneQueryBuilder.java

示例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();
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:18,代碼來源:TextQuery.java

示例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();
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:22,代碼來源:FileQuery.java

示例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());
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:19,代碼來源:TestLindenCore.java

示例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();
}
 
開發者ID:mpcontracting,項目名稱:rpmjukebox,代碼行數:27,代碼來源:SearchManager.java

示例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)));
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:MavenClassSearcher.java

示例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());
}
 
開發者ID:KorAP,項目名稱:Krill,代碼行數:20,代碼來源:TestWildcardIndex.java

示例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());

}
 
開發者ID:KorAP,項目名稱:Krill,代碼行數:19,代碼來源:TestWildcardIndex.java

示例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());

}
 
開發者ID:KorAP,項目名稱:Krill,代碼行數:19,代碼來源:TestWildcardIndex.java

示例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);
	}
}
 
開發者ID:ujmp,項目名稱:universal-java-matrix-package,代碼行數:21,代碼來源:LuceneMap.java


注:本文中的org.apache.lucene.search.WildcardQuery類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。