public override async Task <IEnumerable <ArtifactSearchResult> > GetSemanticSearchSuggestions(SearchEngineParameters searchEngineParameters) { try { var index = await SemanticSearchRepository.GetSemanticSearchIndex(); if (String.IsNullOrEmpty(index)) { // Returning empty results when index has not been created yet. return(new List <ArtifactSearchResult>()); } PerformIndexHealthCheck(index); // Setting default index name on the connection, otherwise the search request will fail _elasticClient.ConnectionSettings.DefaultIndices.Clear(); _elasticClient.ConnectionSettings.DefaultIndices.Add(typeof(SemanticSearchItem), index); var searchText = await SemanticSearchRepository.GetSemanticSearchText(searchEngineParameters.ArtifactId, searchEngineParameters.UserId); // Create the bool query descripter that just searchs for the searchText we constructed var boolQueryDescriptor = new BoolQueryDescriptor <SemanticSearchItem>(); boolQueryDescriptor.Must(GetMoreLikeThisQuery(searchText)); // Dont return back result for the current artifact id we're searching against boolQueryDescriptor.MustNot(GetArtifactIdMatchQuery(searchEngineParameters.ArtifactId)); // If not instance admin, use the list of accessible project ids to filter out, otherwise no need to filter if (!searchEngineParameters.IsInstanceAdmin) { boolQueryDescriptor.Filter(GetContainsProjectIdsQuery(searchEngineParameters.AccessibleProjectIds)); } // Creates the search descriptor var searchDescriptor = new SearchDescriptor <SemanticSearchItem>(); searchDescriptor.Index(index).Size(searchEngineParameters.PageSize).Query(q => q.Bool(b => boolQueryDescriptor)); var results = await _elasticClient.SearchAsync <SemanticSearchItem>(searchDescriptor); var hits = results.Hits; var itemIds = new List <int>(); hits.ForEach(a => { int output; if (Int32.TryParse(a.Id, out output)) { itemIds.Add(output); } }); // parse the artifact ids into a artifactsearchresult to return to the caller return(await GetArtifactSearchResultsFromItemIds(itemIds.Distinct().ToList(), searchEngineParameters.UserId)); } catch (Exception ex) { if (ex is ElasticsearchConfigurationException) { throw; } throw new ElasticsearchException(I18NHelper.FormatInvariant("Elastic search failed to process search. Exception:{0}", ex)); } }