/// <summary> /// Register the query as a lazy async query in the session and return a lazy async /// instance that will evaluate the query only when needed /// </summary> public Lazy <Task <IEnumerable <S> > > LazilyAsync <S>(Expression expression, Action <IEnumerable <S> > onEval) { var processor = GetQueryProviderProcessor <S>(); var query = processor.GetDocumentQueryForAsync(expression); if (afterQueryExecuted != null) { query.AfterQueryExecuted(afterQueryExecuted); } var renamedFields = FieldsToFetch.Select(field => { var renamedField = FieldsToRename.FirstOrDefault(x => x.OriginalField == field); if (renamedField != null) { return(renamedField.NewField ?? field); } return(field); }).ToArray(); if (renamedFields.Length > 0) { query.AfterQueryExecuted(processor.RenameResults); } if (FieldsToFetch.Count > 0) { query = query.SelectFields <S>(FieldsToFetch.ToArray(), renamedFields); } return(query.LazilyAsync(onEval)); }
/// <summary> /// Register the query as a lazy query in the session and return a lazy /// instance that will evaluate the query only when needed /// </summary> public Lazy <IEnumerable <S> > Lazily <S>(Expression expression, Action <IEnumerable <S> > onEval) { var processor = GetQueryProviderProcessor <S>(); var query = processor.GetLuceneQueryFor(expression); if (afterQueryExecuted != null) { query.AfterQueryExecuted(afterQueryExecuted); } var renamedFields = FieldsToFetch.Select(field => { string value; if (FieldsToRename.TryGetValue(field, out value) && value != null) { return(value); } return(field); }).ToArray(); if (renamedFields.Length > 0) { query.AfterQueryExecuted(processor.RenameResults); } if (FieldsToFetch.Count > 0) { query = query.SelectFields <S>(FieldsToFetch.ToArray(), renamedFields); } return(query.Lazily(onEval)); }
/// <summary> /// Convert the expression to a Lucene query /// </summary> public IDocumentQuery <TResult> ToDocumentQuery <TResult>(Expression expression) { var processor = GetQueryProviderProcessor <T>(); var result = (IDocumentQuery <TResult>)processor.GetDocumentQueryFor(expression); result.SetResultTransformer(ResultTransformer); var renamedFields = FieldsToFetch.Select(field => { var renamedField = FieldsToRename.FirstOrDefault(x => x.OriginalField == field); if (renamedField != null) { return(renamedField.NewField ?? field); } return(field); }).ToArray(); if (renamedFields.Length > 0) { result.AfterStreamExecuted(processor.RenameSingleResult); } return(result); }