SemanticSearchImplementation
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SemanticSearchImplementation.ElasticsearchSearchClient Class Reference

Implements necessary functions to use Elasticsearch as a search engine. More...

Inheritance diagram for SemanticSearchImplementation.ElasticsearchSearchClient:
SemanticSearchImplementation.ISearchClient

Public Member Functions

 ElasticsearchSearchClient (string server="localhost", string port="9200")
 
void ChangeIndex (string index)
 Updates the current index. More...
 
async Task< IDictionary< string, string > > GetMappingAsync ()
 Queries the mappings of the current index. More...
 
async Task CreateIndexAsync (JObject content, string index)
 Creates an index with the given settings and mappings. More...
 
async Task AddDocumentsAsync (IEnumerable< JObject > documents)
 Adds the given documents as a bulk upload. More...
 
async Task SwitchAliasAsync (string from, string to)
 Changes the alias from the old to the new index. More...
 
async Task DeleteIndexAsync (string index)
 Deletes the given index. More...
 
async Task AddDocumentAsync (string graphName, IDictionary< string, JObject > documents)
 Adds/updates a new document and possibly changes existing documents. More...
 
async Task DeleteDocumentAsync (string graphName, IDictionary< string, JObject > documents)
 Deletes a document and possibly changes other existing documents. More...
 
async Task< IDictionary< string, double > > SearchAsync (string query, IEnumerable< string > projects, bool advanced, int size, int from, string sorting)
 Searches the index using the alias. More...
 

Private Member Functions

async Task< string > GetIdFromGraphNameAsync (string graphName)
 Queries the document ID for a metadata graph. More...
 
void HandleResponse (HttpResponseMessage response)
 Handles response of a HTTP request. More...
 
HttpContent CreateJsonContent (JObject content)
 
HttpContent CreateJsonContent (string content)
 
async Task< List< string > > AddOtherDocuments (List< string > contentList, KeyValuePair< string, JObject > document)
 Creates the content list for a bulk request with the given documents. More...
 
async Task BulkRequestAsync (IEnumerable< string > contentList)
 Executes a bulk request with the given list of content. More...
 
JProperty CreateVisibilityFilter (IEnumerable< string > projects)
 Creates the visibility filter for search to allow a user only to see public metadata or metadata of own projects. More...
 
async Task< IDictionary< string, double > > Search (JObject content)
 Runs the search and handles the response. More...
 
IDictionary< string, double > GetSearchResults (JObject results)
 Filters the plain search results of a search request. More...
 

Private Attributes

readonly string baseUrl
 
string _index
 

Static Private Attributes

const string ALIASES = "_aliases"
 
const string SEARCH = "_search"
 
const string MAPPING = "_mapping"
 
const string BULK = "_bulk"
 
static readonly HttpClient client = new HttpClient()
 

Detailed Description

Implements necessary functions to use Elasticsearch as a search engine.

Constructor & Destructor Documentation

◆ ElasticsearchSearchClient()

SemanticSearchImplementation.ElasticsearchSearchClient.ElasticsearchSearchClient ( string  server = "localhost",
string  port = "9200" 
)
inline

Member Function Documentation

◆ AddDocumentAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.AddDocumentAsync ( string  graphName,
IDictionary< string, JObject >  documents 
)
inline

Adds/updates a new document and possibly changes existing documents.

Additional rules can influence the mapping of existing metadata graphs.

Parameters
graphNameID of the metadata graph to be added/updated.
documentsA dictionary containing the ID of metadata graphs (key) and corresponding JSON objects (value).
Returns
A task that represents the asynchronous save operation.

Implements SemanticSearchImplementation.ISearchClient.

◆ AddDocumentsAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.AddDocumentsAsync ( IEnumerable< JObject >  documents)
inline

Adds the given documents as a bulk upload.

Parameters
documentsAn enumerator of all documents as JSON object.
Returns
A task that represents the asynchronous save operation.

Implements SemanticSearchImplementation.ISearchClient.

◆ AddOtherDocuments()

async Task<List<string> > SemanticSearchImplementation.ElasticsearchSearchClient.AddOtherDocuments ( List< string >  contentList,
KeyValuePair< string, JObject >  document 
)
inlineprivate

Creates the content list for a bulk request with the given documents.

Parameters
contentListA list containing the content for the bulk request.
documentIDs of metadata graphs (key) and their correcsponding content as JSON object (value).
Returns
The task result contains the created content list for the bulk request.

◆ BulkRequestAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.BulkRequestAsync ( IEnumerable< string >  contentList)
inlineprivate

Executes a bulk request with the given list of content.

Parameters
contentListAn enumerator of content rows for the bulk request.
Returns
A task that represents the asynchronous save operation.

◆ ChangeIndex()

void SemanticSearchImplementation.ElasticsearchSearchClient.ChangeIndex ( string  index)
inline

Updates the current index.

Parameters
indexName of new current index.

Implements SemanticSearchImplementation.ISearchClient.

◆ CreateIndexAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.CreateIndexAsync ( JObject  content,
string  index 
)
inline

Creates an index with the given settings and mappings.

Parameters
contentJSON object containing the settings and mappings.
indexThe index name.
Returns
A task that represents the asynchronous save operation.

