Search connectors allow you to easily communicate with your Netaphor search server. The connector deals with authentication and HTTP communication allowing you to perform common search and update tasks using a local object.
Using the search connector you can easliy:
There is a suite of search connectors in the pipeline, the first, available below, is written in PHP.
The PHP connector consists of a single primary class ("NetaphorSearch") used to perform interactions with your search server. Additionally there is a helper class that uses cURL to handle the HTTP communication.
By default all communications are done over HTTPS. Normally you will communicate with:
https://www.netaphorsearch.com/search/
If you have access to one of our development servers then we will have provided you with an alternative URL
| Method name | Returns | Notes |
|---|---|---|
| commit() | XML | Commit your changes to the search index |
| optimize() | XML | Optimize the search index, this should after a large content update and usually only one a day during off-peak hours. |
| commitAndOptimise() | XML | Sequentially performs both the commit and optimize methods |
| search($query, $requestHandler, $anyExtraParams) |
Boolean | Perform a search: $search - Your search query, $requestHandler - the Solr request handler, $anyExtraParams - anything else you want to add to the Solr request string |
| getResponse() | Specified in request | Get the response from the last requestm normally this is XML except for search() where the response will be formatted in the format requested in the query (XMl is the default) |
| update($xmlData) | XML | Post data to your server in XML format. Use commit() aferwards to update the index and make your changes visible |
| delete($recordId) | XML | Delete an item from your index, specify the Id of the document you wish to delete. Use commit() afterwards to makes your changes visible |
| responseError() | Boolean | Returns false if there was a communication error with the server |
| getHttpResponseCode() | String | The HTTP response code of the last communication |
| getQueryString() | String | The full request string sent to the server |
The XML responses are the same as those provided directly by the RESTful API.
Below is a fairly simplistic example of how you might use the search connector
<?php
// Include the connector file
include ("netaphorSearchConnector.php");
// Create a new Netaphor search object
$netaphorSearch = new NetaphorSearch('yourSearchId',
'yourUserName',
'yourPassword',
'https://www.netaphorsearch.com/search/');
// You need some XML data to add to you search.
$postData = file_get_contents('myUpdateData.xml');
// Update your search with your XML
$netaphorSearch->update($postData);
// Commit your changes
$netaphorSearch->commit();
// Perform a search:
// $netaphorSearch->search(searchQuery, solrRequestHandler, extraParamters)
// searchQuery: A string representing your search query or phrase.
// The search connector will encode the query for you.
// solrRequestHandler: A string defining the Solr request handler,
// typically "dismax" or "standard".
// extraParamters: A URL query string with all your additional Solr
// query parameters. Ensure values are url encoded.
$query = 'printer';
// filter the query using a facet, in this case it is the "manufacturer"
// field with a value of "Konica Minolta"
$filterOptions = '&fq=manufacturer:"Konica Minolta"';
// Add some useful facet-related parameters
// Turn on faceting
$filterOptions .= '&facet=true';
// Don't return facet values that are not in the result set
$filterOptions .= '&facet.mincount=1';
// Request 20 results
$filterOptions .= '&rows=20';
// In this example we request the response in php serialised format by
// specifying "&wt=phps" in the extra params.
$filterOptions .= '&wt=phps';
// Call the search method
$netaphorSearch->search($query, 'dismax', $filterOptions);
if($netaphorSearch->responseError()){
// there was a http communication error
echo 'The response code was' . $netaphorSearch->getHttpResponseCode()
. ' the response body was ' . $netaphorSearch.getResponse();
} else {
// turn the String response into data
$searchResponse = unserialize($netaphorSearch->getResponse());
// Display the results to the user
}
?>