public TextQueryResponse <ProcedureTypeSummary> TextQuery(TextQueryRequest request)
        {
            var broker    = PersistenceContext.GetBroker <IProcedureTypeBroker>();
            var assembler = new ProcedureTypeAssembler();

            var helper = new TextQueryHelper <ProcedureType, ProcedureTypeSearchCriteria, ProcedureTypeSummary>(
                delegate
            {
                var rawQuery = request.TextQuery;

                IList <string> terms = TextQueryHelper.ParseTerms(rawQuery);
                var criteria         = new List <ProcedureTypeSearchCriteria>();

                // allow matching on name (assume entire query is a name which may contain spaces)
                var nameCriteria = new ProcedureTypeSearchCriteria();
                nameCriteria.Name.StartsWith(rawQuery);
                criteria.Add(nameCriteria);

                // allow matching of any term against ID
                criteria.AddRange(CollectionUtils.Map(terms,
                                                      delegate(string term)
                {
                    var c = new ProcedureTypeSearchCriteria();
                    c.Id.StartsWith(term);
                    return(c);
                }));

                return(criteria.ToArray());
            },
                assembler.CreateSummary,
                (criteria, threshold) => broker.Count(criteria) <= threshold,
                broker.Find);

            return(helper.Query(request));
        }
Esempio n. 2
0
        public TextQueryResponse <DiagnosticServiceSummary> TextQuery(TextQueryRequest request)
        {
            IDiagnosticServiceBroker   broker    = PersistenceContext.GetBroker <IDiagnosticServiceBroker>();
            DiagnosticServiceAssembler assembler = new DiagnosticServiceAssembler();

            TextQueryHelper <DiagnosticService, DiagnosticServiceSearchCriteria, DiagnosticServiceSummary> helper
                = new TextQueryHelper <DiagnosticService, DiagnosticServiceSearchCriteria, DiagnosticServiceSummary>(
                      delegate
            {
                string rawQuery = request.TextQuery;

                IList <string> terms = TextQueryHelper.ParseTerms(rawQuery);
                List <DiagnosticServiceSearchCriteria> criteria = new List <DiagnosticServiceSearchCriteria>();

                // allow matching on name (assume entire query is a name which may contain spaces)
                DiagnosticServiceSearchCriteria nameCriteria = new DiagnosticServiceSearchCriteria();
                nameCriteria.Name.StartsWith(rawQuery);
                criteria.Add(nameCriteria);

                // allow matching of any term against ID
                criteria.AddRange(CollectionUtils.Map <string, DiagnosticServiceSearchCriteria>(terms,
                                                                                                delegate(string term)
                {
                    DiagnosticServiceSearchCriteria c = new DiagnosticServiceSearchCriteria();
                    c.Id.StartsWith(term);
                    return(c);
                }));

                return(criteria.ToArray());
            },
                      delegate(DiagnosticService ds)
            {
                return(assembler.CreateSummary(ds));
            },
                      delegate(DiagnosticServiceSearchCriteria[] criteria, int threshold)
            {
                return(broker.Count(criteria) <= threshold);
            },
                      delegate(DiagnosticServiceSearchCriteria[] criteria, SearchResultPage page)
            {
                return(broker.Find(criteria, page));
            });

            return(helper.Query(request));
        }