Indexing documents API

From OpenSearchServer Wiki
Jump to: navigation, search

Contents

Description

API Update is the interface to insert/update documents into an index of the OSS search engine.

Posting a text file

One easy way to populate data is to upload an XML file using a post or a put http request.

Then you have to post the file using a post or a put http request. In our example we use curl:

curl -o log.out -H "Content-type: text/xml; charset=utf-8" -T documents.xml "http://localhost:8080/update?use=indexName"

The XML format is described here XML Indexing Format

Using PHP

The request is done using the PHP5 method OSS_API::update (see the examples below). This class can be downloaded along with OSS source code, and found here: OSS_API.class.php.

If you have a valid XML Index document you can send it using the OSS_API directly.

Example

	$server = new OSS_API('http://localhost:8080', 'indexName');
	$server->update($xmlIndex);

If you need to create one, you can use the OSS_IndexDocument found here OSS_IndexDocument.class.php.

Example

The following creates an instance of the OSS_IndexDocument class. This object can carry one or more documents to index.

	$index = new OSS_IndexDocument();

The following adds a document:

	$document = $index->newDocument('en');

The following adds a field within the document:

	$document->newField('id', '1234');
	$document->newField('title', 'Open Search Server');
	$document->newField('content', 'Open Source Search Engine');
	$document->newField('meta', 'Open Source');
	$document->newField('meta', 'Search Engine'); // Multi value field

The following inserts the document(s) within the index.

	$server = new OSS_API('http://localhost:8080', 'indexName');
	$server->update($index);
Personal tools
Get OSS Open Search Server at SourceForge.net. Fast, secure and Free Open Source software downloads