Exemple #1
0
        public ApiModule(
            [NotNull] ISuggestQueryParser suggestQueryParser,
            [NotNull] ISuggestQueryHandler suggestQueryHandler,
            [NotNull] ISearchQueryParser searchQueryParser,
            [NotNull] ISearchQueryHandler searchQueryHandler)
        {
            Logger.Debug("Starting module {module}", nameof(ApiModule));

            Get["/suggest"] = _ =>
            {
                Logger.Verbose("Processing {method} method for the path {path}", Request.Method, Request.Path);

                using (Logger.BeginTimedOperation("suggest", level: LogEventLevel.Verbose))
                {
                    string text;
                    int    count;
                    IEnumerable <string> errors;
                    if (!suggestQueryParser.TryParse(Request.Query, out text, out count, out errors))
                    {
                        return(Response.AsJson(errors, HttpStatusCode.BadRequest));
                    }

                    return(Response.AsJson(new { matches = suggestQueryHandler.Suggest(text, count) }));
                }
            };


            Get["/query"] = _ =>
            {
                Logger.Verbose("Processing {method} method for the path {path}", Request.Method, Request.Path);

                using (Logger.BeginTimedOperation("query", level: LogEventLevel.Verbose))
                {
                    string text;
                    int    count;
                    IEnumerable <string> errors;
                    if (!searchQueryParser.TryParse(Request.Query, out text, out count, out errors))
                    {
                        return(Response.AsJson(errors, HttpStatusCode.BadRequest));
                    }

                    return(Response.AsJson(new { matches = searchQueryHandler.Search(text, count) }));
                }
            };
        }
Exemple #2
0
    public QueryBuilder(ILogger <QueryBuilder> logger, IViewTypeInfoService typeInfoService,
                        IMapper mapper, ISearchQueryParser parser, IPermissionService permissionService)
    {
        this.logger            = logger;
        this.typeService       = typeInfoService;
        this.mapper            = mapper;
        this.parser            = parser;
        this.permissionService = permissionService;

        var assembly = System.Reflection.Assembly.GetAssembly(typeof(contentapi.data.Views.UserView)) ?? throw new InvalidOperationException("NO ASSEMBLY FOR QUERYBUILDER???");

        //Pull the view types out, compute the STANDARD mapping of requests to views. Requests that don't have a standard mapping have something custom and don't go through
        //any of the standard codepaths (they do their own thing entirely)
        ViewTypes = assembly.GetTypes().Where(t => String.Equals(t.Namespace, $"{nameof(contentapi)}.{nameof(contentapi.data)}.{nameof(contentapi.data.Views)}", StringComparison.Ordinal)).ToList();
        var typeInfos = ViewTypes.Select(x => typeInfoService.GetTypeInfo(x));

        StandardViewRequests = typeInfos.Where(x => x.requestType.HasValue).ToDictionary(
            k => k.requestType ?? throw new InvalidOperationException("How did the HasValue check fail on StandardViewRequest build??"), v => v.type);

        if (StandardViewRequests.Count == 0)
        {
            throw new InvalidOperationException("NO VIEWS FOUND FOR CACHING IN QUERY BUILDER!! Check the namespace!");
        }
    }
 public EntitySearch(IRepository <T> repository, ISearchQueryParser searchQueryParser, IQueryModifierFactory queryModifierFactory)
 {
     _repository           = repository;
     _searchQueryParser    = searchQueryParser;
     _queryModifierFactory = queryModifierFactory;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchScoreExplainer"/> class.
        /// </summary>
        /// <param name="searchQueryParser">The search query parser.</param>
		public SearchScoreExplainer(ISearchQueryParser searchQueryParser)
		{
			this.searchQueryParser = searchQueryParser;
		}
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Searcher{TSearchData}"/> class.
 /// </summary>
 /// <param name="searchQueryParser">The search query parser.</param>
 /// <param name="documentToSearchDataTypeConverter">The document to search data type converter.</param>
 public Searcher(ISearchQueryParser searchQueryParser, IDocumentToSearchDataTypeConverter <TSearchData> documentToSearchDataTypeConverter)
 {
     this.searchQueryParser = searchQueryParser;
     this.documentToSearchDataTypeConverter = documentToSearchDataTypeConverter;
 }
Exemple #6
0
 public EntitySearcherBuilder <T> WithSearchStatementParser(ISearchQueryParser searchQueryParser)
 {
     _searchQueryParser = searchQueryParser;
     return(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SearchScoreExplainer"/> class.
 /// </summary>
 /// <param name="searchQueryParser">The search query parser.</param>
 public SearchScoreExplainer(ISearchQueryParser searchQueryParser)
 {
     this.searchQueryParser = searchQueryParser;
 }
Exemple #8
0
 public EntitySearch(IStudyBuddyDbContext context, ISearchQueryParser searchQueryParser, IQueryModifierFactory queryModifierFactory)
 {
     _context              = context;
     _searchQueryParser    = searchQueryParser;
     _queryModifierFactory = queryModifierFactory;
 }