本文整理汇总了Java中org.apache.lucene.search.RegexpQuery类的典型用法代码示例。如果您正苦于以下问题:Java RegexpQuery类的具体用法?Java RegexpQuery怎么用?Java RegexpQuery使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RegexpQuery类属于org.apache.lucene.search包,在下文中一共展示了RegexpQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWildcardStarRewritten
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Test
public void testWildcardStarRewritten () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// meine* /+w1:2,s0 &Erfahrung
// rewritten into meine.*
RegexpQuery wcquery = new RegexpQuery(new Term("tokens", "s:meine.*"));
SpanMultiTermQueryWrapper<RegexpQuery> mtq =
new SpanMultiTermQueryWrapper<RegexpQuery>(wcquery);
SpanMultipleDistanceQuery 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());
}
示例2: testWildcardQuestionMarkRewritten
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Test
public void testWildcardQuestionMarkRewritten () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// meine? /+w1:2,s0 &Erfahrung
// meine? rewritten into meine.
SpanMultiTermQueryWrapper<RegexpQuery> mtq =
new SpanMultiTermQueryWrapper<RegexpQuery>(
new RegexpQuery(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());
}
示例3: testWildcardPlusRewritten
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Test
public void testWildcardPlusRewritten () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// C2 meine+ /+w1:2,s0 &Erfahrung
// meine+ rewritten into meine.?
SpanMultiTermQueryWrapper<RegexpQuery> mtq =
new SpanMultiTermQueryWrapper<RegexpQuery>(
new RegexpQuery(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(4, kr.getMatches().size());
}
示例4: testWildcardPlusRewritten2
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Test
public void testWildcardPlusRewritten2 () throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// C2 mein+ /+w1:2,s0 &Erfahrung
// mein+ rewritten into mein.?
SpanMultiTermQueryWrapper<RegexpQuery> mtq =
new SpanMultiTermQueryWrapper<RegexpQuery>(
new RegexpQuery(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(2, kr.getMatches().size());
}
示例5: build
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Override
public RegexpQuery build(QueryNode queryNode) throws QueryNodeException {
RegexpQueryNode regexpNode = (RegexpQueryNode) queryNode;
// TODO: make the maxStates configurable w/ a reasonable default (QueryParserBase uses 10000)
RegexpQuery q = new RegexpQuery(new Term(regexpNode.getFieldAsString(),
regexpNode.textToBytesRef()));
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode
.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null) {
q.setRewriteMethod(method);
}
return q;
}
示例6: testNoSuchMultiTermsInSpanFirst
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public void testNoSuchMultiTermsInSpanFirst() throws Exception {
//this hasn't been a problem
FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
SpanQuery spanFirst = new SpanFirstQuery(spanNoSuch, 10);
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
spanFirst = new SpanFirstQuery(spanWCNoSuch, 10);
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
spanFirst = new SpanFirstQuery(spanRgxNoSuch, 10);
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
spanFirst = new SpanFirstQuery(spanPrfxNoSuch, 10);
assertEquals(0, searcher.search(spanFirst, 10).totalHits);
}
示例7: newWildcardQuery
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Override
protected Query newWildcardQuery(Term t)
{
if(t.text().equals("*"))
{
BooleanQuery bQuery = new BooleanQuery();
bQuery.add(createTermQuery(FIELD_FIELDS, t.field()), Occur.SHOULD);
bQuery.add(createTermQuery(FIELD_PROPERTIES, t.field()), Occur.SHOULD);
return bQuery;
}
else if (t.text().contains("\\"))
{
String regexp = SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_REGEX, t.text());
return new RegexpQuery(new Term(t.field(), regexp));
}
else
{
org.apache.lucene.search.WildcardQuery query = new org.apache.lucene.search.WildcardQuery(t);
query.setRewriteMethod(new MultiTermQuery.TopTermsScoringBooleanQueryRewrite(topTermSpanRewriteLimit));
return query;
}
}
示例8: regexpQuery
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Override
public final Query regexpQuery(String value, int flags, int maxDeterminizedStates,
MultiTermQuery.RewriteMethod method, QueryShardContext context) {
failIfNotIndexed();
RegexpQuery query = new RegexpQuery(new Term(name(), indexedValueForSearch(value)), flags, maxDeterminizedStates);
if (method != null) {
query.setRewriteMethod(method);
}
return query;
}
示例9: testToQueryRegExpQuery
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public void testToQueryRegExpQuery() throws Exception {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
Query query = queryStringQuery("/foo*bar/").defaultField(STRING_FIELD_NAME)
.maxDeterminizedStates(5000)
.toQuery(createShardContext());
assertThat(query, instanceOf(RegexpQuery.class));
RegexpQuery regexpQuery = (RegexpQuery) query;
assertTrue(regexpQuery.toString().contains("/foo*bar/"));
}
示例10: testRegexpQuery
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public void testRegexpQuery() {
MappedFieldType ft = createDefaultFieldType();
ft.setName("field");
ft.setIndexOptions(IndexOptions.DOCS);
assertEquals(new RegexpQuery(new Term("field","foo.*")),
ft.regexpQuery("foo.*", 0, 10, null, null));
ft.setIndexOptions(IndexOptions.NONE);
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> ft.regexpQuery("foo.*", 0, 10, null, null));
assertEquals("Cannot search on field [field] since it is not indexed.", e.getMessage());
}
示例11: build
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
@Override
public RegexpQuery build(QueryNode queryNode) throws QueryNodeException {
RegexpQueryNode regexpNode = (RegexpQueryNode) queryNode;
RegexpQuery q = new RegexpQuery(new Term(regexpNode.getFieldAsString(),
regexpNode.textToBytesRef()));
MultiTermQuery.RewriteMethod method = (MultiTermQuery.RewriteMethod) queryNode
.getTag(MultiTermRewriteMethodProcessor.TAG_ID);
if (method != null) {
q.setRewriteMethod(method);
}
return q;
}
示例12: SpanRegexQueryWrapper
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public SpanRegexQueryWrapper (String field, String re, int flags,
boolean caseinsensitive) {
if (caseinsensitive) {
if (re.startsWith("s:")) {
re = re.replaceFirst("s:", "i:");
};
re = re.toLowerCase();
};
RegexpQuery requery = new RegexpQuery(new Term(field, re), flags);
query = new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
}
示例13: createRegExpQuery
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public static Query createRegExpQuery(final String field, final String value) {
return new Query() {
@Override
public org.apache.lucene.search.Query getLuceneQuery(Schema schema) {
validateType(field, schema, JsonNode.Type.STRING);
return new RegexpQuery(new Term(field, value));
}
};
}
示例14: testNullPointerException
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public void testNullPointerException() throws IOException {
RegexpQuery regex = new RegexpQuery(new Term("field", "worl."));
SpanQuery wrappedquery = new SpanMultiTermQueryWrapper<>(regex);
MemoryIndex mindex = new MemoryIndex(random().nextBoolean(), random().nextInt(50) * 1024 * 1024);
mindex.addField("field", new MockAnalyzer(random()).tokenStream("field", "hello there"));
// This throws an NPE
assertEquals(0, mindex.search(wrappedquery), 0.00001f);
}
示例15: testPassesIfWrapped
import org.apache.lucene.search.RegexpQuery; //导入依赖的package包/类
public void testPassesIfWrapped() throws IOException {
RegexpQuery regex = new RegexpQuery(new Term("field", "worl."));
SpanQuery wrappedquery = new SpanOrQuery(new SpanMultiTermQueryWrapper<>(regex));
MemoryIndex mindex = new MemoryIndex(random().nextBoolean(), random().nextInt(50) * 1024 * 1024);
mindex.addField("field", new MockAnalyzer(random()).tokenStream("field", "hello there"));
// This passes though
assertEquals(0, mindex.search(wrappedquery), 0.00001f);
}