Exemplo n.º 1
0
 public Task <Live.LiveSearchResponse> LiveSearchAsync(
     string q,
     int offset,
     int limit,
     SearchTargetType targets    = SearchTargetType.All,
     LiveSearchFieldType fields  = LiveSearchFieldType.All,
     LiveSearchSortType sortType = LiveSearchSortType.StartTime | LiveSearchSortType.SortDecsending,
     ISearchFilter searchFilter  = null
     )
 {
     return(Live.LiveSearchClient.GetLiveSearchAsync(_context,
                                                     q,
                                                     offset,
                                                     limit,
                                                     targets,
                                                     fields,
                                                     sortType,
                                                     searchFilter
                                                     ));
 }
Exemplo n.º 2
0
 /// <summary>
 /// 生放送情報の検索結果を取得します。
 /// </summary>
 /// <param name="q">検索キーワード</param>
 /// <param name="offset">返ってくるコンテンツの取得オフセット。最大:1600</param>
 /// <param name="limit">返ってくるコンテンツの最大数。最大:100</param>
 /// <param name="targets">検索対象のフィールド</param>
 /// <param name="fields">レスポンスに含みたいヒットしたコンテンツのフィールド</param>
 /// <param name="sortType">ソート順(デフォルトは降順/Decsending)。昇順指定する場合は LiveSearchSortType.SortAcsending を | で繋いで指定します。</param>
 /// <param name="filterExpression">検索結果をフィルタの条件にマッチするコンテンツだけに絞ります。</param>
 /// <see cref="https://site.nicovideo.jp/search-api-docs/search.html"/>
 public Task <Live.LiveSearchResponse> LiveSearchAsync(
     string q,
     int offset,
     int limit,
     SearchTargetType targets    = SearchTargetType.All,
     LiveSearchFieldType fields  = LiveSearchFieldType.All,
     LiveSearchSortType sortType = LiveSearchSortType.StartTime | LiveSearchSortType.SortDecsending,
     Expression <Func <SearchFilterField, bool> > filterExpression = null
     )
 {
     return(Live.LiveSearchClient.GetLiveSearchAsync(_context,
                                                     q,
                                                     offset,
                                                     limit,
                                                     targets,
                                                     fields,
                                                     sortType,
                                                     filterExpression
                                                     ));
 }
Exemplo n.º 3
0
 public static Task <LiveSearchResponse> GetLiveSearchAsync(
     NiconicoContext context,
     string q,
     int offset,
     int limit,
     SearchTargetType targets    = SearchTargetType.All,
     LiveSearchFieldType fields  = LiveSearchFieldType.ContentId,
     LiveSearchSortType sortType = LiveSearchSortType.StartTime | LiveSearchSortType.SortDecsending,
     Expression <Func <SearchFilterField, bool> > filterExpression = null
     )
 {
     return(GetLiveSearchAsync(
                context,
                q,
                offset,
                limit,
                targets,
                fields,
                sortType,
                searchFilter: filterExpression != null ? new ExpressionSearchFilter(filterExpression) : default(ISearchFilter)
                ));
 }
Exemplo n.º 4
0
        public static async Task <LiveSearchResponse> GetLiveSearchAsync(
            NiconicoContext context,
            string q,
            int offset,
            int limit,
            SearchTargetType targets    = SearchTargetType.All,
            LiveSearchFieldType fields  = LiveSearchFieldType.ContentId,
            LiveSearchSortType sortType = LiveSearchSortType.StartTime | LiveSearchSortType.SortDecsending,
            ISearchFilter searchFilter  = null
            )
        {
            if (string.IsNullOrWhiteSpace(q))
            {
                throw new ArgumentException("q value must contains any character.");
            }
            if (offset < 0 || offset >= SearchConstants.MaxSearchOffset)
            {
                throw new ArgumentException("offset value out of bounds. (0 <= offset <= 1600)");
            }

            if (limit < 0 || limit >= SearchConstants.MaxSearchLimit)
            {
                throw new ArgumentException("limit value out of bounds. (0 <= limit <= 100)");
            }

            var dict = new Dictionary <string, string>()
            {
                { SearchConstants.QuaryParameter, q },
                { SearchConstants.OffsetParameter, offset.ToString() },
                { SearchConstants.LimitParameter, limit.ToString() },
                { SearchConstants.TargetsParameter, SearchHelpers.ToQueryString(targets) },
            };

            if (context.AdditionalUserAgent != null)
            {
                dict.Add(SearchConstants.ContextParameter, context.AdditionalUserAgent);
            }

            if (fields != LiveSearchFieldType.None)
            {
                dict.Add(SearchConstants.FieldsParameter, SearchHelpers.ToQueryString(fields));
            }

            if (sortType != LiveSearchSortType.None)
            {
                dict.Add(SearchConstants.SortParameter, SearchHelpers.ToQueryString(sortType));
            }

            if (searchFilter != null)
            {
                var filters = searchFilter.GetFilterKeyValues();
                foreach (var f in filters)
                {
                    dict.Add(f.Key, f.Value);
                }
            }

            var json = await context.GetStringAsync(SearchConstants.LiveSearchEndPoint, dict);

            return(JsonSerializerExtensions.Load <LiveSearchResponse>(json));
        }