本文整理匯總了Java中org.apache.lucene.search.Filter類的典型用法代碼示例。如果您正苦於以下問題:Java Filter類的具體用法?Java Filter怎麽用?Java Filter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Filter類屬於org.apache.lucene.search包,在下文中一共展示了Filter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: limitingFilter
import org.apache.lucene.search.Filter; //導入依賴的package包/類
private Optional<Query> limitingFilter(Query query, boolean isNegated) {
if (query instanceof SpanQuery) {
return limitingFilterForSpan((SpanQuery) query, isNegated);
} else if (query instanceof Filter) {
return Optional.of(query);
} else if (query instanceof BooleanQuery) {
return boolQuery((BooleanQuery) query, isNegated);
} else if (query instanceof TermQuery) {
return Optional.of(query);
} else if (query instanceof PhraseQuery) {
return phraseFilter((PhraseQuery) query, isNegated);
} else if (query instanceof MultiTermQuery) {
return Optional.of(query);
} else if (query instanceof WildcardPhraseQuery) {
return wildcardPhraseFilter((WildcardPhraseQuery) query, isNegated);
} else if (query instanceof ToParentBlockJoinQuery) {
//This can be really bad for performance, if the nested query contains expensive operations (phrases/spans)
//On the other hand, it is only slow if the field actually has any data, and we currently do not have
// any data in the only nested text field (enrichments.sentences)
return Optional.of(query);
} else {
//This should never happen, but if it does, it might be really bad for performance
//logger.warn("failed to limit query, this should never happen. Query : [{}]", query.toString());
return Optional.of(query);
}
}
示例2: searchRequestToBitSet
import org.apache.lucene.search.Filter; //導入依賴的package包/類
private OpenBitSet searchRequestToBitSet(@Nullable final Search searchreq, IndexSearcher searcher,
IndexReader reader) throws IOException
{
if( searchreq != null )
{
Filter filters = getFilter(searchreq);
Query query = getQuery(searchreq, null, false);
BitSetCollector collector = new BitSetCollector();
searcher.search(query, filters, collector);
return collector.getBitSet();
}
else
{
return (OpenBitSet) new InstitutionFilter().getDocIdSet(reader);
}
}
示例3: getFilter
import org.apache.lucene.search.Filter; //導入依賴的package包/類
@Override
public Filter getFilter(Element e) throws ParserException {
List<BytesRef> terms = new ArrayList<>();
String text = DOMUtils.getNonBlankTextOrFail(e);
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
TokenStream ts = null;
try {
ts = analyzer.tokenStream(fieldName, text);
TermToBytesRefAttribute termAtt = ts.addAttribute(TermToBytesRefAttribute.class);
BytesRef bytes = termAtt.getBytesRef();
ts.reset();
while (ts.incrementToken()) {
termAtt.fillBytesRef();
terms.add(BytesRef.deepCopyOf(bytes));
}
ts.end();
}
catch (IOException ioe) {
throw new RuntimeException("Error constructing terms from index:" + ioe);
} finally {
IOUtils.closeWhileHandlingException(ts);
}
return new TermsFilter(fieldName, terms);
}
示例4: getFilter
import org.apache.lucene.search.Filter; //導入依賴的package包/類
@Override
public Filter getFilter(Element e) throws ParserException {
BooleanFilter bf = new BooleanFilter();
NodeList nl = e.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node.getNodeName().equals("Clause")) {
Element clauseElem = (Element) node;
BooleanClause.Occur occurs = BooleanQueryBuilder.getOccursValue(clauseElem);
Element clauseFilter = DOMUtils.getFirstChildOrFail(clauseElem);
Filter f = factory.getFilter(clauseFilter);
bf.add(new FilterClause(f, occurs));
}
}
return bf;
}
示例5: getFilter
import org.apache.lucene.search.Filter; //導入依賴的package包/類
@Override
public Filter getFilter(Element e) throws ParserException {
String fieldName = DOMUtils.getAttributeWithInheritanceOrFail(e, "fieldName");
DuplicateFilter df = new DuplicateFilter(fieldName);
String keepMode = DOMUtils.getAttribute(e, "keepMode", "first");
if (keepMode.equalsIgnoreCase("first")) {
df.setKeepMode(DuplicateFilter.KeepMode.KM_USE_FIRST_OCCURRENCE);
} else if (keepMode.equalsIgnoreCase("last")) {
df.setKeepMode(DuplicateFilter.KeepMode.KM_USE_LAST_OCCURRENCE);
} else {
throw new ParserException("Illegal keepMode attribute in DuplicateFilter:" + keepMode);
}
String processingMode = DOMUtils.getAttribute(e, "processingMode", "full");
if (processingMode.equalsIgnoreCase("full")) {
df.setProcessingMode(DuplicateFilter.ProcessingMode.PM_FULL_VALIDATION);
} else if (processingMode.equalsIgnoreCase("fast")) {
df.setProcessingMode(DuplicateFilter.ProcessingMode.PM_FAST_INVALIDATION);
} else {
throw new ParserException("Illegal processingMode attribute in DuplicateFilter:" + processingMode);
}
return df;
}
示例6: construct
import org.apache.lucene.search.Filter; //導入依賴的package包/類
@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws Exception {
List<LindenBooleanSubFilter> booleanSubFilterList = lindenFilter.getBooleanFilter().getFilters();
BooleanFilter booleanFilter = new BooleanFilter();
for (LindenBooleanSubFilter booleanSubFilter : booleanSubFilterList) {
LindenFilter subFilter = booleanSubFilter.getFilter();
switch (booleanSubFilter.clause) {
case MUST:
booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.MUST);
continue;
case SHOULD:
booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.SHOULD);
continue;
case MUST_NOT:
booleanFilter.add(FilterConstructor.constructFilter(subFilter, config), BooleanClause.Occur.MUST_NOT);
}
}
return booleanFilter;
}
示例7: constructFilter
import org.apache.lucene.search.Filter; //導入依賴的package包/類
public static Filter constructFilter(LindenFilter lindenFilter, LindenConfig config) throws Exception {
if (lindenFilter == null) {
return null;
}
if (lindenFilter.isSetTermFilter()) {
return TERM_FILTER_CONSTRUCTOR.construct(lindenFilter, config);
} else if (lindenFilter.isSetRangeFilter()) {
return RANGE_FILTER_CONSTRUCTOR.construct(lindenFilter, config);
} else if (lindenFilter.isSetQueryFilter()) {
return QUERY_FILTER_CONSTRUCTOR.construct(lindenFilter, config);
} else if (lindenFilter.isSetBooleanFilter()) {
return BOOLEAN_FILTER_CONSTRUCTOR.construct(lindenFilter, config);
} else if (lindenFilter.isSetSpatialFilter()) {
return SPATIAL_FILTER_CONSTRUCTOR.construct(lindenFilter, config);
} else if (lindenFilter.isSetNotNullFieldFilter()) {
return NOT_NULL_FIELD_FILTER_CONSTRUCTOR.construct(lindenFilter, config);
}
return null;
}
示例8: terms
import org.apache.lucene.search.Filter; //導入依賴的package包/類
/**
* Returns a filter that forces a given field to be one of the given values
*/
public static Filter terms(final String field, final Collection<?> values) {
if (CollectionUtils.isEmpty(values)) {
return null;
}
final TermsFilter filter = new TermsFilter();
int count = 0;
for (final Object object : values) {
final String term = object == null ? null : StringUtils.trimToNull("" + object);
if (term != null) {
/* todo addterm*/
//filter.addTerm(new Term(field, term));
count++;
}
}
return count == 0 ? null : filter;
}
示例9: searchNearby
import org.apache.lucene.search.Filter; //導入依賴的package包/類
/**
* Returns a list of location near a certain coordinate.
* @param latitude, @param longitude - Center of search area
* @param distanceInMiles - Search Radius in miles
* @param indexerPath - Path to Lucene index
* @param count - Upper bound to number of results
* @return - List of locations sorted by population
* @throws IOException
*/
public List<Location> searchNearby(Double latitude, Double longitude, Double distanceInMiles, String indexerPath, int count) throws IOException {
double distanceInDeg = DistanceUtils.dist2Degrees(distanceInMiles,DistanceUtils.EARTH_EQUATORIAL_RADIUS_MI);
SpatialArgs spatialArgs = new SpatialArgs(SpatialOperation.IsWithin,
ctx.makeCircle(longitude,latitude, distanceInDeg));
String key = latitude+"-"+longitude;
Filter filter = strategy.makeFilter(spatialArgs);
IndexSearcher searcher = new IndexSearcher(createIndexReader(indexerPath));
Sort sort = new Sort(populationSort);
TopDocs topDocs = searcher.search(new MatchAllDocsQuery(), filter, count, sort);
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
HashMap<String, List<Location>> allCandidates = new HashMap<String, List<Location>>();
getMatchingCandidates(searcher, allCandidates, key, scoreDocs);
List<Location> results = allCandidates.get(key);
return results;
}
示例10: build
import org.apache.lucene.search.Filter; //導入依賴的package包/類
@Override
public SpatialQueryContext build(Map<String, Object> query) throws Exception {
Shape shape = parseShape(query);
System.out.println("qui:: " + shape);
SpatialStrategy strategy = manager.strategy();
if (isOnlyBB(strategy)) {
shape = shape.getBoundingBox();
}
SpatialArgs args1 = new SpatialArgs(SpatialOperation.IsWithin, shape);
// SpatialArgs args2 = new SpatialArgs(SpatialOperation., shape);
Geometry geo = OShapeFactory.INSTANCE.toGeometry(shape);
Filter filter = strategy.makeFilter(args1);
return new SpatialQueryContext(null, manager.searcher(), new MatchAllDocsQuery(), filter);
}
示例11: testGetFilterHandleNumericParseError
import org.apache.lucene.search.Filter; //導入依賴的package包/類
public void testGetFilterHandleNumericParseError() throws Exception {
NumericRangeFilterBuilder filterBuilder = new NumericRangeFilterBuilder();
filterBuilder.setStrictMode(false);
String xml = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";
Document doc = getDocumentFromString(xml);
Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
Directory ramDir = newDirectory();
IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(null));
writer.commit();
try {
AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(ramDir));
try {
assertNull(filter.getDocIdSet(reader.getContext(), reader.getLiveDocs()));
}
finally {
reader.close();
}
}
finally {
writer.commit();
writer.close();
ramDir.close();
}
}
示例12: makeQueryFromShape
import org.apache.lucene.search.Filter; //導入依賴的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);
}
}
}
示例13: testSingleFilter
import org.apache.lucene.search.Filter; //導入依賴的package包/類
public void testSingleFilter() throws Exception {
ChainedFilter chain = getChainedFilter(new Filter[] {dateFilter}, null);
int numHits = searcher.search(query, chain, 1000).totalHits;
assertEquals(MAX, numHits);
chain = new ChainedFilter(new Filter[] {bobFilter});
numHits = searcher.search(query, chain, 1000).totalHits;
assertEquals(MAX / 2, numHits);
chain = getChainedFilter(new Filter[] {bobFilter}, new int[] {ChainedFilter.AND});
TopDocs hits = searcher.search(query, chain, 1000);
numHits = hits.totalHits;
assertEquals(MAX / 2, numHits);
assertEquals("bob", searcher.doc(hits.scoreDocs[0].doc).get("owner"));
chain = getChainedFilter(new Filter[] {bobFilter}, new int[] {ChainedFilter.ANDNOT});
hits = searcher.search(query, chain, 1000);
numHits = hits.totalHits;
assertEquals(MAX / 2, numHits);
assertEquals("sue", searcher.doc(hits.scoreDocs[0].doc).get("owner"));
}
示例14: testANDNOT
import org.apache.lucene.search.Filter; //導入依賴的package包/類
public void testANDNOT() throws Exception {
ChainedFilter chain = getChainedFilter(
new Filter[]{dateFilter, sueFilter},
new int[] {ChainedFilter.AND, ChainedFilter.ANDNOT});
TopDocs hits = searcher.search(query, chain, 1000);
assertEquals("ANDNOT matches just bob",
MAX / 2, hits.totalHits);
assertEquals("bob", searcher.doc(hits.scoreDocs[0].doc).get("owner"));
chain = getChainedFilter(
new Filter[]{bobFilter, bobFilter},
new int[] {ChainedFilter.ANDNOT, ChainedFilter.ANDNOT});
hits = searcher.search(query, chain, 1000);
assertEquals("ANDNOT bob ANDNOT bob matches all sues",
MAX / 2, hits.totalHits);
assertEquals("sue", searcher.doc(hits.scoreDocs[0].doc).get("owner"));
}
示例15: testWithCachingFilter
import org.apache.lucene.search.Filter; //導入依賴的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();
}