<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://api.textwise.com"
	xmlns:tns="http://api.textwise.com" 
	elementFormDefault="qualified">

	<xs:attributeGroup name="processAttributes">
		<!--
			The 'processingTime' string is in the format of 'NNNNms' where
			NNNN is an integer representing the number of milliseconds the
			live or batch update took to process.
		-->
		<xs:attribute name="processingTime" type="xs:string"/>
		<xs:attribute name="totalItems" type="xs:string" use="required"/>
		<xs:attribute name="adds" type="xs:integer"/>
		<xs:attribute name="updates" type="xs:integer"/>
		<xs:attribute name="deletes" type="xs:integer"/>
		<xs:attribute name="failed" type="xs:integer"/>

		<xs:attribute name="batchId" type="xs:integer"/>
		<!--
			CREATED - The load has been created but is not ready yet to be loaded
			QUEUED - All feeds have been created and the load is ready for loading
			PROCESSING - The feeds for the load are currently being processed
			FAILED - There was a failure during the loading process
			COMPLETED - load done, failures will be available.
			ABORTED - The loading process was interrupted
		-->
		<xs:attribute name="state" type="xs:string"/>
		<!-- For batch process status -->
		<!--
			queuePosition -  the position of this Batch process in the processing queue.
		-->
		<!-- Not supported for now -->
		<!-- <xs:attribute name="queuePosition" type="xs:integer"/> -->
	</xs:attributeGroup>

	<xs:attributeGroup name="statusAttributes">
		<xs:attribute name="indexId" type="xs:string"/>
		<xs:attribute name="dictionaryId" type="xs:string"/>
		<xs:attribute name="dateCreated" type="xs:dateTime"/>
		<xs:attribute name="currentSize" type="xs:integer"/>
		<xs:attribute name="capacity" type="xs:integer"/>
		<xs:attribute name="lastModificationDate" type="xs:dateTime"/>
		<xs:attribute name="modificationInProcess" type="xs:boolean"/>
		<!-- Not currently possible to get -->
		<!--<xs:attribute name="queriesPerSecond" type="xs:integer"/>-->
	</xs:attributeGroup>

	<xs:element name="response">
		<xs:complexType>
			<xs:sequence>

				<!--
					<about>
					<requestId>B53DDF481D28E824B8816B4BE2128FA8</requestId>
					<systemType>index</systemType>
					<externalId>1236691446064</externalId>
					<requestDate>2009-03-10T19:01:44+0000</requestDate>
					<systemVersion>2.0</systemVersion>
					</about>
				-->
				<xs:element name="about" minOccurs="1" maxOccurs="1">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="requestId" type="xs:string" maxOccurs="1"/>
							<xs:element name="systemType" type="xs:string" maxOccurs="1"/>
							<xs:element name="externalId" type="xs:string" minOccurs="0" maxOccurs="1"/>
							<xs:element name="requestDate" type="xs:dateTime" maxOccurs="1"/>
							<xs:element name="systemVersion" type="xs:string" maxOccurs="1"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>


				<!--
					<contentIndex>
				-->

				<xs:element name="contentIndex" minOccurs="0" maxOccurs="1">
					<xs:complexType>
						<xs:sequence>

							<xs:element name="contentIndexResponse" minOccurs="0" maxOccurs="1">
								<xs:complexType>
									<xs:sequence>

										<!-- The result of the 'item' call
											<contentIndexResponse externalId="foo">
											<contentId>theContentId</contentId>
											<externalId>theExternalId</externalId>
											<signature>
											<dimension weight="0.6535" index="42"/>
											<dimension weight="0.5634" index="4242"/>
											...
											</signature>
											<attribute name="title">Title</attribute>
											<attribute name="content" >content</attribute>
											<attribute name="URI" >Title</attribute>
											</contentIndexResponse>
										-->
										<xs:element name="contentId" type="xs:string" minOccurs="0" maxOccurs="1"/>
										<xs:element name="externalId" type="xs:string" minOccurs="0" maxOccurs="1"/>

										<xs:element name="signature" minOccurs="0" maxOccurs="1">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="dimension" minOccurs="0" maxOccurs="unbounded">
														<xs:complexType>
															<xs:attribute name="weight" type="xs:string"/>
															<xs:attribute name="index" type="xs:integer"/>
														</xs:complexType>
													</xs:element>
												</xs:sequence>
											</xs:complexType>
										</xs:element>

										<xs:element name="attributes" minOccurs="0" maxOccurs="1">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="attribute" minOccurs="0" maxOccurs="unbounded">
														<xs:complexType>
															<xs:simpleContent>
																<xs:extension base="xs:string">
																	<xs:attribute name="name" type="xs:string"/>
																</xs:extension>
															</xs:simpleContent>
														</xs:complexType>
													</xs:element>
												</xs:sequence>
											</xs:complexType>
										</xs:element>

									</xs:sequence>
								</xs:complexType>
							</xs:element>

							<!--
								For the getStatus Call

								<contentIndexStatus indexId="foo"
								dictionaryId="bar"
								dateCreated="1970-01-01Thh:mm:ss+0000"
								currentSize="50000"
								capacity="1000000"
								lastModificationDate="1970-01-01Thh:mm:ss+0000"
								modificationInProcess="true|false"
								queriesPerSecond="2">
								</contentIndexStatus>
							-->
							<xs:element name="contentIndexStatus" minOccurs="0" maxOccurs="1">
								<xs:complexType>
									<xs:attributeGroup ref="tns:statusAttributes"/>
								</xs:complexType>
							</xs:element>

							<!--
								For the index facets call, lists the facets that
								are defined for the index. 
							 -->
							<xs:element name="facets" minOccurs="0" maxOccurs="1">
								<xs:complexType>
									<xs:sequence>
										<xs:element name="facet" minOccurs="1" maxOccurs="unbounded">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="ranges" minOccurs="0" maxOccurs="1">
														<xs:complexType>
															<xs:sequence>
																<xs:element name="range" minOccurs="1" maxOccurs="unbounded">
																	<xs:complexType>
																		<xs:attribute name="start" type="xs:string" />
																		<xs:attribute name="end" type="xs:string" />
																	</xs:complexType>
																</xs:element>
															</xs:sequence>
														</xs:complexType>
													</xs:element>
												</xs:sequence>
												<xs:attribute name="name" type="xs:string" use="required" />
												<xs:attribute name="multivalue" type="xs:boolean" use="required" />
												<xs:attribute name="multivalueDelimiter" type="xs:string" use="required" />
												<xs:attribute name="dateformat" type="xs:string" />
												<xs:attribute name="type" use="required">
													<xs:simpleType>
														<xs:restriction base="xs:string">
															<xs:enumeration value="string"/>
															<xs:enumeration value="short"/>
															<xs:enumeration value="int"/>
															<xs:enumeration value="long"/>
															<xs:enumeration value="float"/>
															<xs:enumeration value="price"/>
															<xs:enumeration value="timestamp"/>
														</xs:restriction>
													</xs:simpleType>
												</xs:attribute>
											</xs:complexType>
										</xs:element>
									</xs:sequence>
								</xs:complexType>
							</xs:element>


							<!--
							<live-process-info totalItems="7" adds="2" updates="1" deletes="2" failed="2">
								<failures>
									<item externalId="1020"> DELETE_DOES_NOT_EXIST</item>
									<item externalId="1021"> ADD_EXISTS</item>
								</failures >
							</live-process-info>
							-->
							<xs:element name="live-process-info" minOccurs="0" maxOccurs="1">
								<xs:complexType>
									<xs:sequence>
										<xs:element name="failures" minOccurs="0" maxOccurs="1">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
														<xs:complexType>
															<xs:simpleContent>
																<xs:extension base="xs:string">
																	<xs:attribute name="externalId" type="xs:string" use="required"/>
																</xs:extension>
															</xs:simpleContent>
														</xs:complexType>
													</xs:element>
												</xs:sequence>
											</xs:complexType>
										</xs:element>
									</xs:sequence>
									<xs:attributeGroup ref="tns:processAttributes"/>
								</xs:complexType>
							</xs:element>


							<!--
								Only if the state is COMPLETED would the failures be printed.
								This is used for the initial response on batch load to provide
								the batchId, and for the status call to check on it.

								<batch-process-info  batchId="3456" state="COMPLETED">
									<failures>
										<item externalId="1020"> DELETE_DOES_NOT_EXIST</item>
										<item externalId="1021"> ADD_EXISTS</item>
									</failures >
								</batch-process-info>
							-->
							<xs:element name="batch-process-info" minOccurs="0" maxOccurs="1">
								<xs:complexType>
									<xs:sequence>
										<xs:element name="failures" minOccurs="0" maxOccurs="1">
											<xs:complexType>
												<xs:sequence>
													<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
														<xs:complexType>
															<xs:simpleContent>
																<xs:extension base="xs:string">
																	<xs:attribute name="externalId" type="xs:string" use="required"/>
																</xs:extension>
															</xs:simpleContent>
														</xs:complexType>
													</xs:element>
												</xs:sequence>
											</xs:complexType>
										</xs:element>
									</xs:sequence>
									<xs:attributeGroup ref="tns:processAttributes"/>
								</xs:complexType>
							</xs:element>


						</xs:sequence>
					</xs:complexType>
				</xs:element>

			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

