001/* 002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Antoine Taillefer <ataillefer@nuxeo.com> 018 */ 019package org.nuxeo.elasticsearch.api; 020 021import org.elasticsearch.action.search.SearchResponse; 022import org.nuxeo.ecm.core.api.DocumentModelList; 023import org.nuxeo.ecm.core.api.IterableQueryResult; 024import org.nuxeo.elasticsearch.query.NxQueryBuilder; 025 026/** 027 * Wrapper for the results of a scrollable search request. 028 * 029 * @see ElasticSearchService#scroll(NxQueryBuilder, long) 030 * @see ElasticSearchService#scroll(EsScrollResult) 031 * @since 8.3 032 */ 033public class EsScrollResult extends EsResult { 034 035 /** 036 * {@link NxQueryBuilder} used for the initial search request. 037 */ 038 protected final NxQueryBuilder queryBuilder; 039 040 /** 041 * Scroll id returned by the search request. 042 */ 043 protected final String scrollId; 044 045 /** 046 * Timeout for keeping the search context alive. 047 */ 048 protected final long keepAlive; 049 050 public EsScrollResult(DocumentModelList documents, SearchResponse response, NxQueryBuilder queryBuilder, 051 String scrollId, long keepAlive) { 052 super(documents, null, response); 053 this.queryBuilder = queryBuilder; 054 this.scrollId = scrollId; 055 this.keepAlive = keepAlive; 056 } 057 058 public EsScrollResult(IterableQueryResult rows, SearchResponse response, NxQueryBuilder queryBuilder, 059 String scrollId, long keepAlive) { 060 super(rows, null, response); 061 this.queryBuilder = queryBuilder; 062 this.scrollId = scrollId; 063 this.keepAlive = keepAlive; 064 } 065 066 public EsScrollResult(SearchResponse response, NxQueryBuilder queryBuilder, String scrollId, long keepAlive) { 067 super(response); 068 this.queryBuilder = queryBuilder; 069 this.scrollId = scrollId; 070 this.keepAlive = keepAlive; 071 } 072 073 public EsScrollResult(NxQueryBuilder queryBuilder, String scrollId, long keepAlive) { 074 this(null, queryBuilder, scrollId, keepAlive); 075 } 076 077 public NxQueryBuilder getQueryBuilder() { 078 return queryBuilder; 079 } 080 081 public String getScrollId() { 082 return scrollId; 083 } 084 085 public long getKeepAlive() { 086 return keepAlive; 087 } 088 089}