anchor.diff:  
   /// Index related operations
   type IIndexService = 
  -    abstract GetIndex : string -> Choice<Index.Dto, Error>
  -    abstract UpdateIndex : Index.Dto -> Choice<unit, Error>
  -    abstract DeleteIndex : string -> Choice<unit, Error>
  -    abstract AddIndex : Index.Dto -> Choice<CreateResponse, Error>
  +    abstract GetIndex : indexName:string -> Choice<Index.Dto, Error>
  +    abstract UpdateIndexFields : fields:Field.Dto [] -> Choice<unit, Error>
  +    abstract DeleteIndex : indexName:string -> Choice<unit, Error>
  +    abstract AddIndex : index:Index.Dto -> Choice<CreateResponse, Error>
       abstract GetAllIndex : unit -> Index.Dto array
  -    abstract IndexExists : string -> bool
  -    abstract IndexOnline : string -> bool
  -    abstract GetIndexStatus : string -> Choice<IndexState, Error>
  -    abstract OpenIndex : string -> Choice<unit, Error>
  -    abstract CloseIndex : string -> Choice<unit, Error>
  -    abstract Commit : string -> Choice<unit, Error>
  -    abstract Refresh : string -> Choice<unit, Error>
  -    abstract GetRealtimeSearchers : string -> Choice<array<RealTimeSearcher>, Error>
  -    abstract GetRealtimeSearcher : string * int -> Choice<RealTimeSearcher, Error>
  +    abstract IndexExists : indexName:string -> bool
  +    abstract IndexOnline : indexName:string -> bool
  +    abstract IsIndexOnline : indexName:string -> Choice<IndexWriter.T, Error>
  +    abstract GetIndexState : indexName:string -> Choice<IndexState, Error>
  +    abstract OpenIndex : indexName:string -> Choice<unit, Error>
  +    abstract CloseIndex : indexName:string -> Choice<unit, Error>
  +    abstract Commit : indexName:string -> Choice<unit, Error>
  +    abstract Refresh : indexName:string -> Choice<unit, Error>
  +    abstract GetRealtimeSearchers : indexName:string -> Choice<array<RealTimeSearcher>, Error>
  +    abstract GetRealtimeSearcher : indexName:string * int -> Choice<RealTimeSearcher, Error>
   
   /// Document related operations
   type IDocumentService = 
  
positive.code:                             (writers.Settings.FieldsLookup, predicate, searchQuery, searchProfile, queryTypes)
          }
      
      let search (searchQuery : SearchQuery.Dto, queryTypes) (state : State.T) = 
          maybe { 
              let! (index, state, writers) = state.IndexFactory 
                                             |> LazyFactory.getAsTuple searchQuery.IndexName IndexService.indexNotFound
              let! query = generateSearchQuery (writers, searchQuery, None, queryTypes)
              let! (results, recordsReturned, totalAvailable) = SearchDsl.searchDocumentSeq (writers, query, searchQuery)
              let searchResults = new SearchResults()
  
negative.code:             return! Choice1Of2(searchResults)
          }
      
      // Generate query types from query factory. This is necessary as a single query can support multiple
      // query names
      let queryTypes = 
          let result = new Dictionary<string, IFlexQuery>(StringComparer.OrdinalIgnoreCase)
          for pair in queryFactory.GetAllModules() do
              for queryName in pair.Value.QueryName() do
                  result.Add(queryName, pair.Value)
          result
      
      interface ISearchService with
          member __.Search(query) = search (query, queryTypes)
          member __.SearchAsDocmentSeq(searchQuery) = 
              maybe { let! writers = indexService.IsIndexOnline <| searchQuery.IndexName
                      let! query = generateSearchQuery (writers, searchQuery, None, queryTypes)
                      return! SearchDsl.searchDocumentSeq (writers, query, searchQuery) }
          member __.SearchAsDictionarySeq(searchQuery : SearchQuery.Dto) = 
              maybe { let! writers = indexService.IsIndexOnline <| searchQuery.IndexName
                      let! query = generateSearchQuery (writers, searchQuery, None, queryTypes)
                      return! SearchDsl.searchDictionarySeq (writers, query, searchQuery) }
          member __.SearchUsingProfile(searchQuery : SearchQuery.Dto, inputFields : Dictionary<string, string>) = 
              maybe { 
                  let! writers = indexService.IsIndexOnline <| searchQuery.IndexName
                  let! query = generateSearchQuery (writers, searchQuery, Some(inputFields), queryTypes)
                  let! (results, recordsReturned, totalAvailable) = SearchDsl.searchDocumentSeq 
                                                                        (writers, query, searchQuery)
                  let searchResults = new SearchResults()
                  searchResults.Documents <- results.ToList()
                  searchResults.TotalAvailable <- totalAvailable
                  searchResults.RecordsReturned <- recordsReturned
                  return! Choice1Of2(searchResults)
              }
  
  [<Sealed>]
  type DocumentService(searchService : ISearchService, indexService : IIndexService) = 
      interface IDocumentService with
          
          /// Returns the total number of documents present in the index
          member __.TotalDocumentCount(indexName : string) = maybe { let! writer = indexService.IsIndexOnline <| indexName
                                                                     return writer |> IndexWriter.getDocumentCount }
          
          /// Get a document by Id        
          member __.GetDocument(indexName, documentId) = 
              maybe { 
                  let q = new SearchQuery.Dto(indexName, (sprintf "%s = '%s'" Constants.IdField documentId))
                  q.ReturnScore <- false
                  q.ReturnFlatResult <- false
                  q.Columns <- [| "*" |]
                  match searchService.Search(q) with
                  | Choice1Of2(v') -> 
                      if v'.Documents.Count <> 0 then return! Choice1Of2(v'.Documents.First())
                      else return! fail <| DocumentIdNotFound(indexName, documentId)
                  | Choice2Of2(e) -> return! Choice2Of2(e)
              }
          
          /// Get top 10 document from the index
          member __.GetDocuments(indexName, count) = 
              maybe { 
                  let q = new SearchQuery.Dto(indexName, (sprintf "%s matchall 'x'" Constants.IdField))
                  q.ReturnScore <- false
                  q.ReturnFlatResult <- false
                  q.Columns <- [| "*" |]
                  q.Count <- count
                  q.MissingValueConfiguration.Add(Constants.IdField, MissingValueOption.Ignore)
                  return! searchService.Search(q)
              }
          
          /// Add or update an existing document
          member __.AddOrUpdateDocument(document) = 
              maybe { 
                  do! document.Validate()
                  let! indexWriter = indexService.IsIndexOnline <| document.IndexName
                  indexWriter |> IndexWriter.updateDocument document
              }
          
          /// Add a new document to the index
          member __.AddDocument(document) = 
              maybe { 
                  do! document.Validate()
                  if document.TimeStamp > 0L then 
                      return! fail 
                              <| IndexingVersionConflict(document.IndexName, document.Id, document.TimeStamp.ToString())
                  let! writer = indexService.IsIndexOnline <| document.IndexName
                  writer |> IndexWriter.addDocument document
                  return new CreateResponse(document.Id)
              }
          
          /// Delete a document by Id
          member __.DeleteDocument(indexName, documentId) = maybe { let! writer = indexService.IsIndexOnline <| indexName
                                                                    writer |> IndexWriter.deleteDocument documentId }
          
          /// Delete all the documents present in an index
          member __.DeleteAllDocuments indexName = maybe { let! writer = indexService.IsIndexOnline <| indexName
                                                           writer |> IndexWriter.deleteAllDocuments }
  