org.apache.solr.common.params.CursorMarkParams Java Examples
The following examples show how to use
org.apache.solr.common.params.CursorMarkParams.
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: MCROAISolrSearcher.java From mycore with GNU General Public License v3.0 | 6 votes |
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException { SolrQuery query = getBaseQuery(CommonParams.Q); // set support if (this.set != null) { String setId = this.set.getSetId(); MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId); setConfig.getHandler().apply(this.set, query); } // from & until if (this.from != null || this.until != null) { String fromUntilCondition = buildFromUntilCondition(this.from, this.until); query.add(CommonParams.FQ, fromUntilCondition); } // cursor query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START)); query.set(CommonParams.ROWS, String.valueOf(getPartitionSize())); query.set(CommonParams.SORT, "id asc"); // do the query SolrClient solrClient = MCRSolrClientFactory.getMainSolrClient(); QueryResponse response = solrClient.query(query); Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults()); return new MCROAISolrResult(response, d -> toHeader(d, setResolver)); }
Example #2
Source File: TestSolrEntityProcessorUnit.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testPagingQuery() { SolrEntityProcessor processor = new NoNextMockProcessor() ; HashMap<String,String> entityAttrs = new HashMap<String,String>(){{ put(SolrEntityProcessor.SOLR_SERVER,"http://route:66/no"); if (random().nextBoolean()) { List<String> noCursor = Arrays.asList("","false",CursorMarkParams.CURSOR_MARK_START);//only 'true' not '*' Collections.shuffle(noCursor, random()); put(CursorMarkParams.CURSOR_MARK_PARAM, noCursor.get(0)); }}}; processor.init(getContext(null, null, null, null, Collections.emptyList(), entityAttrs)); try { processor.buildIterator(); SolrQuery query = new SolrQuery(); ((SolrDocumentListIterator) processor.rowIterator).passNextPage(query); assertEquals("0", query.get(CommonParams.START)); assertNull( query.get(CursorMarkParams.CURSOR_MARK_PARAM)); assertNotNull( query.get(CommonParams.TIME_ALLOWED)); }finally { processor.destroy(); } }
Example #3
Source File: TestSolrEntityProcessorUnit.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testCursorQuery() { SolrEntityProcessor processor = new NoNextMockProcessor() ; HashMap<String,String> entityAttrs = new HashMap<String,String>(){{ put(SolrEntityProcessor.SOLR_SERVER,"http://route:66/no"); put(CursorMarkParams.CURSOR_MARK_PARAM,"true"); }}; processor.init(getContext(null, null, null, null, Collections.emptyList(), entityAttrs)); try { processor.buildIterator(); SolrQuery query = new SolrQuery(); ((SolrDocumentListIterator) processor.rowIterator).passNextPage(query); assertNull(query.get(CommonParams.START)); assertEquals(CursorMarkParams.CURSOR_MARK_START, query.get(CursorMarkParams.CURSOR_MARK_PARAM)); assertNull( query.get(CommonParams.TIME_ALLOWED)); }finally { processor.destroy(); } }
Example #4
Source File: QueryComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void regularFinishStage(ResponseBuilder rb) { // We may not have been able to retrieve all the docs due to an // index change. Remove any null documents. for (Iterator<SolrDocument> iter = rb.getResponseDocs().iterator(); iter.hasNext();) { if (iter.next() == null) { iter.remove(); rb.getResponseDocs().setNumFound(rb.getResponseDocs().getNumFound()-1); } } rb.rsp.addResponse(rb.getResponseDocs()); if (null != rb.getNextCursorMark()) { rb.rsp.add(CursorMarkParams.CURSOR_MARK_NEXT, rb.getNextCursorMark().getSerializedTotem()); } }
Example #5
Source File: DelegatingCursor.java From dubbox with Apache License 2.0 | 5 votes |
protected DelegatingCursor(SolrQuery query, String initalCursorMark) { this.referenceQuery = query; this.cursorMark = StringUtils.hasText(initalCursorMark) ? initalCursorMark : CursorMarkParams.CURSOR_MARK_START; this.state = State.REDAY; this.delegate = Collections.<T> emptyList().iterator(); }
Example #6
Source File: DelegatingCursor.java From dubbox with Apache License 2.0 | 5 votes |
private void load(String cursorMark) { SolrQuery query = referenceQuery.getCopy(); query.set(CursorMarkParams.CURSOR_MARK_PARAM, this.getCursorMark()); PartialResult<T> result = doLoad(query); process(result); }
Example #7
Source File: SolrEntityProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * The following method changes the rowIterator mutable field. It requires * external synchronization. */ protected void buildIterator() { if (rowIterator != null) { SolrDocumentListIterator documentListIterator = (SolrDocumentListIterator) rowIterator; if (!documentListIterator.hasNext() && documentListIterator.hasMoreRows()) { nextPage(); } } else { boolean cursor = Boolean.parseBoolean(context .getResolvedEntityAttribute(CursorMarkParams.CURSOR_MARK_PARAM)); rowIterator = !cursor ? new SolrDocumentListIterator(new SolrDocumentList()) : new SolrDocumentListCursor(new SolrDocumentList(), CursorMarkParams.CURSOR_MARK_START); nextPage(); } }
Example #8
Source File: SolrEntityProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override protected void passNextPage(SolrQuery solrQuery) { String timeoutAsString = context.getResolvedEntityAttribute(TIMEOUT); if (timeoutAsString != null) { throw new DataImportHandlerException(SEVERE,"cursorMark can't be used with timeout"); } solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); }
Example #9
Source File: QueryComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
private void doProcessUngroupedSearch(ResponseBuilder rb, QueryCommand cmd, QueryResult result) throws IOException { SolrQueryRequest req = rb.req; SolrQueryResponse rsp = rb.rsp; SolrIndexSearcher searcher = req.getSearcher(); try { searcher.search(result, cmd); } catch (FuzzyTermsEnum.FuzzyTermsException e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } rb.setResult(result); ResultContext ctx = new BasicResultContext(rb); rsp.addResponse(ctx); rsp.getToLog().add("hits", rb.getResults()==null || rb.getResults().docList==null ? 0 : rb.getResults().docList.matches()); if ( ! rb.req.getParams().getBool(ShardParams.IS_SHARD,false) ) { if (null != rb.getNextCursorMark()) { rb.rsp.add(CursorMarkParams.CURSOR_MARK_NEXT, rb.getNextCursorMark().getSerializedTotem()); } } if(rb.mergeFieldHandler != null) { rb.mergeFieldHandler.handleMergeFields(rb, searcher); } else { doFieldSortValues(rb, searcher); } doPrefetch(rb); }
Example #10
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testWithCursorMark() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellCheckComponent.SPELLCHECK_BUILD, "true"); params.add(SpellCheckComponent.SPELLCHECK_COUNT, "10"); params.add(SpellCheckComponent.SPELLCHECK_COLLATE, "true"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATION_TRIES, "2"); params.add(SpellCheckComponent.SPELLCHECK_MAX_COLLATIONS, "1"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); params.add(CommonParams.SORT, "id asc"); params.add(CursorMarkParams.CURSOR_MARK_PARAM, CursorMarkParams.CURSOR_MARK_START); SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationList = (NamedList) spellCheck.get("collations"); List<?> collations = (List<?>) collationList.getAll("collation"); assertTrue(collations.size() == 1); }
Example #11
Source File: DelegatingCursor.java From dubbox with Apache License 2.0 | 4 votes |
protected DelegatingCursor(SolrQuery query) { this(query, CursorMarkParams.CURSOR_MARK_START); }
Example #12
Source File: QueryResponse.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings({"rawtypes"}) public void setResponse( NamedList<Object> res ) { super.setResponse( res ); // Look for known things for( int i=0; i<res.size(); i++ ) { String n = res.getName( i ); if( "responseHeader".equals( n ) ) { _header = (NamedList<Object>) res.getVal( i ); } else if( "response".equals( n ) ) { _results = (SolrDocumentList) res.getVal( i ); } else if( "sort_values".equals( n ) ) { _sortvalues = (NamedList<ArrayList>) res.getVal( i ); } else if( "facet_counts".equals( n ) ) { _facetInfo = (NamedList<Object>) res.getVal( i ); // extractFacetInfo inspects _results, so defer calling it // in case it hasn't been populated yet. } else if( "debug".equals( n ) ) { _debugInfo = (NamedList<Object>) res.getVal( i ); extractDebugInfo( _debugInfo ); } else if( "grouped".equals( n ) ) { _groupedInfo = (NamedList<Object>) res.getVal( i ); extractGroupedInfo( _groupedInfo ); } else if("expanded".equals(n)) { NamedList map = (NamedList) res.getVal(i); _expandedResults = map.asMap(1); } else if( "highlighting".equals( n ) ) { _highlightingInfo = (NamedList<Object>) res.getVal( i ); extractHighlightingInfo( _highlightingInfo ); } else if ( "spellcheck".equals( n ) ) { _spellInfo = (NamedList<Object>) res.getVal( i ); extractSpellCheckInfo( _spellInfo ); } else if ("clusters".equals(n)) { _clusterInfo = (ArrayList<NamedList<Object>>) res.getVal(i); extractClusteringInfo(_clusterInfo); } else if ("facets".equals(n)) { _jsonFacetingInfo = (NamedList<Object>) res.getVal(i); // Don't call extractJsonFacetingInfo(_jsonFacetingInfo) here in an effort to do it lazily } else if ( "suggest".equals( n ) ) { _suggestInfo = (Map<String,NamedList<Object>>) res.getVal( i ); extractSuggesterInfo(_suggestInfo); } else if ( "stats".equals( n ) ) { _statsInfo = (NamedList<Object>) res.getVal( i ); extractStatsInfo( _statsInfo ); } else if ( "terms".equals( n ) ) { _termsInfo = (NamedList<NamedList<Object>>) res.getVal( i ); extractTermsInfo( _termsInfo ); } else if ( "moreLikeThis".equals( n ) ) { _moreLikeThisInfo = (NamedList<SolrDocumentList>) res.getVal( i ); } else if ( CursorMarkParams.CURSOR_MARK_NEXT.equals( n ) ) { _cursorMarkNext = (String) res.getVal( i ); } } if(_facetInfo != null) extractFacetInfo( _facetInfo ); }
Example #13
Source File: SolrMetaAlertSearchDao.java From metron with Apache License 2.0 | 4 votes |
@Override public SearchResponse getAllMetaAlertsForAlert(String guid) throws InvalidSearchException { if (guid == null || guid.trim().isEmpty()) { throw new InvalidSearchException("Guid cannot be empty"); } // Searches for all alerts containing the meta alert guid in it's "metalerts" array // The query has to match the parentFilter to avoid errors. Guid must also be explicitly // included. String activeClause = MetaAlertConstants.STATUS_FIELD + ":" + MetaAlertStatus.ACTIVE.getStatusString(); String guidClause = Constants.GUID + ":" + guid; String fullClause = "{!parent which=" + activeClause + "}" + guidClause; String metaalertTypeClause = config.getSourceTypeField() + ":" + MetaAlertConstants.METAALERT_TYPE; SolrQuery solrQuery = new SolrQuery() .setQuery(fullClause) .setFields("*", "[child parentFilter=" + metaalertTypeClause + " limit=999]") .addSort(Constants.GUID, SolrQuery.ORDER.asc); // Just do basic sorting to track where we are // Use Solr's Cursors to handle the paging, rather than doing it manually. List<SearchResult> allResults = new ArrayList<>(); try { String cursorMark = CursorMarkParams.CURSOR_MARK_START; boolean done = false; while (!done) { solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark); QueryResponse rsp = solrClient.query(METAALERTS_COLLECTION, solrQuery); String nextCursorMark = rsp.getNextCursorMark(); rsp.getResults().stream() .map(solrDocument -> SolrUtilities.getSearchResult(solrDocument, null, solrSearchDao.getAccessConfig().getIndexSupplier())) .forEachOrdered(allResults::add); if (cursorMark.equals(nextCursorMark)) { done = true; } cursorMark = nextCursorMark; } } catch (IOException | SolrServerException e) { throw new InvalidSearchException("Unable to complete search", e); } SearchResponse searchResponse = new SearchResponse(); searchResponse.setResults(allResults); searchResponse.setTotal(allResults.size()); return searchResponse; }