Indexing operations

Goal

This section provides information about the implementation of the indexing process. The C# SDK exposes several methods needed for the proper implementation of the indexing. All of these methods are exposed in the HawksearchClient class.

Prerequisite

Installed .NET SDK NuGet package

 

Create Index


The CreateIndex method exposes the functionality to create indexes via the Hawksearch API. You need to provide the field definitions and suffix for the index.

HttpResponseMessage CreateIndex(List<FieldDefinition> fieldDefinitions, string suffix = "")

Parameters

  • List<FieldDefinition> fieldDefinitions

These are the fields that each document will have. They are of type FieldDefinition. Each FieldDefinition has a string Name and string Type.

  • string suffix

This will be attached at the end of the Hawksearch index name

Returns

  • HttpResponseMessage

Returns a message and status code indicating whether the process has failed (404 Bad request) or succeeded (200 OK).

Usage

Call this method when you want to create a new index with your specific fields and suffix.

 

Delete Index


The DeleteIndex method exposes the functionality to delete an index via the Hawksearch API. You must provide the name of the Hawksearch index you want to delete.

HttpResponseMessage DeleteIndex(string indexName)

Parameters

  • string indexName

The name of the Hawksearch index you want to delete

Returns

  • HttpResponseMessage

Returns a message and status code indicating whether the process has failed (404 Bad request) or succeeded (200 OK).

Usage

Call this method when you want to delete a specific Hawksearch index.

 

Remove Document


The RemoveDocument method removes a specific document entry from a Hawksearch index. You need to provide the Id of the document and the name of the Hawksearch index.

HttpResponseMessage RemoveDocument(string indexName, string identityField)

Parameters

  • string indexName

The name of the index from which you want to remove the document

  • string identityField

The Id of the document you want to remove

Returns

  • HttpResponseMessage

Returns a message and status code indicating whether the process has failed (404 Bad request) or succeeded (200 OK).

Usage

Call this method when you want to delete a specific document form a Hawksearch index.

 

Remove Documents


The RemoveDocuments method removes a specific list of documents from a Hawksearch index. You need to provide the Ids of the documents and the name of the Hawksearch index.

Parameters

  • string indexName

The name of the index from which you want to remove the document

  • List<string> documents

The Ids of the documents you want to remove

Returns

  • HttpResponseMessage

Returns a message and status code indicating whether the process has failed (404 Bad request) or succeeded (200 OK).

Usage

Call this method when you want to delete a specific list of documents form a Hawksearch index.

 

Add Documents


The AddDocuments method provides the functionality to add document entries to a specific Hawksearch index. You need to provide the name of Hawksearch index and a list of documents to be added.

Parameters

  • string indexName

The name of the Hawksearch index to which you want to add the documents

  • List<SubmitDocument> documents

A list with all of the documents you want to add. They are of type SubmitDocument.

 

Your documents need to mapped to type SubmitDocument so adapt them accordingly.

Returns

  • List<HttpResponseMessage>

The Hawksearch API sends back a response with a message and status code for each document added to the index. The responses are then gathered in a list which is returned

Usage

Call this method when you want to update an index with new documents.

After the documents have been added to the index you need to rebuild it in order for the changes to be reflected . Please refer to the RebuildAll method.

 

Get Indexes


The GetIndexes method provides you with the functionality to get all of the Hawksearch indexes that you have.

Returns

  • HttpResponseMessage

Returns a response message which contains all of the indexes or an error message.

Usage

Call this method when you need a list of all of the Hawksearch indexes that you have for your client.

 

Get Current Index


The GetCurrentIndex method provides you with the functionality to get the current index in your Hawksearch instance.

Returns

  • HttpResponseMessage

Returns a response message which contains the current index or an error message.

Usage

Call this method when you need to see the index which is marked as Current in your Hawksearch instance.

 

Set Current Index


The SetCurrentIndex method provides you with the functionality to set the current index in your Hawksearch instance.

Parameters

  • string indexName

The name of the index which you want to set as current

Returns

  • HttpResponseMessage

Returns a response message with status code indicating whether the operation was successful or not.

