Example #1
0
        protected MemberSearchResults Search(MemberSearchQuery memberQuery, int skip, int take)
        {
            var searcher      = new Searcher(_indexWriter.getReader());
            var query         = _indexer.GetQuery(memberQuery);
            var filter        = _indexer.GetFilter(memberQuery, null, null);
            var selections    = _indexer.GetSelections(memberQuery);
            var sort          = _indexer.GetSort(null, memberQuery);
            var searchResults = searcher.Search(query, filter, selections, sort == null ? null : sort.getSort(), skip, take, true);

            return(searchResults);
        }
Example #2
0
        private MemberSearchResults Search(Guid?employerId, Guid?organisationId, MemberSearchQuery searchQuery, Func <Employer, MemberSearchQuery, IList <Guid> > getIncludeMemberIds, Func <Employer, MemberSearchQuery, IList <Guid> > getExcludeMemberIds)
        {
            const string method = "SearchFolder";

            try
            {
                #region Log
                Stopwatch searchTime = null;
                if (EventSource.IsEnabled(Event.Trace))
                {
                    searchTime = Stopwatch.StartNew();
                }
                #endregion

                // Employer.

                var employer = employerId == null || organisationId == null
                    ? null
                    : new Employer {
                    Id = employerId.Value, Organisation = new Organisation {
                        Id = organisationId.Value
                    }
                };

                // Gather the pieces.

                var query      = _indexer.GetQuery(searchQuery);
                var filter     = _indexer.GetFilter(searchQuery, getIncludeMemberIds(employer, searchQuery), getExcludeMemberIds(employer, searchQuery));
                var selections = _indexer.GetSelections(searchQuery);
                var sort       = _indexer.GetSort(employer, searchQuery);

                #region Log
                if (EventSource.IsEnabled(Event.Trace))
                {
                    EventSource.Raise(Event.Trace, method, "Executing query.", Event.Arg("query", (query != null) ? query.toString() : string.Empty));
                }
                #endregion

                // Search.

                var reader        = GetReader();
                var searcher      = new Searcher(reader);
                var sorts         = (sort != null) ? sort.getSort() : null;
                var searchResults = searcher.Search(query, filter, selections, sorts, searchQuery.Skip, searchQuery.Take ?? reader.maxDoc(), true);

                #region Log
                if (searchTime != null)
                {
                    searchTime.Stop();
                    EventSource.Raise(Event.Trace, method, "Query execution complete.", Event.Arg("query", (query != null) ? query.toString() : string.Empty), Event.Arg("total hits", searchResults.TotalMatches), Event.Arg("result count", searchResults.MemberIds.Count), Event.Arg("searchTime", searchTime.ElapsedMilliseconds));
                }
                #endregion

                return(searchResults);
            }
            catch (Exception e)
            {
                #region Log
                EventSource.Raise(Event.Error, method, "Unexpected exception.", e);
                #endregion
                throw;
            }
        }