本文整理汇总了Java中org.apache.lucene.search.QueryWrapperFilter类的典型用法代码示例。如果您正苦于以下问题:Java QueryWrapperFilter类的具体用法?Java QueryWrapperFilter怎么用?Java QueryWrapperFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QueryWrapperFilter类属于org.apache.lucene.search包,在下文中一共展示了QueryWrapperFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeQueryFromShape
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
protected Query makeQueryFromShape(Shape shape) {
SpatialArgs args = new SpatialArgs(operation, shape);
if (!Double.isNaN(distErrPct))
args.setDistErrPct(distErrPct);
if (score) {
ValueSource valueSource = strategy.makeDistanceValueSource(shape.getCenter());
return new CustomScoreQuery(strategy.makeQuery(args), new FunctionQuery(valueSource));
} else {
//strategy.makeQuery() could potentially score (isn't well defined) so instead we call
// makeFilter() and wrap
Filter filter = strategy.makeFilter(args);
if (filter instanceof QueryWrapperFilter) {
return ((QueryWrapperFilter)filter).getQuery();
} else {
return new ConstantScoreQuery(filter);
}
}
}
示例2: testWithCachingFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
public void testWithCachingFilter() throws Exception {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
IndexReader reader = writer.getReader();
writer.close();
IndexSearcher searcher = newSearcher(reader);
Query query = new TermQuery(new Term("none", "none"));
QueryWrapperFilter queryFilter = new QueryWrapperFilter(query);
CachingWrapperFilter cachingFilter = new CachingWrapperFilter(queryFilter);
searcher.search(query, cachingFilter, 1);
CachingWrapperFilter cachingFilter2 = new CachingWrapperFilter(queryFilter);
Filter[] chain = new Filter[2];
chain[0] = cachingFilter;
chain[1] = cachingFilter2;
ChainedFilter cf = new ChainedFilter(chain);
// throws java.lang.ClassCastException: org.apache.lucene.util.OpenBitSet cannot be cast to java.util.BitSet
searcher.search(new MatchAllDocsQuery(), cf, 1);
reader.close();
dir.close();
}
示例3: testQueries
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
public void testQueries() throws Exception {
int n = atLeast(4);
for (int i = 0; i < n; i++) {
Filter odd = new QueryWrapperFilter(new TermQuery(new Term("oddeven", "odd")));
assertQuery(new MatchAllDocsQuery(), null);
assertQuery(new TermQuery(new Term("english", "one")), null);
assertQuery(new MatchAllDocsQuery(), odd);
assertQuery(new TermQuery(new Term("english", "four")), odd);
BooleanQuery bq = new BooleanQuery();
bq.add(new TermQuery(new Term("english", "one")), BooleanClause.Occur.SHOULD);
bq.add(new TermQuery(new Term("oddeven", "even")), BooleanClause.Occur.SHOULD);
assertQuery(bq, null);
// force in order
bq.add(new TermQuery(new Term("english", "two")), BooleanClause.Occur.SHOULD);
bq.setMinimumNumberShouldMatch(2);
assertQuery(bq, null);
}
}
示例4: buildFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
@org.hibernate.search.annotations.Factory
public Filter buildFilter(){
QueryParser qp = new QueryParser(Version.LUCENE_CURRENT,field, analyzer);
Query q;
try {
if(allowLuceneSyntax)
q = qp.parse(value);
else
q = qp.parse(QueryParser.escape(value));
} catch (ParseException e) {
org.webdsl.logging.Logger.error("Error while parsing query in field filter: ");
org.webdsl.logging.Logger.error("EXCEPTION",e);
q = new TermQuery(new Term(field, value));
}
Filter filter = new QueryWrapperFilter(q);
filter = new CachingWrapperFilter( filter );
return filter;
}
示例5: getCollectionFilters
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
/**
* Set up the filters for collections - this is for searching within collections.
*
* @param collection - to search within
* @return - created filter
* @throws ParseException
*/
private List<Filter> getCollectionFilters(InstitutionalCollection collection) throws ParseException
{
List<Filter> filters = new LinkedList<Filter>();
//isolate the collection root
Term t = new Term("collection_root_id", NumericUtils.longToPrefixCoded(collection.getTreeRoot().getId()));
Query subQuery = new TermQuery( t );
filters.add(new QueryWrapperFilter(subQuery));
//isolate the range of children
subQuery = NumericRangeQuery.newLongRange("collection_left_value", collection.getLeftValue(), collection.getRightValue(), true, true);
filters.add(new QueryWrapperFilter(subQuery));
return filters;
}
示例6: getSubQueryFilters
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
/**
* Execute the sub query facets and return the search results
* @throws ParseException
* @throws IOException
*/
private List<Filter> getSubQueryFilters( List<FacetFilter> filters,
IndexSearcher searcher) throws ParseException, IOException
{
List<Filter> luceneFilters = new LinkedList<Filter>();
for(FacetFilter filter : filters)
{
if(log.isDebugEnabled())
{
log.debug("adding filter for field " + filter.getField() + " and query " + filter.getQuery());
}
QueryParser subQueryParser = new QueryParser(Version.LUCENE_35, filter.getField(), analyzer);
subQueryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
String fixedQuery = SearchHelper.prepareFacetSearchString(filter.getQuery(), false);
fixedQuery = "\"" + fixedQuery + "\"";
Query subQuery = subQueryParser.parse(fixedQuery);
if(log.isDebugEnabled())
{
log.debug("sub query ing getSubQueryFilters is " + fixedQuery);
}
luceneFilters.add(new QueryWrapperFilter(subQuery));
}
return luceneFilters;
}
示例7: getFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
/**
* Creates a directory filter; also filters a range of pages
* @param constrainField The field that contains the directory info
* @param constrainValues The directories to which the filters shold limit
* @return The created filter
*/
private Filter getFilter(String constrainField, List<String> constrainValues,
int type, int startPage,
int endPage){
BooleanQuery cqry = new BooleanQuery();
if(constrainValues.size() == 1){
cqry.add(new TermQuery(new Term(constrainField, constrainValues.get(0))),
BooleanClause.Occur.MUST);
} else {
for(String s : constrainValues) {
cqry.add(new TermQuery(new Term(constrainField, s)),
BooleanClause.Occur.SHOULD);
}
}
if(type == FileSearcher.QUERY_BOOLEAN && startPage != -1 && endPage != -1) {
cqry.add(NumericRangeQuery.newIntRange("page", startPage, endPage, true, true),
BooleanClause.Occur.MUST);
}
return new QueryWrapperFilter(cqry);
}
示例8: buildNewFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
private Filter buildNewFilter(Query query, ConcurrentMap<String, String> filterAlias, FilterParser filterParser)
throws ParseException {
if (query instanceof BooleanQuery) {
BooleanQuery booleanQuery = (BooleanQuery) query;
BooleanFilter booleanFilter = new BooleanFilter();
for (BooleanClause clause : booleanQuery.clauses()) {
booleanFilter.add(buildNewFilter(clause.getQuery(), filterAlias, filterParser), clause.getOccur());
}
return booleanFilter;
} else if (query instanceof TermQuery) {
TermQuery termQuery = (TermQuery) query;
Term term = termQuery.getTerm();
String key = term.toString();
String queryStr = filterAlias.get(key);
if (queryStr == null) {
return new QueryWrapperFilter(termQuery);
}
String id = getId(key);
return new FilterCache(id, new QueryWrapperFilter(filterParser.parse(queryStr)));
} else {
return new QueryWrapperFilter(query);
}
}
示例9: testFetchRowByRecordIdWithFilterNoHit
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
@Test
public void testFetchRowByRecordIdWithFilterNoHit() throws Exception {
IndexManagerTestReadInterceptor.interceptor = new ReadInterceptor(null) {
@Override
public Filter getFilter() {
return new QueryWrapperFilter(new TermQuery(new Term(FAMILY + ".testcol1", "NOHIT")));
}
};
Selector selector = new Selector().setRowId("row-1").setRecordId("record-1").setRecordOnly(true);
FetchResult fetchResult = new FetchResult();
indexManager.fetchRow(TABLE, selector, fetchResult);
assertFalse(fetchResult.deleted);
assertFalse(fetchResult.exists);
assertEquals(TABLE, fetchResult.table);
assertNull(fetchResult.rowResult);
assertNull(fetchResult.recordResult);
}
示例10: parse
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Query parse() throws SyntaxError {
Method method = Method.valueOf(localParams.get(METHOD, Method.termsFilter.name()));
JoinSpec<T> js = JoinSpec.parse(localParams.get(QueryParsing.V));
Iterator<T> it = js.iterator(this);
if (joinField == null) {
throw new Exception("No XJoin component referenced by query");
}
FieldType ft = req.getSchema().getFieldTypeNoEx(joinField);
Iterator<BytesRef> bytesRefs = new TransformIterator(it, transformer(ft));
if (! bytesRefs.hasNext()) {
return new BooleanQuery.Builder().build(); // matches nothing
}
Query query = method.makeQuery(joinField, bytesRefs);
return new SolrConstantScoreQuery(new QueryWrapperFilter(query));
}
示例11: testSecurityFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
public void testSecurityFilter() throws Exception {
TermQuery query = new TermQuery( //#1
new Term("keywords", "info")); //#1
assertEquals("Both documents match", //#2
2, //#2
TestUtil.hitCount(searcher, query)); //#2
Filter jakeFilter = new QueryWrapperFilter( //#3
new TermQuery(new Term("owner", "jake"))); //#3
TopDocs hits = searcher.search(query, jakeFilter, 10);
assertEquals(1, hits.totalHits); //#4
assertEquals("elwood is safe", //#4
"jake's sensitive info", //#4
searcher.doc(hits.scoreDocs[0].doc) //#4
.get("keywords")); //#4
}
示例12: applyQueryDeletes
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
private static long applyQueryDeletes(Iterable<QueryAndLimit> queriesIter, ReadersAndUpdates rld, final SegmentReader reader) throws IOException {
long delCount = 0;
final AtomicReaderContext readerContext = reader.getContext();
boolean any = false;
for (QueryAndLimit ent : queriesIter) {
Query query = ent.query;
int limit = ent.limit;
final DocIdSet docs = new QueryWrapperFilter(query).getDocIdSet(readerContext, reader.getLiveDocs());
if (docs != null) {
final DocIdSetIterator it = docs.iterator();
if (it != null) {
while(true) {
int doc = it.nextDoc();
if (doc >= limit) {
break;
}
if (!any) {
rld.initWritableLiveDocs();
any = true;
}
if (rld.delete(doc)) {
delCount++;
}
}
}
}
}
return delCount;
}
示例13: getQueryFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
public static Filter getQueryFilter(String query){
try{
WhitespaceAnalyzer sa= new WhitespaceAnalyzer();
QueryParser p = new QueryParser("contents",sa);
Query q = p.parse(query);
Filter filter = new QueryWrapperFilter(q);
return filter;
}catch (Exception e){
return null;
}
}
示例14: fieldQuery
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的package包/类
/**
* Returns a filter that applies a query to an specific field
*/
public static Filter fieldQuery(final Analyzer analyzer, final String field, final String query) {
if (StringUtils.isEmpty(query)) {
return null;
}
QueryParser parser = new QueryParser(LuceneUtils.LUCENE_VERSION, field, analyzer);
try {
Query q = parser.parse(query);
return new QueryWrapperFilter(q);
} catch (ParseException e) {
throw new QueryParseException();
}
}
示例15: spanFilter
import org.apache.lucene.search.QueryWrapperFilter; //导入依赖的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);
}
}