Last updated: 2024-06-07
Search Operation
In this topic:
Overview
The search operation makes use of numerous attributes and conditions to locate objects in the SmartOffice database.
The example request below shows a typical search operation. It finds all contacts that have a last name beginning with "Ack"; returns the ID, last name and first name of each contact; sorts the results by first name; returns 20 "pages" of results at a time; and stops returning results after 20 "pages."
For explanations of the various elements and attributes, continue to the next section.
<request version="1.0">
<header>...</header>
<search maxpages="200" pagesize="20">
<object>
<Contact>
<LastName/>
<FirstName/>
</Contact>
</object>
<condition>
<expr prop="LastName" op="starts">
<v>Ack</v>
</expr>
</condition>
<sort>
<item prop="FirstName" order="asc"/>
</sort>
</search>
</request>The response includes the requested object information:
<response version="1.0">
<header>...</header>
<search pagesize="20" page="0" total="1" more="false">
<Contact id="Contact.123.456">
<LastName>Ackerman</LastName>
<FirstName>Joe</FirstName>
</Contact>
</search>
</response>Note the search element attributes in the response. These provide information about the current page of results, the total number or records returned in the search, and whether there are more pages. See Pagination for more details.
Search Attributes
The following table describes the attributes that can be used in the search element.
| Attribute | Description |
|---|---|
searchid | Search id, read-only. Specifies the unique ID of the search. The searchid is necessary when the search results are on multiple pages (see Pagination for more details). |
pagesize | Number of objects each page, read/write. The default page size is 2000. |
maxpages | The maximum number of pages the search should return. |
page | Current page, read/write. If the results are greater than the pagesize, this attribute lists the current page number to note where you are. |
total | Number of records retrieved in the response, read-only. |
more | Specifies whether there are more records to be retrieved from the search, read-only. See Pagination for more details. |
Object Element
The object element of a search operation is a template object element that specifies the main object and properties that should be returned in the response. If no properties are specified in the object element, SmartIntegrator returns the default properties.
Condition Element
The condition element of a search operation, which is required, specifies the conditions of the query, which are defined using one or more expr elements.
For more information, see Conditions.
Sort Element
See Sort.
Pagination
When you need to retrieve a large amount of data in a search operation, SmartIntegrator provides the ability to produce paginated data .
Using the search ID generated after the first search, a client application can retrieve a selected element's searchid attribute from the response XML and specify that searchid and the desired page number in a subsequent request to retrieve another page of results.
Not specifying a page number or leaving it blank defaults to retrieving the next page. Clients will not know the total number of records until the last page is retrieved, in which case the more attribute of the search element in the response will be false).
Use of pagination is highly recommended for better performance and efficient data retrieval.
The following example shows a search request with pagination.
Important: The keepsession element with a value of true is required in the header element for pagination to work. WIthout it, you will not receive a searchid value in the response and will not be able to retrieve subsequent pages.
<request version="1.0">
<header>
<office/>
<user/>
<password/>
<keepsession>true</keepsession>
</header>
<search total="true" pagesize="5">
<object>
<Contact>
<LastName/>
<FirstName/>
</Contact>
</object>
<condition>
<expr prop='LastName' op='starts'>
<v>A</v>
</expr>
</condition>
</search>
</request>The response returns five records (due to the pagesize attribute in the request) and provides the search ID for retrieving more pages:
<response version="1.0">
<header/>
<search total="6" searchid="MQ==" more="true" pagesize="5" office="MYSO" page="0" user="Test">
<Contact_type="obj" id="Contact.90807498.174">
<LastName>Aetna Senior Supplement</LastName>
</Contact>
<Contact_type="obj" id="Contact.90807498.163320593">
<LastName>American Funds</LastName>
</Contact>
<Contact_type="obj" id="Contact.90807498.163321105">
<LastName>A</LastName>
</Contact>
<Contact_type="obj" id="Contact.90807498.163321733">
<LastName>Advantage Elite Select 30</LastName>
</Contact>
<Contact_type="obj" id="Contact.90807498.163321884">
<LastName>AdamsBridge</LastName>
</Contact>
</search>
</response>The follow-up request includes the search ID.
<request version="1.0">
<header>
<office/>
<user/>
<password/>
<keepsession>true</keepsession>
</header>
<search total="true" pagesize="5" searchid="MQ==">
<object>
<Contact>
<LastName/>
<FirstName/>
</Contact>
</object>
<condition>
<expr prop='LastName' op='starts'>
<v>A</v>
</expr>
</condition>
</search>
</request>Because the request does not include the page attribute, SmartIntegrator returns the next page by default:
<response version="1.0">
<header/>
<search total="6" searchid="MQ==" more="false" pagesize="5" office="MYSO" page="-1" user="Test">
<Contact _type="obj" id="Contact.90807498.163321887">
<LastName>Appollo Hospital</LastName>
</Contact>
</search>
</response>