public static Func <IEnumerable <Word>, IEnumerable <Word>, IEnumerable <Word>, IEnumerable <HealthRecord> > WithAllAnyNotWords(ISession session) { return((all, any, not) => { Contract.Ensures(Contract.Result <IEnumerable <HealthRecord> >() != null); // записи где слова - надмножество all // all.IsSubmultisetOf(hr.Words) // var withAny = withall.Where(hr => any.Any(w => hr.Words.DifferenceWith(all).Contains(w))); // TODO minany // записи где set(all) - подмножество слов записи //all.IsSubsetOf(hr.Words) if (any.Any() || all.Any()) { var withAny = WithAnyWord(session)(any.Any() ? any : all); var withall = withAny.Where(hr => all.IsSubsetOf(hr.Words)); // записи где слова - надмножество all return withall.Where(hr => !hr.Words.Any(w => not.Contains(w))); //IEnumerable<HealthRecord> allany; //if (any.Any() && all.Any()) //{ // var withall = WithAllWords(session)(all); // allany = withall.Where(hr => any.Any(w => hr.Words.Contains(w))); //} //else if (any.Any()) // allany = WithAnyWord(session)(any); //else // all.Any() // allany = WithAllWords(session)(all); //return allany.Where(hr => !hr.Words.Any(w => not.Contains(w))); } else { return WithoutAnyWord(session)(not); } }); }
/// <summary> /// Возвращает записи со всеми словами в области поиска. /// Повторы слов должны быть в записи минимум столько раз, сколько передано. /// </summary> public static Func <IEnumerable <Word>, HealthRecordQueryAndScope, IEnumerable <HealthRecord> > WithAllWordsInScope(ISession session) { return((words, scope) => { Contract.Ensures(Contract.Result <IEnumerable <HealthRecord> >() != null); var withAny = WithAnyWord(session)(words); switch (scope) { case HealthRecordQueryAndScope.Appointment: return GetHrsInScope(words, withAny, (hr) => hr.Appointment); case HealthRecordQueryAndScope.Course: return GetHrsInScope(words, withAny, (hr) => hr.GetCourse()); case HealthRecordQueryAndScope.Patient: return GetHrsInScope(words, withAny, (hr) => hr.GetPatient()); default: case HealthRecordQueryAndScope.HealthRecord: return withAny.Where(hr => words.IsSubmultisetOf(hr.Words)).ToList(); } }); }