本文整理汇总了Java中org.apache.lucene.search.spans.SpanNotQuery类的典型用法代码示例。如果您正苦于以下问题:Java SpanNotQuery类的具体用法?Java SpanNotQuery怎么用?Java SpanNotQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpanNotQuery类属于org.apache.lucene.search.spans包,在下文中一共展示了SpanNotQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getSpanQuery
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
@Override
public SpanQuery getSpanQuery(Element e) throws ParserException {
Element includeElem = DOMUtils.getChildByTagOrFail(e, "Include");
includeElem = DOMUtils.getFirstChildOrFail(includeElem);
Element excludeElem = DOMUtils.getChildByTagOrFail(e, "Exclude");
excludeElem = DOMUtils.getFirstChildOrFail(excludeElem);
SpanQuery include = factory.getSpanQuery(includeElem);
SpanQuery exclude = factory.getSpanQuery(excludeElem);
SpanNotQuery snq = new SpanNotQuery(include, exclude);
snq.setBoost(DOMUtils.getAttribute(e, "boost", 1.0f));
return snq;
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:SpanNotBuilder.java
示例2: toFragmentQuery
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
public SpanQuery toFragmentQuery () throws QueryException {
if (this.isNull
|| (this.inclusive.size() + this.exclusive.size() == 0)) {
return (SpanQuery) null;
}
else if (this.inclusive.size() >= 1 && this.exclusive.size() >= 1) {
return (SpanQuery) new SpanNotQuery(
this._listToQuery(this.inclusive),
this._listToOrQuery(this.exclusive));
}
// These are now identical but may be negative
else if (this.inclusive.size() == 0 && this.exclusive.size() >= 1) {
return (SpanQuery) this._listToQuery(this.exclusive);
}
else if (this.inclusive.size() >= 1 && this.exclusive.size() == 0) {
return (SpanQuery) this._listToQuery(this.inclusive);
};
return (SpanQuery) null;
}
开发者ID:KorAP,项目名称:Krill,代码行数:22,代码来源:SpanSegmentQueryWrapper.java
示例3: rewrite
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
/**
* Rewrite a span-based NOT query. The procedure in this case is simple:
* simply rewrite both the include and exclude clauses.
*
* @param nq The query to rewrite
* @return Rewritten version, or 'nq' unchanged if no changed needed.
*/
protected Query rewrite(SpanNotQuery nq)
{
// Rewrite the sub-queries
SpanQuery include = (SpanQuery)rewriteQuery(nq.getInclude());
SpanQuery exclude = (SpanQuery)rewriteQuery(nq.getExclude());
// If the sub-queries didn't change, then neither does this NOT.
if (include == nq.getInclude() &&
exclude == nq.getExclude() &&
!forceRewrite(nq))
return nq;
// Make a new NOT query
Query newq = new SpanNotQuery(include, exclude);
copyBoost(nq, newq);
return newq;
}
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:25,代码来源:QueryRewriter.java
示例4: testExtractQueryMetadata_spanNotQuery
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
public void testExtractQueryMetadata_spanNotQuery() {
SpanTermQuery spanTermQuery1 = new SpanTermQuery(new Term("_field", "_short_term"));
SpanTermQuery spanTermQuery2 = new SpanTermQuery(new Term("_field", "_very_long_term"));
SpanNotQuery spanNotQuery = new SpanNotQuery(spanTermQuery1, spanTermQuery2);
Result result = analyze(spanNotQuery);
assertThat(result.verified, is(false));
assertTermsEqual(result.terms, spanTermQuery1.getTerm());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:QueryAnalyzerTests.java
示例5: doAssertLuceneQuery
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
@Override
protected void doAssertLuceneQuery(SpanNotQueryBuilder queryBuilder, Query query, SearchContext context) throws IOException {
assertThat(query, instanceOf(SpanNotQuery.class));
SpanNotQuery spanNotQuery = (SpanNotQuery) query;
assertThat(spanNotQuery.getExclude(), equalTo(queryBuilder.excludeQuery().toQuery(context.getQueryShardContext())));
assertThat(spanNotQuery.getInclude(), equalTo(queryBuilder.includeQuery().toQuery(context.getQueryShardContext())));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:SpanNotQueryBuilderTests.java
示例6: spanFilter
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
private Query spanFilter(SpanQuery query) {
if (query instanceof SpanNearQuery) {
return spanNearFilter((SpanNearQuery) query);
} else if (query instanceof SpanNotQuery) {
return spanNotFilter((SpanNotQuery) query);
} else if (query instanceof SpanOrQuery) {
return spanOrFilter((SpanOrQuery) query);
} else if (query instanceof SpanTermQuery) {
return new TermQuery(((SpanTermQuery) query).getTerm());
} else if (query instanceof SpanMultiTermQueryWrapper) {
return ((SpanMultiTermQueryWrapper) query).getWrappedQuery();
} else {
return new QueryWrapperFilter(query);
}
}
开发者ID:meltwater,项目名称:meltwater-elasticsearch-queries,代码行数:16,代码来源:LimitingFilterFactory.java
示例7: testSpanNotQuery
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
public void testSpanNotQuery() throws Exception {
SpanNearQuery quick_fox =
new SpanNearQuery(new SpanQuery[]{quick, fox}, 1, true);
assertBothFoxes(quick_fox);
dumpSpans(quick_fox);
SpanNotQuery quick_fox_dog = new SpanNotQuery(quick_fox, dog);
assertBothFoxes(quick_fox_dog);
dumpSpans(quick_fox_dog);
SpanNotQuery no_quick_red_fox =
new SpanNotQuery(quick_fox, red);
assertOnlyBrownFox(no_quick_red_fox);
dumpSpans(no_quick_red_fox);
}
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:16,代码来源:SpanQueryTest.java
示例8: spanNotQuery
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
static Function<Query, Result> spanNotQuery() {
return query -> {
Result result = analyze(((SpanNotQuery) query).getInclude());
return new Result(false, result.terms);
};
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:QueryAnalyzer.java
示例9: testDuelSpecificQueries
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
public void testDuelSpecificQueries() throws Exception {
List<ParseContext.Document> documents = new ArrayList<>();
CommonTermsQuery commonTermsQuery = new CommonTermsQuery(BooleanClause.Occur.SHOULD, BooleanClause.Occur.SHOULD, 128);
commonTermsQuery.add(new Term("field", "quick"));
commonTermsQuery.add(new Term("field", "brown"));
commonTermsQuery.add(new Term("field", "fox"));
addQuery(commonTermsQuery, documents);
BlendedTermQuery blendedTermQuery = BlendedTermQuery.booleanBlendedQuery(new Term[]{new Term("field", "quick"),
new Term("field", "brown"), new Term("field", "fox")}, false);
addQuery(blendedTermQuery, documents);
SpanNearQuery spanNearQuery = new SpanNearQuery.Builder("field", true)
.addClause(new SpanTermQuery(new Term("field", "quick")))
.addClause(new SpanTermQuery(new Term("field", "brown")))
.addClause(new SpanTermQuery(new Term("field", "fox")))
.build();
addQuery(spanNearQuery, documents);
SpanNearQuery spanNearQuery2 = new SpanNearQuery.Builder("field", true)
.addClause(new SpanTermQuery(new Term("field", "the")))
.addClause(new SpanTermQuery(new Term("field", "lazy")))
.addClause(new SpanTermQuery(new Term("field", "doc")))
.build();
SpanOrQuery spanOrQuery = new SpanOrQuery(
spanNearQuery,
spanNearQuery2
);
addQuery(spanOrQuery, documents);
SpanNotQuery spanNotQuery = new SpanNotQuery(spanNearQuery, spanNearQuery);
addQuery(spanNotQuery, documents);
long lowerLong = randomIntBetween(0, 256);
long upperLong = lowerLong + randomIntBetween(0, 32);
addQuery(LongPoint.newRangeQuery("long_field", lowerLong, upperLong), documents);
indexWriter.addDocuments(documents);
indexWriter.close();
directoryReader = DirectoryReader.open(directory);
IndexSearcher shardSearcher = newSearcher(directoryReader);
// Disable query cache, because ControlQuery cannot be cached...
shardSearcher.setQueryCache(null);
Document document = new Document();
document.add(new TextField("field", "the quick brown fox jumps over the lazy dog", Field.Store.NO));
long randomLong = randomIntBetween((int) lowerLong, (int) upperLong);
document.add(new LongPoint("long_field", randomLong));
MemoryIndex memoryIndex = MemoryIndex.fromDocument(document, new WhitespaceAnalyzer());
duelRun(queryStore, memoryIndex, shardSearcher);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:53,代码来源:CandidateQueryTests.java
示例10: addComplexPhraseClause
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
private void addComplexPhraseClause(List<SpanQuery> spanClauses, BooleanQuery qc) {
ArrayList<SpanQuery> ors = new ArrayList<>();
ArrayList<SpanQuery> nots = new ArrayList<>();
BooleanClause[] bclauses = qc.getClauses();
// For all clauses e.g. one* two~
for (int i = 0; i < bclauses.length; i++) {
Query childQuery = bclauses[i].getQuery();
// select the list to which we will add these options
ArrayList<SpanQuery> chosenList = ors;
if (bclauses[i].getOccur() == BooleanClause.Occur.MUST_NOT) {
chosenList = nots;
}
if (childQuery instanceof TermQuery) {
TermQuery tq = (TermQuery) childQuery;
SpanTermQuery stq = new SpanTermQuery(tq.getTerm());
stq.setBoost(tq.getBoost());
chosenList.add(stq);
} else if (childQuery instanceof BooleanQuery) {
BooleanQuery cbq = (BooleanQuery) childQuery;
addComplexPhraseClause(chosenList, cbq);
} else {
// TODO alternatively could call extract terms here?
throw new IllegalArgumentException("Unknown query type:"
+ childQuery.getClass().getName());
}
}
if (ors.size() == 0) {
return;
}
SpanOrQuery soq = new SpanOrQuery(ors
.toArray(new SpanQuery[ors.size()]));
if (nots.size() == 0) {
spanClauses.add(soq);
} else {
SpanOrQuery snqs = new SpanOrQuery(nots
.toArray(new SpanQuery[nots.size()]));
SpanNotQuery snq = new SpanNotQuery(soq, snqs);
spanClauses.add(snq);
}
}
开发者ID:lamsfoundation,项目名称:lams,代码行数:44,代码来源:ComplexPhraseQueryParser.java
示例11: spanNotFilter
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
private Query spanNotFilter(SpanNotQuery query) {
return spanFilter(query.getInclude());
}
开发者ID:meltwater,项目名称:meltwater-elasticsearch-queries,代码行数:4,代码来源:LimitingFilterFactory.java
示例12: testSpanNot
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
public void testSpanNot() throws Exception {
Directory dir = newDirectory();
// use simpleanalyzer for more natural tokenization (else "test." is a token)
final Analyzer analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true);
IndexWriterConfig iwc = newIndexWriterConfig(analyzer);
iwc.setMergePolicy(newLogMergePolicy());
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
FieldType offsetsType = new FieldType(TextField.TYPE_STORED);
offsetsType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
Field body = new Field("body", "", offsetsType);
Document doc = new Document();
doc.add(body);
body.setStringValue("This is a test.");
iw.addDocument(doc);
body.setStringValue("Test a one sentence document.");
iw.addDocument(doc);
IndexReader ir = iw.getReader();
iw.close();
IndexSearcher searcher = newSearcher(ir);
PostingsHighlighter highlighter = new PostingsHighlighter() {
@Override
protected Analyzer getIndexAnalyzer(String field) {
return analyzer;
}
};
SpanQuery include = new SpanMultiTermQueryWrapper<>(new WildcardQuery(new Term("body", "te*")));
SpanQuery exclude = new SpanTermQuery(new Term("body", "bogus"));
Query query = new SpanNotQuery(include, exclude);
TopDocs topDocs = searcher.search(query, null, 10, Sort.INDEXORDER);
assertEquals(2, topDocs.totalHits);
String snippets[] = highlighter.highlight("body", query, searcher, topDocs);
assertEquals(2, snippets.length);
assertEquals("This is a <b>test</b>.", snippets[0]);
assertEquals("<b>Test</b> a one sentence document.", snippets[1]);
ir.close();
dir.close();
}
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:TestMultiTermHighlighting.java
示例13: snot
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
/** MACRO for SpanNotQuery */
public SpanNotQuery snot(SpanQuery i, SpanQuery e) {
return new SpanNotQuery(i,e);
}
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:BaseExplanationTestCase.java
示例14: addComplexPhraseClause
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
private void addComplexPhraseClause(List<SpanQuery> spanClauses, BooleanQuery qc) {
ArrayList<SpanQuery> ors = new ArrayList<SpanQuery>();
ArrayList<SpanQuery> nots = new ArrayList<SpanQuery>();
BooleanClause[] bclauses = qc.getClauses();
// For all clauses e.g. one* two~
for (int i = 0; i < bclauses.length; i++) {
Query childQuery = bclauses[i].getQuery();
// select the list to which we will add these options
ArrayList<SpanQuery> chosenList = ors;
if (bclauses[i].getOccur() == BooleanClause.Occur.MUST_NOT) {
chosenList = nots;
}
if (childQuery instanceof TermQuery) {
TermQuery tq = (TermQuery) childQuery;
SpanTermQuery stq = new SpanTermQuery(tq.getTerm());
stq.setBoost(tq.getBoost());
chosenList.add(stq);
} else if (childQuery instanceof BooleanQuery) {
BooleanQuery cbq = (BooleanQuery) childQuery;
addComplexPhraseClause(chosenList, cbq);
} else {
// TODO alternatively could call extract terms here?
throw new IllegalArgumentException("Unknown query type:"
+ childQuery.getClass().getName());
}
}
if (ors.size() == 0) {
return;
}
SpanOrQuery soq = new SpanOrQuery(ors
.toArray(new SpanQuery[ors.size()]));
if (nots.size() == 0) {
spanClauses.add(soq);
} else {
SpanOrQuery snqs = new SpanOrQuery(nots
.toArray(new SpanQuery[nots.size()]));
SpanNotQuery snq = new SpanNotQuery(soq, snqs);
spanClauses.add(snq);
}
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:44,代码来源:ComplexPhraseQueryParser.java
示例15: traverse
import org.apache.lucene.search.spans.SpanNotQuery; //导入依赖的package包/类
/**
* Traverse a span-based NOT query.
*
* @param nq The query to traverse
*/
protected void traverse(SpanNotQuery nq) {
traverseQuery(nq.getInclude());
traverseQuery(nq.getExclude());
}
开发者ID:CDLUC3,项目名称:dash-xtf,代码行数:10,代码来源:QueryTraverser.java
注:本文中的org.apache.lucene.search.spans.SpanNotQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论