public FulltextSearchResultContract ProcessSearchByCriteriaCount(ICountResponse response) { if (!response.IsValid) { throw new FulltextDatabaseException(response.DebugInformation); } return(new FulltextSearchResultContract { Count = response.Count }); }
/*---------Metodos genericos------------------*/ public int GetCount(string tipo) { ICountResponse response = null; if (tipo == "log") { response = Client.Count <Log>(c => c.Index(Index).Type(Index)); } else if (tipo == "votacion") { response = Client.Count <Votacion>(c => c.Index(Index).Type(Index)); } return((int)response.Count); }
public long Count() { ICountResponse result = this._esClient.Count <T>( c => c.Index(this._entityIndex) .Type(this._entityType) ); if (!result.IsValid) { this._logger.LogError(result.OriginalException, $"Error in getting count of entities of type {this._entityType} to index {this._entityIndex}", new[] { result }); throw result.OriginalException; } this._logger.LogTrace($"There are {result.Count} entities of type {this._entityType} in index {this._entityIndex}.", new[] { result }); return(result.Count); }
/// <summary> /// Get the total number of terms available in the version of a dictionary matching a specific audience and language. /// </summary> /// <param name="dictionary">The specific dictionary to retrieve from.</param> /// <param name="audience">The target audience.</param> /// <param name="language">Language (English - en; Spanish - es).</param> /// <returns>The number of terms available.</returns> public async Task <long> GetCount(string dictionary, AudienceType audience, string language) { // Set up the CountRequest to send to elasticsearch. Indices index = Indices.Index(new string[] { this._apiOptions.AliasName }); Types types = Types.Type(new string[] { "terms" }); CountRequest request = new CountRequest(index, types) { Query = new TermQuery { Field = "language", Value = language.ToString() } && new TermQuery { Field = "audience", Value = audience.ToString() } && new TermQuery { Field = "dictionary", Value = dictionary.ToString() } }; ICountResponse response = null; try { response = await _elasticClient.CountAsync <GlossaryTerm>(request); } catch (Exception ex) { String msg = $"Could not get a count for dictionary '{dictionary}', audience '{audience}', language '{language}'"; _logger.LogError($"Error getting count on index: '{this._apiOptions.AliasName}'."); _logger.LogError(msg, ex); throw new APIErrorException(500, msg); } if (!response.IsValid) { String msg = $"Invalid response when searching for dictionary '{dictionary}', audience '{audience}', language '{language}'"; _logger.LogError(msg); throw new APIErrorException(500, "errors occured"); } return(response.Count); }