|
| 1 | +/* |
| 2 | + * Copyright 2012-2015 MarkLogic Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.marklogic.client.query; |
| 17 | + |
| 18 | +import com.marklogic.client.io.Format; |
| 19 | + |
| 20 | +/** Surfaces the data sent from the server-side XQuery search:search API. Note |
| 21 | + * that the most important function is to provide access to the list of ExtractedItem |
| 22 | + * objects. For example: |
| 23 | + * <pre> String combinedSearch = |
| 24 | + * "<search:search xmlns:search=\"http://marklogic.com/appservices/search\">" + |
| 25 | + * "<search:qtext>my search terms</search:qtext>" + |
| 26 | + * "<search:options>" + |
| 27 | + * "<search:extract-document-data>" + |
| 28 | + * "<search:extract-path>/some/path</search:extract-path>" + |
| 29 | + * "<search:extract-path>/another/path/*</search:extract-path>" + |
| 30 | + * "</search:extract-document-data>" + |
| 31 | + * "</search:options>" + |
| 32 | + * "</search:search>"; |
| 33 | + * StringHandle queryHandle = new StringHandle(combinedSearch).withMimetype("application/xml"); |
| 34 | + * QueryDefinition query = queryMgr.newRawCombinedQueryDefinition(queryHandle); |
| 35 | + * SearchHandle results = queryMgr.search(query, new SearchHandle()); |
| 36 | + * MatchDocumentSummary[] summaries = results.getMatchResults(); |
| 37 | + * for (MatchDocumentSummary summary : summaries) { |
| 38 | + * ExtractedResult extracted = summary.getExtracted(); |
| 39 | + * if ( Format.XML == summary.getFormat() ) { |
| 40 | + * for (ExtractedItem item : extracted) { |
| 41 | + * Document extractItem = extracted.next().getAs(Document.class); |
| 42 | + * ... |
| 43 | + * } |
| 44 | + * } |
| 45 | + * }</pre> |
| 46 | + * |
| 47 | + * Where you can, of course, use any appropriate StructureReadHandle or corresponding |
| 48 | + * class (provided by that handle's receiveAs() method) passed to the |
| 49 | + * {@link ExtractedItem#getAs} method. |
| 50 | + **/ |
| 51 | +public interface ExtractedResult extends Iterable<ExtractedItem> { |
| 52 | + |
| 53 | + /** The format of the extracted data. Not always available, returns null if |
| 54 | + * unavailable. **/ |
| 55 | + public Format getFormat(); |
| 56 | + |
| 57 | + /** The xquery to retrieve the parent document. Not always available, returns |
| 58 | + * null if unavailable. **/ |
| 59 | + public String getContext(); |
| 60 | + |
| 61 | + /** The xquery type of the extracted data. For XML it will be "element". For |
| 62 | + * JSON it will be "object" or "array". Not always available, returns null if |
| 63 | + * unavailable. **/ |
| 64 | + public String getKind(); |
| 65 | + |
| 66 | + /** Returns true if the underlying node is an "extracted-none" XML element or |
| 67 | + * JSON property. */ |
| 68 | + public boolean isEmpty(); |
| 69 | + |
| 70 | + /** The number of ExtractedItem objects in the Iterator. */ |
| 71 | + public int size(); |
| 72 | + |
| 73 | + /** Returns the next element in the internal iterator, which is separate |
| 74 | + * from any new iterator created by calls to iterator(). |
| 75 | + * @return the next element in the iteration |
| 76 | + */ |
| 77 | + public ExtractedItem next(); |
| 78 | + |
| 79 | + /** Returns true if internal iterator has more elements. |
| 80 | + * The internal iterator is separate from any new iterator created by calls to iterator(). |
| 81 | + * @return true if the internal iterator has more elements |
| 82 | + */ |
| 83 | + public boolean hasNext(); |
| 84 | +} |
0 commit comments