org.apache.lucene.search.QueryWrapperFilter Java Examples
The following examples show how to use
org.apache.lucene.search.QueryWrapperFilter.
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: 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 #3
Source File: XJoinQParserPlugin.java From BioSolr with Apache License 2.0 | 6 votes |
@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)); }
Example #4
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 #5
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 #6
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 #7
Source File: FilterCacheTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test1() throws IOException { Filter filter = new QueryWrapperFilter(new TermQuery(new Term("f1", "t1"))); FilterCache filterCache = new FilterCache("filter1", filter); RAMDirectory directory = new RAMDirectory(); writeDocs(filterCache, directory); DirectoryReader reader = DirectoryReader.open(directory); IndexSearcher searcher = new IndexSearcher(reader); Query query = new TermQuery(new Term("f2", "t2")); TopDocs topDocs1 = searcher.search(query, filterCache, 10); assertEquals(1, filterCache.getMisses()); assertEquals(0, filterCache.getHits()); assertEquals(1, topDocs1.totalHits); TopDocs topDocs2 = searcher.search(query, filterCache, 10); assertEquals(1, filterCache.getMisses()); assertEquals(1, filterCache.getHits()); assertEquals(1, topDocs2.totalHits); TopDocs topDocs3 = searcher.search(query, filterCache, 10); assertEquals(1, filterCache.getMisses()); assertEquals(2, filterCache.getHits()); assertEquals(1, topDocs3.totalHits); }
Example #8
Source File: XJoinQParserPlugin.java From BioSolr with Apache License 2.0 | 5 votes |
@Override Filter makeFilter(String fname, Iterator<BytesRef> it) { BooleanQuery bq = new BooleanQuery(true); while (it.hasNext()) { bq.add(new TermQuery(new Term(fname, it.next())), BooleanClause.Occur.SHOULD); } return new QueryWrapperFilter(bq); }
Example #9
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 #10
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 #11
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 #12
Source File: QueryFilterConstructor.java From linden with Apache License 2.0 | 4 votes |
@Override protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws Exception { QueryWrapperFilter filter = new QueryWrapperFilter( QueryConstructor.constructQuery(lindenFilter.getQueryFilter().getQuery(), config)); return filter; }
Example #13
Source File: NamespaceConstraintFilter.java From webdsl with Apache License 2.0 | 4 votes |
@org.hibernate.search.annotations.Factory public Filter buildFilter(){ Filter filter = new QueryWrapperFilter( SearchHelper.namespaceQuery(namespace) ); filter = new CachingWrapperFilter( filter ); return filter; }
Example #14
Source File: Condition.java From stratio-cassandra with Apache License 2.0 | 2 votes |
/** * Returns the Lucene {@link Filter} representation of this condition. * * @param schema The schema to be used. * @return The Lucene {@link Filter} representation of this condition. */ public Filter filter(Schema schema) { return new QueryWrapperFilter(query(schema)); }