Implements SemanticSearchImplementation.ISearchClient.

◆ CreateJsonContent() [1/2]

HttpContent SemanticSearchImplementation.ElasticsearchSearchClient.CreateJsonContent ( JObject  content)
inlineprivate

◆ CreateJsonContent() [2/2]

HttpContent SemanticSearchImplementation.ElasticsearchSearchClient.CreateJsonContent ( string  content)
inlineprivate

◆ CreateVisibilityFilter()

JProperty SemanticSearchImplementation.ElasticsearchSearchClient.CreateVisibilityFilter ( IEnumerable< string >  projects)
inlineprivate

Creates the visibility filter for search to allow a user only to see public metadata or metadata of own projects.

Parameters
projectsAn enumerator containing the projects which are allowed.
Returns
A JProperty containing the specified visibility filter.

◆ DeleteDocumentAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.DeleteDocumentAsync ( string  graphName,
IDictionary< string, JObject >  documents 
)
inline

Deletes a document and possibly changes other existing documents.

Additional rules can influence the mapping of existing metadata graphs.

Parameters
graphNameID of the metadata graph to be deleted.
documentsA dictionary containing the ID of metadata graphs (key) and corresponding JSON objects (value).
Returns
A task that represents the asynchronous delete operation.

Implements SemanticSearchImplementation.ISearchClient.

◆ DeleteIndexAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.DeleteIndexAsync ( string  index)
inline

Deletes the given index.

Parameters
indexName of the index.
Returns
A task that represents the asynchronous delete operation.

Implements SemanticSearchImplementation.ISearchClient.

◆ GetIdFromGraphNameAsync()

async Task<string> SemanticSearchImplementation.ElasticsearchSearchClient.GetIdFromGraphNameAsync ( string  graphName)
inlineprivate

Queries the document ID for a metadata graph.

Parameters
graphNameID of the metadata graph.
Returns
ID of the Elasticsearch document.

◆ GetMappingAsync()

async Task<IDictionary<string, string> > SemanticSearchImplementation.ElasticsearchSearchClient.GetMappingAsync ( )
inline

Queries the mappings of the current index.

Returns
A dictionary containing the fields and corresponding types.

Implements SemanticSearchImplementation.ISearchClient.

◆ GetSearchResults()

IDictionary<string, double> SemanticSearchImplementation.ElasticsearchSearchClient.GetSearchResults ( JObject  results)
inlineprivate

Filters the plain search results of a search request.

Parameters
resultsPlain JSON result of a search request.
Returns
A dictionary containing the ID of the metadata graphs (key) and the corresponding rankings (value),

◆ HandleResponse()

void SemanticSearchImplementation.ElasticsearchSearchClient.HandleResponse ( HttpResponseMessage  response)
inlineprivate

Handles response of a HTTP request.

Parameters
responseThe response of a HTTP request.

◆ Search()

async Task<IDictionary<string, double> > SemanticSearchImplementation.ElasticsearchSearchClient.Search ( JObject  content)
inlineprivate

Runs the search and handles the response.

Parameters
contentA JSON object containing the body of the search request.
Returns
The task result contains a dictionary containing the IDs of the found metadata graphs (key) and the corresponding ranking (value).

◆ SearchAsync()

async Task<IDictionary<string, double> > SemanticSearchImplementation.ElasticsearchSearchClient.SearchAsync ( string  query,
IEnumerable< string >  projects,
bool  advanced,
int  size,
int  from,
string  sorting 
)
inline

Searches the index using the alias.

Parameters
queryThe search query of the user.
projectsList of allowed projects (of a user).
advancedFlag to specify simple or advanced search syntax.
sizeNumber of results.
fromPosition from which the results should be returned.
sortingSorting of the results (see https://www.elastic.co/guide/en/elasticsearch/reference/current/sort-search-results.html).
Returns
The task result contains a dictionary containing the IDs of the found metadata graphs (key) and the corresponding ranking (value).

Implements SemanticSearchImplementation.ISearchClient.

◆ SwitchAliasAsync()

async Task SemanticSearchImplementation.ElasticsearchSearchClient.SwitchAliasAsync ( string  from,
string  to 
)
inline

Changes the alias from the old to the new index.

Parameters
fromName of old index.
toName of new index.
Returns

Implements SemanticSearchImplementation.ISearchClient.

Member Data Documentation

◆ _index

string SemanticSearchImplementation.ElasticsearchSearchClient._index
private

◆ ALIASES

const string SemanticSearchImplementation.ElasticsearchSearchClient.ALIASES = "_aliases"
staticprivate

◆ baseUrl

readonly string SemanticSearchImplementation.ElasticsearchSearchClient.baseUrl
private

◆ BULK

const string SemanticSearchImplementation.ElasticsearchSearchClient.BULK = "_bulk"
staticprivate

◆ client

readonly HttpClient SemanticSearchImplementation.ElasticsearchSearchClient.client = new HttpClient()
staticprivate

◆ MAPPING

const string SemanticSearchImplementation.ElasticsearchSearchClient.MAPPING = "_mapping"
staticprivate

◆ SEARCH

const string SemanticSearchImplementation.ElasticsearchSearchClient.SEARCH = "_search"
staticprivate

The documentation for this class was generated from the following file: