Example #1
0
        /// <summary>
        /// The initial search request to obtain the search identifier.
        /// </summary>
        /// <param name="term">The search term. Must be valid <see cref="SelectorType"/>.</param>
        /// <param name="buckets">The buckets to be queried for results.</param>
        /// <param name="timeout">The timeout in seconds.</param>
        /// <param name="maxResults">The maximum results to be queried per bucket, therefore the aggregated result set might be even bigger.</param>
        /// <param name="from">Result after the specified date. Both <paramref name="from"/> and <paramref name="to"/> are required if set.</param>
        /// <param name="to">Result before the specified date. Both <paramref name="from"/> and <paramref name="to"/> are required if set.</param>
        /// <param name="sorting">The sort order.</param>
        /// <param name="mediaType">The <see cref="MediaType"/> filter.</param>
        /// <param name="terminate">An array of search identifiers to be terminated. Can also be done with <seealso cref="TerminateAsync(Guid, CancellationToken)"/></param>
        /// <exception cref="ArgumentException">Thrown when invalid search <paramref name="term"/> is submitted.</exception>
        /// <returns>The search identifier to be used to retrieve the results.</returns>
        public async Task <Guid> SearchAsync(string term,
                                             string[] buckets    = default,
                                             int timeout         = 0, int maxResults    = 0,
                                             DateTime?from       = default, DateTime?to = default,
                                             SortType sorting    = default,
                                             MediaType mediaType = default,
                                             Guid[] terminate    = default,
                                             CancellationToken cancellationToken = default)
        {
            var searchRequest = new SearchRequest
            {
                Term       = term,
                Buckets    = buckets ?? Array.Empty <string>(),
                Timeout    = timeout,
                MaxResults = maxResults,
                DateFrom   = from,
                DateTo     = to,
                Sort       = sorting,
                Media      = mediaType,
                Terminate  = terminate ?? Array.Empty <Guid>()
            };

            var response = await IXAPI.PostAsync <SearchResponse>(_context,
                                                                  _apiPathSegment + "/search", searchRequest, cancellationToken : cancellationToken).ConfigureAwait(false);

            if (response.Status == SearchStatus.InvalidTerm)
            {
                throw new ArgumentException("Invalid input term.", nameof(term));
            }

            return(response.Id);
        }
        /// <summary>
        /// Fetches statistics about the search result items.
        /// </summary>
        public async Task <SearchStatistic> GetStatisticsAsync(Guid searchId)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", searchId }
            };

            return(await IXAPI.GetAsync <SearchStatistic>(_context,
                                                          "/intelligent/search/statistic", parameters).ConfigureAwait(false));
        }
        /// <summary>
        /// Fetches statistics about the search result items.
        /// </summary>
        public Task <SearchStatistic> GetStatisticsAsync(Guid searchId, CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", searchId }
            };

            return(IXAPI.GetAsync <SearchStatistic>(_context,
                                                    "/intelligent/search/statistic", parameters, cancellationToken: cancellationToken));
        }
Example #4
0
        /// <summary>
        /// Terminates the search job, no-op if the search was already terminated.
        /// </summary>
        /// <param name="searchId">The identifier of search to be terminated.</param>
        public async Task TerminateAsync(Guid searchId)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", searchId }
            };

            await IXAPI.PostAsync <string>(_context,
                                           "/intelligent/search/terminate", parameters).ConfigureAwait(false);
        }
Example #5
0
        public async Task <XScoreExplanation> ExplainXScoreAsync(Guid systemId, string bucket)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", systemId },
                { "bucket", bucket }
            };

            return(await IXAPI.GetAsync <XScoreExplanation>(_context,
                                                            "/item/explain/xscore", parameters).ConfigureAwait(false));
        }
Example #6
0
        public Task <XScoreExplanation> ExplainXScoreAsync(Guid systemId, string bucket, CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", systemId },
                { "bucket", bucket }
            };

            return(IXAPI.GetAsync <XScoreExplanation>(_context,
                                                      "/item/explain/xscore", parameters, cancellationToken: cancellationToken));
        }
Example #7
0
        public async Task <byte[]> ReadAsync(string storageId, string?bucket = default)
        {
            const int OUTPUT_TYPE_RAW_BINARY = 0;

            var parameters = new Dictionary <string, object>
            {
                { "type", OUTPUT_TYPE_RAW_BINARY },
                { "storageid", storageId },
                { "bucket", bucket ?? string.Empty }
            };

            return(await IXAPI.GetAsync <byte[]>(_context, "/file/read", parameters).ConfigureAwait(false));
        }
