org.apache.lucene.search.Filter Java Examples
The following examples show how to use
org.apache.lucene.search.Filter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AliasBlurFilterCache.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
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); } }
Example #2
Source File: FilterConstructor.java From linden with Apache License 2.0 | 6 votes |
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; }
Example #3
Source File: IndexManagerTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@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); }
Example #4
Source File: BooleanFilterConstructor.java From linden with Apache License 2.0 | 6 votes |
@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; }
Example #5
Source File: GeoNameResolver.java From lucene-geo-gazetteer with Apache License 2.0 | 6 votes |
/** * 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; }
Example #6
Source File: IndexManager.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
private Query getHighlightQuery(Selector selector, String table, FieldManager fieldManager) throws ParseException, BlurException { HighlightOptions highlightOptions = selector.getHighlightOptions(); if (highlightOptions == null) { return null; } org.apache.blur.thrift.generated.Query query = highlightOptions.getQuery(); if (query == null) { return null; } TableContext context = getTableContext(table); Filter preFilter = QueryParserUtil.parseFilter(table, query.recordFilter, false, fieldManager, _filterCache, context); Filter postFilter = QueryParserUtil.parseFilter(table, query.rowFilter, true, fieldManager, _filterCache, context); return QueryParserUtil.parseQuery(query.query, query.rowQuery, fieldManager, postFilter, preFilter, getScoreType(query.scoreType), context); }
Example #7
Source File: TermQueryPrefixTreeStrategy.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Override public Filter makeFilter(SpatialArgs args) { final SpatialOperation op = args.getOperation(); if (op != SpatialOperation.Intersects) throw new UnsupportedSpatialOperation(op); Shape shape = args.getShape(); int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct)); List<Cell> cells = grid.getCells(shape, detailLevel, false,// no parents true);// simplify BytesRef[] terms = new BytesRef[cells.size()]; int i = 0; for (Cell cell : cells) { terms[i++] = new BytesRef(cell.getTokenString()); } return new TermsFilter(getFieldName(), terms); }
Example #8
Source File: UserProfileDataFilterMapper.java From adam with GNU Lesser General Public License v3.0 | 6 votes |
@Nullable protected Filter toFilter(@Nullable Iterable<String> groups) { final Iterator<String> i = groups != null ? groups.iterator() : null; final Filter result; if (i != null && i.hasNext()) { final Filter first = new TermFilter(new Term("group", i.next())); if (i.hasNext()) { final List<Filter> filters = new ArrayList<>(); filters.add(first); while (i.hasNext()) { filters.add(new TermFilter(new Term("group", i.next()))); } result = new ChainedFilter(filters.toArray(new Filter[filters.size()]), OR); } else { result = first; } } else { result = null; } return result; }
Example #9
Source File: BlurSecureIndexSearcher.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
/** * This method is very important!!! It handles rewriting the real query (which * can be a {@link SuperQuery} to have document (record) level filtering or * access control. */ @Override protected Query wrapFilter(Query query, Filter filter) { if (filter == null) { return query; } else if (query instanceof SuperQuery) { SuperQuery superQuery = (SuperQuery) query; Query innerQuery = superQuery.getQuery(); Term primeDocTerm = superQuery.getPrimeDocTerm(); ScoreType scoreType = superQuery.getScoreType(); return new SuperQuery(wrapFilter(innerQuery, filter), scoreType, primeDocTerm); } else if (query instanceof BooleanQuery) { BooleanQuery booleanQuery = (BooleanQuery) query; List<BooleanClause> clauses = booleanQuery.clauses(); for (BooleanClause booleanClause : clauses) { booleanClause.setQuery(wrapFilter(booleanClause.getQuery(), filter)); } return booleanQuery; } else { return new FilteredQuery(query, filter); } }
Example #10
Source File: LindenResultParser.java From linden with Apache License 2.0 | 5 votes |
public LindenResultParser(LindenConfig config, LindenSearchRequest request, IndexSearcher indexSearcher, LindenSnippetGenerator snippetGenerator, Query query, Filter filter, Sort sort) { this.config = config; this.request = request; this.indexSearcher = indexSearcher; this.snippetGenerator = snippetGenerator; this.query = query; this.filter = filter; this.sort = sort; this.sortScoreFieldPos = getSortScoreFieldPos(sort); this.leaves = indexSearcher.getIndexReader().leaves(); }
Example #11
Source File: AliasBlurFilterCache.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public AliasBlurFilterCache(BlurConfiguration configuration) { super(configuration); long _cacheEntries = 100; _preFilterCacheMap = new ConcurrentLinkedHashMap.Builder<FilterKey, Filter>() .maximumWeightedCapacity(_cacheEntries).build(); _postFilterCacheMap = new ConcurrentLinkedHashMap.Builder<FilterKey, Filter>().maximumWeightedCapacity( _cacheEntries).build(); Map<String, String> properties = configuration.getProperties(); for (Entry<String, String> entry : properties.entrySet()) { if (isFilterAlias(entry.getKey())) { String value = entry.getValue(); if (value == null || value.isEmpty()) { continue; } String name = getFilterAlias(entry.getKey()); int index = name.indexOf('.'); String table = name.substring(0, index); String alias = name.substring(index + 1); ConcurrentMap<String, String> aliasFilterMap = _tableAliasFilterMap.get(table); if (aliasFilterMap == null) { aliasFilterMap = new ConcurrentHashMap<String, String>(); _tableAliasFilterMap.put(table, aliasFilterMap); } aliasFilterMap.put(alias, value); } } }
Example #12
Source File: RecursivePrefixTreeStrategy.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public Filter makeFilter(SpatialArgs args) { final SpatialOperation op = args.getOperation(); if (op == SpatialOperation.IsDisjointTo) return new DisjointSpatialFilter(this, args, getFieldName()); Shape shape = args.getShape(); int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct)); final boolean hasIndexedLeaves = true; if (op == SpatialOperation.Intersects) { return new IntersectsPrefixTreeFilter(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, hasIndexedLeaves); } else if (op == SpatialOperation.IsWithin) { return new WithinPrefixTreeFilter(shape, getFieldName(), grid, detailLevel, prefixGridScanLevel, -1);// -1 // flag // is // slower // but // ensures // correct // results } else if (op == SpatialOperation.Contains) { return new ContainsPrefixTreeFilter(shape, getFieldName(), grid, detailLevel); } throw new UnsupportedSpatialOperation(op); }
Example #13
Source File: QueryContext.java From orientdb-lucene with Apache License 2.0 | 5 votes |
public QueryContext(OCommandContext context, IndexSearcher searcher, Query query, Filter filter, Sort sort) { this.context = context; this.searcher = searcher; this.query = query; this.filter = filter; this.sort = sort; initCFG(); }
Example #14
Source File: ChildrenConstantScoreQuery.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Weight doCreateWeight(IndexSearcher searcher, boolean needsScores) throws IOException { SearchContext sc = SearchContext.current(); IndexParentChildFieldData globalIfd = parentChildIndexFieldData.loadGlobal((DirectoryReader)searcher.getIndexReader()); final long valueCount; List<LeafReaderContext> leaves = searcher.getIndexReader().leaves(); if (globalIfd == null || leaves.isEmpty()) { return new BooleanQuery.Builder().build().createWeight(searcher, needsScores); } else { AtomicParentChildFieldData afd = globalIfd.load(leaves.get(0)); SortedDocValues globalValues = afd.getOrdinalsValues(parentType); valueCount = globalValues.getValueCount(); } if (valueCount == 0) { return new BooleanQuery.Builder().build().createWeight(searcher, needsScores); } ParentOrdCollector collector = new ParentOrdCollector(globalIfd, valueCount, parentType); searcher.search(childQuery, collector); final long remaining = collector.foundParents(); if (remaining == 0) { return new BooleanQuery.Builder().build().createWeight(searcher, needsScores); } Filter shortCircuitFilter = null; if (remaining <= shortCircuitParentDocSet) { shortCircuitFilter = ParentIdsFilter.createShortCircuitFilter( nonNestedDocsFilter, sc, parentType, collector.values, collector.parentOrds, remaining ); } return new ParentWeight(this, parentFilter, globalIfd, shortCircuitFilter, collector, remaining); }
Example #15
Source File: BlurSecureIndexSearcherTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void testQueryFilterWrap1() throws IOException { IndexReader r = getIndexReader(); AccessControlFactory accessControlFactory = new FilterAccessControlFactory(); Collection<String> readAuthorizations = new ArrayList<String>(); Collection<String> discoverAuthorizations = new ArrayList<String>(); Set<String> discoverableFields = new HashSet<String>(Arrays.asList("rowid")); BlurSecureIndexSearcher blurSecureIndexSearcher = new BlurSecureIndexSearcher(r, null, accessControlFactory, readAuthorizations, discoverAuthorizations, discoverableFields, null); Query wrapFilter; Query query = new TermQuery(new Term("a", "b")); Filter filter = new Filter() { @Override public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException { throw new RuntimeException("Not implemented."); } }; { Term primeDocTerm = new Term(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE); ScoreType scoreType = ScoreType.SUPER; SuperQuery superQuery = new SuperQuery(query, scoreType, primeDocTerm); wrapFilter = blurSecureIndexSearcher.wrapFilter(superQuery, filter); System.out.println(wrapFilter); } { assertTrue(wrapFilter instanceof SuperQuery); SuperQuery sq = (SuperQuery) wrapFilter; Query inner = sq.getQuery(); assertTrue(inner instanceof FilteredQuery); FilteredQuery filteredQuery = (FilteredQuery) inner; Query innerFilteredQuery = filteredQuery.getQuery(); assertEquals(innerFilteredQuery, query); assertTrue(filteredQuery.getFilter() == filter); } }
Example #16
Source File: ChildrenConstantScoreQuery.java From Elasticsearch with Apache License 2.0 | 5 votes |
public ParentWeight(Query query, Filter parentFilter, IndexParentChildFieldData globalIfd, Filter shortCircuitFilter, ParentOrdCollector collector, long remaining) { super(query); this.parentFilter = parentFilter; this.globalIfd = globalIfd; this.shortCircuitFilter = shortCircuitFilter; this.collector = collector; this.remaining = remaining; }
Example #17
Source File: IndexManagerTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void testQuerySuperQueryTrueWithFilter() throws Exception { IndexManagerTestReadInterceptor.interceptor = new ReadInterceptor(null) { @Override public Filter getFilter() { return new QueryWrapperFilter(new TermQuery(new Term(FAMILY + ".testcol2", "value2"))); } }; BlurQuery blurQuery = new BlurQuery(); blurQuery.query = new Query(); blurQuery.query.query = "test-family.testcol1:value1"; blurQuery.query.rowQuery = true; blurQuery.query.scoreType = ScoreType.SUPER; blurQuery.fetch = 10; blurQuery.minimumNumberOfResults = Long.MAX_VALUE; blurQuery.maxQueryTime = Long.MAX_VALUE; blurQuery.uuid = "1"; BlurResultIterable iterable = indexManager.query(TABLE, blurQuery, null); assertEquals(1, iterable.getTotalResults()); BlurIterator<BlurResult, BlurException> iterator = iterable.iterator(); while (iterator.hasNext()) { BlurResult result = iterator.next(); Selector selector = new Selector().setLocationId(result.getLocationId()); FetchResult fetchResult = new FetchResult(); indexManager.fetchRow(TABLE, selector, fetchResult); assertNotNull(fetchResult.rowResult); assertNull(fetchResult.recordResult); } assertFalse(indexManager.currentQueries(TABLE).isEmpty()); Thread.sleep(2000);// wait for cleanup to fire assertTrue(indexManager.currentQueries(TABLE).isEmpty()); }
Example #18
Source File: ChildrenConstantScoreQuery.java From Elasticsearch with Apache License 2.0 | 5 votes |
public ChildrenConstantScoreQuery(IndexParentChildFieldData parentChildIndexFieldData, Query childQuery, String parentType, String childType, Filter parentFilter, int shortCircuitParentDocSet, BitSetProducer nonNestedDocsFilter) { this.parentChildIndexFieldData = parentChildIndexFieldData; this.parentFilter = parentFilter; this.parentType = parentType; this.childType = childType; this.childQuery = childQuery; this.shortCircuitParentDocSet = shortCircuitParentDocSet; this.nonNestedDocsFilter = nonNestedDocsFilter; }
Example #19
Source File: IndexManagerTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void testFetchRowByRowIdWithFilterNoRow() throws Exception { IndexManagerTestReadInterceptor.interceptor = new ReadInterceptor(null) { @Override public Filter getFilter() { return new QueryWrapperFilter(new TermQuery(new Term(FAMILY + ".testcol12", "NOROW-1"))); } }; Selector selector = new Selector().setRowId("row-6"); FetchResult fetchResult = new FetchResult(); indexManager.fetchRow(TABLE, selector, fetchResult); assertTrue(fetchResult.exists); assertFalse(fetchResult.deleted); assertNull(fetchResult.rowResult.row.records); }
Example #20
Source File: DeviceFilterFactory.java From maven-framework-project with MIT License | 5 votes |
/** * When a @FullTextFilterDef annotation associates this factory class with a given name, and a "FullTextQuery.enableFullTextFilter()" is * called with that name as its input parameter, then this method is used to return a Filter with the actual filtering logic. It is * the @Factory annotation that designates this method as having that responsibility for this factory class. */ @Factory public Filter getFilter() { StringTokenizer tokenzier = new StringTokenizer(deviceName.toLowerCase()); PhraseQuery query = new PhraseQuery(); while(tokenzier.hasMoreTokens()) { // By default, field values were converted to lower-case when indexed by Lucene. So be sure to // convert search terms to lower-case in order to make them match. Term term = new Term("supportedDevices.name", tokenzier.nextToken().toLowerCase()); query.add(term); } Filter filter = new QueryWrapperFilter(query); return new CachingWrapperFilter(filter); }
Example #21
Source File: AliasBlurFilterCache.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public Filter storePreFilter(String table, String filterStr, Filter filter, FilterParser filterParser) throws ParseException { if (filter instanceof QueryWrapperFilter) { QueryWrapperFilter queryWrapperFilter = (QueryWrapperFilter) filter; Query query = queryWrapperFilter.getQuery(); Filter newFilter = buildNewFilter(query, _tableAliasFilterMap.get(table), filterParser); FilterKey key = new FilterKey(table, filterStr); _preFilterCacheMap.put(key, newFilter); return newFilter; } return filter; }
Example #22
Source File: IndexManagerTestReadInterceptor.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Override public Filter getFilter() { if (interceptor == null) { return null; } return interceptor.getFilter(); }
Example #23
Source File: ChildrenQuery.java From Elasticsearch with Apache License 2.0 | 5 votes |
public ChildrenQuery(ParentChildIndexFieldData ifd, String parentType, String childType, Filter parentFilter, Query childQuery, ScoreType scoreType, int minChildren, int maxChildren, int shortCircuitParentDocSet, BitSetProducer nonNestedDocsFilter) { this.ifd = ifd; this.parentType = parentType; this.childType = childType; this.parentFilter = parentFilter; this.childQuery = childQuery; this.scoreType = scoreType; this.shortCircuitParentDocSet = shortCircuitParentDocSet; this.nonNestedDocsFilter = nonNestedDocsFilter; assert maxChildren == 0 || minChildren <= maxChildren; this.minChildren = minChildren > 1 ? minChildren : 0; this.maxChildren = maxChildren; }
Example #24
Source File: AliasBlurFilterCacheTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void testFetchPreFilterNotEmpty() throws IOException, BlurException, ParseException { BlurConfiguration configuration = new BlurConfiguration(); configuration.set("blur.filter.alias.test.super:abc1", "(fam1.f1:abc1 fam2.f1:abc1)"); configuration.set("blur.filter.alias.test.super:abc2", "(fam1.f1:abc2 fam2.f1:abc2)"); configuration.set("blur.filter.alias.test.super:abc3", "(fam1.f1:abc3 fam2.f1:abc3)"); AliasBlurFilterCache defaultBlurFilterCache = new AliasBlurFilterCache(configuration); TableDescriptor tableDescriptor = new TableDescriptor(); tableDescriptor.setName(TABLE); tableDescriptor.setTableUri("file:///"); final TableContext tableContext = TableContext.create(tableDescriptor); final BaseFieldManager fieldManager = getFieldManager(new WhitespaceAnalyzer(LUCENE_VERSION)); Filter filter = QueryParserUtil.parseFilter(TABLE, TEST_FILTER, false, fieldManager, defaultBlurFilterCache, tableContext); Filter filterToRun = defaultBlurFilterCache.storePreFilter(TABLE, TEST_FILTER, filter, new FilterParser() { @Override public Query parse(String query) throws ParseException { return new SuperParser(LUCENE_VERSION, fieldManager, false, null, ScoreType.CONSTANT, tableContext .getDefaultPrimeDocTerm()).parse(query); } }); assertNotNull(filterToRun); assertEquals("BooleanFilter(" + "FilterCache(super-abc1,QueryWrapperFilter(fam1.f1:abc1 fam2.f1:abc1)) " + "FilterCache(super-abc2,QueryWrapperFilter(fam1.f1:abc2 fam2.f1:abc2)) " + "FilterCache(super-abc3,QueryWrapperFilter(fam1.f1:abc3 fam2.f1:abc3))" + ")", filterToRun.toString()); Filter fetchPreFilter = defaultBlurFilterCache.fetchPreFilter(TABLE, TEST_FILTER); assertNotNull(fetchPreFilter); assertTrue(filterToRun == fetchPreFilter); }
Example #25
Source File: IndexManager.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public String parseQuery(String table, org.apache.blur.thrift.generated.Query simpleQuery) throws ParseException, BlurException { TableContext context = getTableContext(table); FieldManager fieldManager = context.getFieldManager(); Filter preFilter = QueryParserUtil.parseFilter(table, simpleQuery.recordFilter, false, fieldManager, _filterCache, context); Filter postFilter = QueryParserUtil.parseFilter(table, simpleQuery.rowFilter, true, fieldManager, _filterCache, context); Query userQuery = QueryParserUtil.parseQuery(simpleQuery.query, simpleQuery.rowQuery, fieldManager, postFilter, preFilter, getScoreType(simpleQuery.scoreType), context); return userQuery.toString(); }
Example #26
Source File: IndexManager.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private Query[] getFacetQueries(BlurQuery blurQuery, FieldManager fieldManager, TableContext context, Filter postFilter, Filter preFilter) throws ParseException { int size = blurQuery.facets.size(); Query[] queries = new Query[size]; for (int i = 0; i < size; i++) { queries[i] = QueryParserUtil.parseQuery(blurQuery.facets.get(i).queryStr, blurQuery.query.rowQuery, fieldManager, postFilter, preFilter, ScoreType.CONSTANT, context); } return queries; }
Example #27
Source File: AliasBlurFilterCacheTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void testFetchPreFilterEmpty() throws IOException { BlurConfiguration configuration = new BlurConfiguration(); AliasBlurFilterCache defaultBlurFilterCache = new AliasBlurFilterCache(configuration); Filter fetchPreFilter = defaultBlurFilterCache.fetchPreFilter(TABLE, TEST_FILTER); assertNull(fetchPreFilter); }
Example #28
Source File: IndexManager.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static boolean isFiltered(int notAdjustedDocId, IndexReader reader, Filter filter) throws IOException { if (filter == null) { return false; } if (reader instanceof BaseCompositeReader) { BaseCompositeReader<IndexReader> indexReader = (BaseCompositeReader<IndexReader>) reader; List<? extends IndexReader> sequentialSubReaders = BaseCompositeReaderUtil.getSequentialSubReaders(indexReader); int readerIndex = BaseCompositeReaderUtil.readerIndex(indexReader, notAdjustedDocId); int readerBase = BaseCompositeReaderUtil.readerBase(indexReader, readerIndex); int docId = notAdjustedDocId - readerBase; IndexReader orgReader = sequentialSubReaders.get(readerIndex); SegmentReader sReader = AtomicReaderUtil.getSegmentReader(orgReader); if (sReader != null) { SegmentReader segmentReader = (SegmentReader) sReader; DocIdSet docIdSet = filter.getDocIdSet(segmentReader.getContext(), segmentReader.getLiveDocs()); DocIdSetIterator iterator = docIdSet.iterator(); if (iterator == null) { return true; } if (iterator.advance(docId) == docId) { return false; } return true; } throw new RuntimeException("Reader has to be a SegmentReader [" + orgReader + "]"); } else { throw new RuntimeException("Reader has to be a BaseCompositeReader [" + reader + "]"); } }
Example #29
Source File: QueryParserUtil.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
public static Query parseQuery(String query, boolean superQueryOn, FieldManager fieldManager, Filter postFilter, Filter preFilter, ScoreType scoreType, TableContext tableContext) throws ParseException { Query result = new SuperParser(LUCENE_VERSION, fieldManager, superQueryOn, preFilter, scoreType, tableContext.getDefaultPrimeDocTerm()).parse(query); if (postFilter == null) { return result; } return new FilteredQuery(result, postFilter); }
Example #30
Source File: BlurUtil.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private static OpenBitSet getDocsToFetch(AtomicReader atomicReader, Selector selector, int primeDocRowId, int numberOfDocsInRow, Bits liveDocs, Filter filter, AtomicInteger totalRecords) throws IOException { Set<String> alreadyProcessed = new HashSet<String>(); OpenBitSet bits = new OpenBitSet(numberOfDocsInRow); OpenBitSet mask = null; if (filter != null) { DocIdSet docIdSet = filter.getDocIdSet(atomicReader.getContext(), liveDocs); mask = getMask(docIdSet, primeDocRowId, numberOfDocsInRow); } Set<String> columnFamiliesToFetch = selector.getColumnFamiliesToFetch(); boolean fetchAll = true; if (columnFamiliesToFetch != null) { fetchAll = false; applyFamilies(alreadyProcessed, bits, columnFamiliesToFetch, atomicReader, primeDocRowId, numberOfDocsInRow, liveDocs); } Map<String, Set<String>> columnsToFetch = selector.getColumnsToFetch(); if (columnsToFetch != null) { fetchAll = false; applyColumns(alreadyProcessed, bits, columnsToFetch, atomicReader, primeDocRowId, numberOfDocsInRow, liveDocs); } if (fetchAll) { bits.set(0, numberOfDocsInRow); } if (mask != null) { bits.intersect(mask); } totalRecords.set((int) bits.cardinality()); return bits; }