Usage

Call this method when you need to set an index as current.

 

Get Field


The GetField method exposes a functionality to read a particular field from your Hawksearch instance.

Parameters

  • string fieldName

The name of the field you want to get from the Hawksearch API

Returns

  • Field

The Hawksearch API returns a HttpResponseMessage which is then mapped to a Field.

Usage

Call this method when you want to read a particular Field from your Hawksearch instance.

 

Get Fields


The GetFields method exposes a functionality to read all fields from your Hawksearch instance.

Returns

  • IEnumerable<Field>

The Hawksearch API returns a HttpResponseMessage which is then mapped to an IEnumerable<Field>.

Usage

Call this method when you want to read all of the Fields from your Hawksearch instance.

 

Create Fields


The CreateFields method exposes a functionality to create new fields in your Hawksearch instance.

Parameters

  • List<FieldDefinition> fieldDefinitions

These are the fields that will be created in your Hawksearch instance. They need to be of type FieldDefinition. Each FieldDefinition has string Name and string Type

Returns

  • List<HttpResponseMessage>

Returns a list of response messages which contain information whether the creation of each field was successful or not.

Usage

This method is called when new fields need to be added to your Hawksearch instance.

This method is invoked internally in CreateIndex(List<FieldDefiniton> fieldDefinitions) so you don’t have to invoke it explicitly when creating an index.

 

Upsert Hierarchies


The UpsertHierarchies method provides the functionality to insert or update hierarchies to a specific Hawksearch index. You need to provide the name of Hawksearch index and a list of hierarchies to be added.

Parameters

  • string indexName

The name of the Hawksearch index to which you want to add the documents

  • List<Hierarchy> hierarchies

A list with all of the hierarchies you want to add. They are of type Hierarchy.

Your hierarchies need to mapped to type Hierarchy so adapt them accordingly.

Returns

  • List<HttpResponseMessage>

The Hawksearch API sends back a response with a message and status code for each document added to the index. The responses are then gathered in a list which is returned

Usage

Call this method when you want to update an index with new hierarchies or update existing ones.

 

Get Hierarchies


The GetHierarchies method provides you with the functionality to get all hierarchies for a given index.

 

 

Returns

  • IEnumerable<HierarchyMapping>

The Hawksearch API returns a HttpResponseMessage which is then mapped to an IEnumerable<HierarchyMapping>.

Usage

Call this method when you want to get all hierarchies from an index.

 

Delete Hierarchies By Ids


The DeleteHierarchiesByIds method provides you with the functionality to delete hierarchies from a given index by providing their ids.

Returns

  • HttpResponseMessage

Returns a response message with status code indicating whether the operation was successful or not.

Usage

Call this method when you want to delete given hierarchies from an index.

 

Delete Hierarchies


The DeleteHierarchies method provides you with the functionality to delete all hierarchies from a given index.

Returns

  • HttpResponseMessage

Returns a response message with status code indicating whether the operation was successful or not.

Usage

Call this method when you want to delete given hierarchies from an index.

 

Rebuild Hierarchies


The RebuildHierarchies method provides you with the functionality to rebuild the hierarchies for a given index.

Returns

  • HttpResponseMessage

Returns a response message with status code indicating whether the operation was successful or not.

Usage

Call this method when you want to rebuild the hierarchies for an index in cases where there are updates.

 

Rebuild Index


The RebuildIndex method is used in the Lucene version of the connector and is usually called after an Export has finished.

Returns

  • HttpResponseMessage

Returns a response message indicating whether the rebuild has been successful or not

Usage

Call this method after you have exported the files in order to trigger a reindex in the Hawksearch API.

 

Rebuild All


The RebuildAll method is usually called after the AddDocuments method in order the reflect the changes made in the index.

Parameters

  • string name

The name of the Hawksearch index that will be rebuild

Returns

  • HttpResponseMessage

Returns a response message which indicates whether the rebuild was successful or not.

Usage

Call this method after AddDocuments(string indexName, List<SubmitDocument> documents) in order to reflect the new documents which were added by triggering a reindex.