Example #8
0
        public async Task <IEnumerable <Selector> > ListSelectorsAsync(Guid systemId, string bucket)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", systemId },
                { "bucket", bucket }
            };

            var response = await IXAPI.GetAsync <ListSelectorsResponse>(_context,
                                                                        "/item/selector/list/human", parameters).ConfigureAwait(false);

            return(response.Selectors);
        }
Example #9
0
        public Task <byte[]> ReadAsync(string storageId, string?bucket = default, CancellationToken cancellationToken = default)
        {
            const int OUTPUT_TYPE_RAW_BINARY = 0;

            var parameters = new Dictionary <string, object>
            {
                { "type", OUTPUT_TYPE_RAW_BINARY },
                { "storageid", storageId },
                { "bucket", bucket ?? string.Empty }
            };

            return(IXAPI.GetAsync <byte[]>(_context, "/file/read", parameters, cancellationToken: cancellationToken));
        }
        public override async Task <(SearchResultStatus, IEnumerable <PhoneBookSelector>)> FetchResultsAsync(Guid searchId, int offset = 0, int limit = 100, CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", searchId },
                { "offset", offset },
                { "limit", limit }
            };

            var response = await IXAPI.GetAsync <PhoneBookSearchResults>(_context,
                                                                         _apiPathSegment + "/search/result", parameters, cancellationToken : cancellationToken).ConfigureAwait(false);

            return(response.Status, response.Selectors);
        }
        public override async Task <(SearchResultStatus, IEnumerable <Item>)> FetchResultsAsync(Guid searchId, int offset = 0, int limit = 100)
        {
            var parameters = new Dictionary <string, object>
            {
                { "id", searchId },
                { "offset", offset },
                { "limit", limit }
            };

            var response = await IXAPI.GetAsync <IntelligentSearchResults>(_context,
                                                                           _apiPathSegment + "/search/result", parameters).ConfigureAwait(false);

            return(response.Status, response.Records);
        }
Example #12
0
        public async Task <byte[]> ViewAsync(
            string storageId,
            string bucket,
            ViewFormat format = ViewFormat.Text,
            bool escapeHtml   = true)
        {
            var parameters = new Dictionary <string, object>
            {
                { "f", format },
                { "storageid", storageId },
                { "bucket", bucket },
                { "escape", escapeHtml ? 1 : 0 }
            };

            return(await IXAPI.GetAsync <byte[]>(_context, "/file/view", parameters).ConfigureAwait(false));
        }
Example #13
0
        public Task <byte[]> ViewAsync(
            string storageId,
            string bucket,
            ViewFormat format = ViewFormat.Text,
            bool escapeHtml   = true,
            CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "f", format },
                { "storageid", storageId },
                { "bucket", bucket },
                { "escape", escapeHtml ? 1 : 0 }
            };

            return(IXAPI.GetAsync <byte[]>(_context, "/file/view", parameters, cancellationToken: cancellationToken));
        }
Example #14
0
        public async Task <byte[]> PreviewAsync(
            string storageId,
            DataType dataType,
            MediaType mediaType,
            string bucket,
            int lineCount   = 12,
            bool escapeHtml = true)
        {
            var parameters = new Dictionary <string, object>
            {
                { "sid", storageId },
                { "b", bucket },
                { "l", lineCount },
                { "f", mediaType == MediaType.Picture ? 1 : 0 },
                { "c", dataType },
                { "m", mediaType },
                { "e", escapeHtml ? 1 : 0 }
            };

            return(await IXAPI.GetAsync <byte[]>(_context, "/file/preview", parameters).ConfigureAwait(false));
        }
Example #15
0
        public Task <byte[]> PreviewAsync(
            string storageId,
            DataType dataType,
            MediaType mediaType,
            string bucket,
            int lineCount   = 12,
            bool escapeHtml = true,
            CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object>
            {
                { "sid", storageId },
                { "b", bucket },
                { "l", lineCount },
                { "f", mediaType == MediaType.Picture ? 1 : 0 },
                { "c", dataType },
                { "m", mediaType },
                { "e", escapeHtml ? 1 : 0 }
            };

            return(IXAPI.GetAsync <byte[]>(_context, "/file/preview", parameters, cancellationToken: cancellationToken));
        }
Example #16
0
 /// <summary>
 /// Terminates the search job, no-op if the search was already terminated.
 /// </summary>
 /// <param name="searchId">The identifier of search to be terminated.</param>
 public Task TerminateAsync(Guid searchId, CancellationToken cancellationToken = default)
 {
     return(IXAPI.GetAsync <string>(_context, "/intelligent/search/terminate?id=" + searchId, cancellationToken: cancellationToken));
 }