public IActionResult SearchAddress(string address = "")
        {
            if (!string.IsNullOrEmpty(address))
            {
                var query = new SearchQuery
                {
                    Index = "fts_index",
                    Query = new MatchQuery(address)
                }
                .Limit(10);
                var             result    = bucket.Query(query);
                List <Landmark> landmarks = new List <Landmark>();

                ISearchQueryResult searchQueryRows = result;
                foreach (var item in searchQueryRows)
                {
                    var landmark = bucket.GetDocument <Landmark>(item.Id).Document.Content;

                    landmarks.Add(landmark);
                }

                return(View(landmarks));
            }
            else
            {
                List <Landmark> landmarks = new List <Landmark>();
                return(View(landmarks));
            }
        }
Example #2
0
        public ISearchQueryResult Send(SearchQuery searchQuery)
        {
            ISearchQueryResult searchResult = null;

            if (_isDown)
            {
                searchResult = HandleNodeUnavailable(searchQuery.Query);
            }
            else
            {
                try
                {
                    searchResult = SearchClient.Query(searchQuery);
                }
                catch (Exception e)
                {
                    MarkDead();
                    searchResult = new SearchQueryResult
                    {
                        Exception = e,
                        Success   = false
                    };
                }
            }
            return(searchResult);
        }
Example #3
0
 protected IActionResult CouchbaseError(ISearchQueryResult result)
 {
     return(StatusCode((int)HttpStatusCode.InternalServerError, new
     {
         message = ErrorMessage(result)
     }));
 }
        /// <summary>
        /// Throws a <see cref="CouchbaseSearchResponseException"/> on any error.
        /// </summary>
        /// <param name="result">The result.</param>
        public static void EnsureSuccess(this ISearchQueryResult result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (!result.Success)
            {
                throw CouchbaseSearchResponseException.FromResult(result);
            }
        }
Example #5
0
        private string ErrorMessage(ISearchQueryResult result)
        {
            var errorMessages = new List <string>();

            if (!string.IsNullOrEmpty(result.Message))
            {
                errorMessages.Add($"Message: '{result.Message}'");
            }
            if (result.Errors != null && result.Errors.Any())
            {
                errorMessages.AddRange(result.Errors.Select(e => $"Error: {e}"));
            }
            if (result.Exception != null)
            {
                errorMessages.Add($"Exception: {result.Exception.Message}");
            }
            return(string.Join(", ", errorMessages));
        }
        public override async Task <ISearchQueryResult> SendWithRetryAsync(SearchQuery searchQuery)
        {
            ISearchQueryResult searchResult = null;

            try
            {
                if (!ConfigInfo.IsSearchCapable)
                {
                    throw new ServiceNotSupportedException
                              (ExceptionUtil.GetMessage(ExceptionUtil.ServiceNotSupportedMsg, "FTS"));
                }

                var     attempts = 0;
                IServer server;
                while ((server = ConfigInfo.GetSearchNode()) == null)
                {
                    if (attempts++ > 10)
                    {
                        throw new TimeoutException("Could not acquire a server.");
                    }
                    Thread.Sleep((int)Math.Pow(2, attempts));
                }

                searchResult = await server.SendAsync(searchQuery);
            }
            catch (Exception e)
            {
                Log.Info(e);
                searchResult = new SearchQueryResult
                {
                    Status    = SearchStatus.Failed,
                    Success   = false,
                    Exception = e
                };
            }
            return(searchResult);
        }
 /// <summary>
 /// Creates a new CouchbaseQueryResponseException.
 /// </summary>
 /// <param name="result">Result from Couchbase</param>
 internal static CouchbaseSearchResponseException FromResult(ISearchQueryResult result)
 {
     return(new CouchbaseSearchResponseException(
                ExceptionUtil.GetResponseExceptionMessage(result.Errors.FirstOrDefault(), result.Status),
                result.Status, result.Errors, result.Exception));
 }
 public SearchResult(ISearchQueryResult[] searchQueryQueryResults)
 {
     SearchQueryResults = searchQueryQueryResults;
     Tweets = searchQueryQueryResults.SelectMany(x => x.FilteredTweets);
     NumberOfQueriesUsedToCompleteTheSearch = searchQueryQueryResults.Length;
 }
Example #9
0
        public void SearchResult_EnsureSuccess_Throws_ArguementNulException_When_Result_Is_Null()
        {
            ISearchQueryResult result = null;

            Assert.Throws <ArgumentNullException>(() => result.EnsureSuccess());
        }