Searching and Retrieving Results Using XML Search
Example: To add search results to a website using XML search:
-
Add an XML Search page to your site.
-
Perform a search using the Coveo XML Search page.
-
Parse the XML to display results.
You can obtain XML search results using the XMLsearch.aspx in the search URL of the form:
http://[CoveoServer]/XMLSearch.aspx?[Query]
Using the following URL from this Coveo server:
https://localhost/XMLsearch.aspx?BasicQuery=united oil financial statements year ended 2003 @sysspversion
returns the same 4 results, but in the following XML format:
<QueryResults xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Executed>true</Executed>
<BasicQuery>
united oil financial statements year ended 2003 @sysspversion
</BasicQuery>
<AdvancedQuery/>
<ExpandedQuery/>
<TotalCount>4</TotalCount>
<Time>0.047</Time>
<Filtered>false</Filtered>
<Optimized>false</Optimized>
<Results>
<QueryResult>...</QueryResult>
<QueryResult>
<UniqueId>172622!-1!</UniqueId>
<Title>Financial funding United Oil Draft</Title>
<Uri>
https://sp2010.demo.coveo.com/Finance/Shared Documents/Funding Reports/Financial funding United oil Sharepoint.docx
</Uri>
<PrintableUri>
https://sp2010.demo.coveo.com/Finance/Shared Documents/Funding Reports/Financial funding United oil Sharepoint.docx
</PrintableUri>
<TargetUri>
https://sp2010.demo.coveo.com/Finance/Shared Documents/Funding Reports/Financial funding United oil Sharepoint.docx
</TargetUri>
<Score>2710</Score>
<PercentageScore>52.927528381347656</PercentageScore>
<Size>293386</Size>
<IsAttachment>false</IsAttachment>
<ContainsAttachment>true</ContainsAttachment>
<ModifiedDate>2010-09-21T18:39:25</ModifiedDate>
<IndexedDate>2011-03-01T16:21:36</IndexedDate>
<IsTopResult>false</IsTopResult>
<Rating>3</Rating>
<IsUserRating>false</IsUserRating>
<LastView>0001-01-01T00:00:00</LastView>
<NumberOfViews>0</NumberOfViews>
</QueryResult>
<QueryResult>...</QueryResult>
<QueryResult>...</QueryResult>
</Results>
<ExceptionCode>1</ExceptionCode>
<ExceptionContext/>
</QueryResults>
Note: The XML search results output does not feature all the controls of the default search interface. For example, the facets are not included.
Available Parameters
In the query, you can use the parameters described in the following table.
Name | Type | Description | Possible Values |
---|---|---|---|
AdvancedQuery | String | Advanced query expression. | (according to search syntax) |
AllRemoteServers | Boolean | Set to true to include all remote servers in the query. | [true, false] |
BasicQuery | String | Basic query expression. | (according to search syntax) |
CollectionIds | Comma separated string | IDs of the collections in which the query should be performed. | If no collections are specified, then they are all selected. |
CollectionNames | Comma separated string | Names of the collections in which the query should be performed. | Available collections.
If collections specified do not exist, they are dismissed. |
DefaultTimeOut | Integer | The timeout delay to use when querying remote servers (in milliseconds). Used only when AllRemoteServers is true. | [0…] |
DoNotLog | Boolean | Set to true to disable query logging. | [true, false] |
ExcerptLength | Integer | Length of the excerpt to retrieve for each result (in characters). Set this property to a non-zero value to retrieve an excerpt. | [0…] |
ExpandQuery | Boolean | Set to true to enable query expansion using the thesaurus. | [true, false] |
FilterByField | String | The custom field to use for filtering custom duplicates. | Any available field, prefixed by @ |
FilterDuplicates | Boolean | Set to true to enable duplicate document filtering. | [true, false] |
FirstResult | Integer | 0-based index of the first result to retrieve. | [0…49999] |
ImpersonatorChain | Comma separated string | Authentication information (chain of users to impersonate) for the execution of the query. | |
NeedCachedDocumentUris | Boolean | Set to true to retrieve the URIs that serve cached versions of the results. | [true, false] |
NeedConcepts | Boolean | Set to true to retrieve the concepts for each result. | [true, false] |
NeededFields | Comma separated string | List of fields whose value should be retrieved. | Any available field, prefixed by @ |
NeedHighlights | Boolean | Set to True to retrieve the highlights for the title, excerpt, etc. | [true, false] |
NeedParsedQuery | Boolean | Set to true to retrieve the parsed query information. When performing a query, the parsed information is available in QueryResults.ParsedQuery. | [true, false] |
NeedQueryCorrections | Boolean | Set to true to retrieve the potential query corrections. | [true, false] |
NumberOfResults | Integer | maximum number of results to retrieve. | [1…50000] |
Optimize | Boolean | Set to true to enable exact string query optimizations. | [true, false] |
PreferredLanguage | String | Optional name of the preferred language for results. | [english,french] |
SavedQueryOrFilter | String | The serialized saved query or filter to include in the search. | |
SortByField | String | Optional name of the field to use for sorting results. | (according to fields configured as sortable)
Used only if SortCriteria is in [FieldAscending, FieldDescending] |
SortCriteria | String | Sort criteria to use for sorting results.
Note: in versions prior to 1413.1808 this parameter was named SortBy. |
[Relevancy, ModifiedDateAscending, ModifiedDateDescending, FieldAscending, FieldDescending] |
SummaryLength | Integer | Length of the summary to retrieve for each result (in words). Set this property to a non-zero value to retrieve a summary. | [0…] |
TimeZoneOffset | Integer | End user's offset from local time to UTC, in minutes. | [-720…720] |
UseCollaborativeRanking | Boolean | Set to true to enable collaborative ranking for this query. | [true, false] |
UseWildcards | Boolean | Set to true to enable wildcards for this query. | [true, false] |
Example: A more complex query combining several parameters: http://localhost/XMLSearch.aspx?BasicQuery=@uri&collectionnames=portal,test&NumberOfResults=4&SortBy=ModifiedDateDescending
&ExcerptLength=200&SummaryLength=60&NeedConcepts=true
Output XML Schema
<QueryResults xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Executed></Executed>
<BasicQuery></BasicQuery>
<AdvancedQuery></AdvancedQuery>
<ExpandedQuery></ExpandedQuery>
<TotalCount></TotalCount>
<Time></Time>
<Filtered></Filtered>
<Optimized></Optimized>
<QueryCorrections>
<QueryCorrection>
<CorrectedQuery></CorrectedQuery>
<WordCorrections>
<WordCorrection>
<Position></Position>
<OriginalWord></OriginalWord>
<CorrectedWord></CorrectedWord>
</WordCorrection>
</WordCorrections>
</QueryCorrection>
</QueryCorrections>
<Results>
<QueryResult>
<UniqueId></UniqueId>
<Title></Title>
<TitleHighlights>
<Highlight>
<Position></Position>
<Length></Length>
</Highlight>
</TitleHighlights>
<Uri></Uri>
<PrintableUri></PrintableUri>
<PrintableUriHighlights>
<Highlight>
<Position></Position>
<Length></Length>
</Highlight>
</PrintableUriHighlights>
<Score></Score>
<Size></Size>
<IsAttachment></IsAttachment>
<ContainsAttachment></ContainsAttachment>
<ModifiedDate></ModifiedDate>
<IndexedDate></IndexedDate>
<Fields>
<ResultField>
<Name></Name>
<Value xsi:type=""> </Value>
</ResultField>
</Fields>
<IsTopResult></IsTopResult>
<Rating></Rating>
<IsUserRating></IsUserRating>
<LastView></LastView>
<NumberOfViews></NumberOfViews>
<Excerpt></Excerpt>
<ExcerptHighlights>
<Highlight>
<Position></Position>
<Length></Length>
</Highlight>
</ExcerptHighlights>
<Summary></Summary>
<Concepts>
<string></string>
</Concepts>
<CachedDocumentUri></CachedDocumentUri>
</QueryResult>
</Results>
</QueryResults>
Element | Data type | Description |
---|---|---|
QueryResults | N/A | Root element. |
Executed | Boolean | True if enough information to perform a search. |
BasicQuery | String | Received BasicQuery parameter content. |
AdvancedQuery | String | Received AdvancedQuery parameter content. |
ExpandedQuery | String | Thesaurus suggested query. |
TotalCount | Integer | Total number of matching documents. |
Time | float | Time required to return results, in seconds. |
Filtered | Boolean | True if duplicate results are filtered. Controlled by the FilterDuplicates parameter. |
Optimized | Boolean | True if query is optimized. Controlled by the Optimize parameter. |
QueryCorrections | N/A | Collection of QueryCorrection elements. Represents the Did You Mean function. |
QueryCorrection | N/A | Contains CorrectedQuery and WordCorrections elements. |
CorrectedQuery | String | Corrected query as if all WordCorrections are applied to BasicQuery. |
WordCorrections | N/A | Collection of WordCorrection elements. |
WordCorrection | N/A | Contains Position, OrignalWord and CorrectedWord elements. |
Position | Integer | Position of OriginalWord in BasicQuery. |
OriginalWord | String | Word that might require a correction. |
CorrectedWord | String | Suggested OriginalWord replacement. |
Results | N/A | Collection of QueryResult elements. |
QueryResult | N/A | Contains UniqueId, Title, TitleHighlights, Uri, PrintableUri, Score, Size, IsAttachment, ContainsAttachment, ModifiedDate, IndexedDate, Fields, IsTopResult, Rating, IsUserRating, LastView, NumberOfViews, Excerpt, and ExcerptHighlights elements. |
UniqueId | Integer | Internal unique document identifier. |
Title | String | Title of the document. |
TitleHighlights | N/A | Collection of Highlight elements. |
Highlight | N/A | Contains Position and Length elements. |
Position | Integer | Position of the expression to highlight in Title. |
Length | Integer | Length of the expression to highlight in Title. |
Uri | String | Address of the document. |
PrintableUri | String | Address that should be displayed to user. |
PrintableUriHighlights | N/A | Collection of Highlight elements. |
Highlight | N/A | Contains Position and Length elements. |
Position | Integer | Position of the expression to highlight in PrintableUri. |
Length | Integer | Length of the expression to highlight in PrintableUri. |
Score | Integer | Relative to the quality of the document in regards of the query. |
Size | Integer | File size in bytes. |
IsAttachment | Boolean | True if the file is contained in another file such as a zipped one. |
ContainsAttachment | Boolean | True if contains other files such as a zip. |
ModifiedDate | date/time | Last time the document was modified. |
IndexedDate | date/time | Last time the document was refreshed in the index. |
Fields | N/A | Collection of ResultField elements. |
ResultField | N/A | Contains Name and Value elements. |
Name | String | Name of a field. |
Value | (description) | Value of the field. This element has an attribute xsi:type that denotes the data type of the value. |
IsTopResult | Boolean | True if the document is displayed as a Top Results. |
Rating | float | Document rating in number of stars. |
IsUserRating | Boolean | True if the Rating element denotes that the rating was manually set by the user. |
LastView | date/time | Time when the document was last opened. |
NumberOfViews | Integer | Number of times a document was opened. |
Excerpt | String | Most relevant document excerpt. |
ExcerptHighlights | N/A | Collection of Highlight elements. |
Highlight | N/A | Contains Position and Length elements. |
Position | Integer | Position of the expression to highlight in Excerpt. |
Length | Integer | Length of the expression to highlight in Excerpt. |
Summary | String | Document summary. |
Concepts | N/A | Collection of string elements. |
String | String | One of the most important document words or expressions. |
CachedDocumentUri | String | Address where users can see the document Quick View. |