private int GetResults(SearchQueryRequest searchQueryRequest) { int totalRows = 0; bool keepTrying = true; // Pick default result processor if (!ResultProcessor.HasValue) // user has not specified one { if (Refiners != null) { ResultProcessor = PSSQT.ResultProcessor.Refiners; } else { ResultProcessor = PSSQT.ResultProcessor.Primary; } WriteVerbose(String.Format("Using ResultProcessor {0}", Enum.GetName(typeof(ResultProcessor), ResultProcessor))); } IQueryResultProcessor queryResultProcessor = QueryResultProcessorFactory.SelectQueryResultProcessor(ResultProcessor.Value, this, searchQueryRequest); queryResultProcessor.Configure(); // May add required properties to retrieve (e.g. rankdetail etc.) while (keepTrying) { keepTrying = false; try { var requestResponsePair = HttpRequestRunner.RunWebRequest(SetSelectProperties(searchQueryRequest)); var queryResults = requestResponsePair.GetResultItem(); totalRows = queryResults.PrimaryQueryResult.TotalRows; queryResultProcessor.Process(queryResults); } catch (RankDetailTooManyResults ex) { WriteWarning("More than 100 results in result set. Resubmitting query with filter to get RankDetail."); searchQueryRequest.QueryText += ex.QueryFilter; keepTrying = true; } catch (Exception ex) { if (!queryResultProcessor.HandleException(ex)) { throw; } } } return(totalRows); }
private void GetResults(SearchSuggestionsRequest searchSuggestionsRequest) { ISuggestionsResultProcessor suggestionResultProcessor = new SuggestionsResultProcessor(this); suggestionResultProcessor.Configure(); WriteVerbose($"Request: {searchSuggestionsRequest.ToString()}"); var requestResponsePair = HttpRequestRunner.RunWebRequest(searchSuggestionsRequest); var suggestionResults = requestResponsePair.GetResultItem <SearchSuggestionsResult>(); suggestionResultProcessor.Process(suggestionResults); }
private int GetResults(SearchQueryRequest searchQueryRequest) { int totalRows = 0; bool keepTrying = true; IQueryResultProcessor queryResultProcessor = QueryResultProcessorFactory.SelectQueryResultProcessor(ResultProcessor, this); queryResultProcessor.Configure(); // May add required properties to retrieve (e.g. rankdetail etc.) while (keepTrying) { keepTrying = false; try { var requestResponsePair = HttpRequestRunner.RunWebRequest(Up2Date(searchQueryRequest)); var queryResults = GetResultItem(requestResponsePair); totalRows = queryResults.PrimaryQueryResult.TotalRows; queryResultProcessor.Process(queryResults); } catch (RankDetailTooManyResults ex) { WriteWarning("More than 100 results in result set. Resubmitting query with filter to get RankDetail."); searchQueryRequest.QueryText += ex.QueryFilter; keepTrying = true; } catch (Exception ex) { if (!queryResultProcessor.HandleException(ex)) { throw; } } } return(totalRows); }
protected override void PrimaryResultPopulateItem(ResultItem resultItem, PSObject item) { if (++CurrentRow > MaxRows) { throw new AllPropertiesMaxRowsExhausted(); } RetrieveAllPropertiesFailed = false; // Perform a new search for this resultItem.workid and retrieve the refiner "managedproperties(filter=600/0/*)" var clonedRequest = request.Clone(); var key = resultItem.Id(); if (key == null) { throw new RuntimeException("Could not retrieve workid from result item."); // todo: add more detail } clonedRequest.QueryText = String.Format("WorkId:\"{0}\"", resultItem[key]); clonedRequest.Refiners = managedPropertiesRefiner; try { var requestResponsePair = HttpRequestRunner.RunWebRequest(clonedRequest); var queryResults = requestResponsePair.GetResultItem(); // Ensure we got primary results and refiner results if (queryResults.PrimaryQueryResult == null || queryResults.PrimaryQueryResult.RefinerResults == null) { throw new RuntimeException("The ManagedProperties property does not contain values."); // todo: add more detail } var refiners = queryResults.PrimaryQueryResult.RefinerResults[0]; // Extract properties from refiner and query again clonedRequest.Refiners = String.Empty; clonedRequest.SelectProperties = String.Join(",", refiners.Select(x => x.Name).ToArray()); clonedRequest.SelectProperties = clonedRequest.SelectProperties.Replace(",ClassificationLastScan", ""); // this mp messes up the call clonedRequest.HttpMethodType = HttpMethodType.Post; requestResponsePair = HttpRequestRunner.RunWebRequest(clonedRequest); queryResults = requestResponsePair.GetResultItem(); if (queryResults.PrimaryQueryResult == null || queryResults.PrimaryQueryResult.RelevantResults == null) { throw new RuntimeException("Failed to retrieve all properties for result item."); // todo: add more detail } ResultItem relevantResult = queryResults.PrimaryQueryResult.RelevantResults[0]; //Cmdlet.WriteVerbose(String.Format("AllPropertiesResultProcessor: TotalRows: {0}", MaxRows)); AddAllProperties(item, key, relevantResult); } catch (Exception e) { RetrieveAllPropertiesFailed = true; Cmdlet.WriteWarning(String.Format("Failed to read all properties for result item with {0} {1}", key, resultItem[key])); // todo: add detail Cmdlet.WriteDebug(e.Message); } }