anchor.diff:      
       [<Sealed>]
       type Service(analyzerService, store) = 
  -        let state = create (analyzerService, store)
  +        let state = State.create (analyzerService, store)
           do state |> loadAllIndex
           interface IIndexService with
               member __.GetIndex(indexName) = state |> getIndex (indexName)
  
positive.code:             member __.GetRealtimeSearcher(indexName, shardNo) = 
                  maybe { let! _ = state |> getIndexState indexName
                          return (state.IndexWriters.[indexName] |> IndexWriter.getRealTimeSearcher shardNo) }
  
negative.code: // ----------------------------------------------------------------------------
  namespace FlexSearch.Core
  
  open System
  open System.Collections.Concurrent
  open System.IO
  open System.Linq
  open System.Threading.Tasks
  open FlexLucene.Analysis
  
  module State = 
      /// Default state to be used by items in the 
      type ItemState = 
          | Active = 0
          | Inactive = 1
      
      /// Factory used for index creation
      type IndexFactory = LazyFactory.T<IndexWriter.T, Index.T, IndexState>
      
      let getIndexFactory (store) = LazyFactory.create<IndexWriter.T, Index.T, IndexState> None store
      
      /// Factory used for analyzer creation
      type AnalyzerFactory = LazyFactory.T<Analyzer, Analyzer.T, ItemState>
      
      let getAnalyzerFactory (store) = LazyFactory.create<Analyzer, Analyzer.T, ItemState> (Some(Analyzer.build)) store
      
      /// Represents the node state. All the state related data should be part 
      /// of this.
      type T = 
          { IndexFactory : IndexFactory
            AnalyzerFactory : AnalyzerFactory
            Store : LazyFactory.Store }
      
      /// Create a new node state
      let create (inMemory) = 
          let store = new LazyFactory.Store(inMemory)
          { IndexFactory = getIndexFactory store
            AnalyzerFactory = getAnalyzerFactory store
            Store = store }
      
      /// Returns IndexNotFound error
      let indexNotFound (indexName) = IndexNotFound <| indexName
      
      /// Check if a given index exists
      let indexExists (indexName) (state : T) = state.IndexFactory |> LazyFactory.exists indexName indexNotFound
  
  module IndexService = 
      /// Returns IndexNotFound error
      let indexNotFound (indexName) = IndexNotFound <| indexName
      
      /// Load a index
      let loadIndex (index : Index.T) (state : State.T) = 
          maybe { 
              let setting = IndexWriter.createIndexSetting (index, state.AnalyzerFactory)
              if Args.getBool index.Online then 
                  do! state.IndexFactory |> LazyFactory.updateState (index.IndexName, IndexState.Opening)
                  do! state.IndexFactory |> LazyFactory.updateInstance (index.IndexName, IndexWriter.create (setting))
              else do! state.IndexFactory |> LazyFactory.updateState (index.IndexName, IndexState.Offline)
          }
      
      let openIndex (indexName) (state : State.T) = 
          maybe { 
              let! item = state.IndexFactory |> LazyFactory.getItemOrError indexName indexNotFound
              let updatedIndex = { item.MetaData with Online = Nullable(true) }
              state.Store.UpdateItem(indexName, updatedIndex)
              let setting = IndexWriter.createIndexSetting (updatedIndex, state.AnalyzerFactory)
              do! state |> loadIndex updatedIndex
          }
      
      let closeIndex (indexName) (state : State.T) = 
          maybe { 
              let! item = state.IndexFactory |> LazyFactory.getItemOrError indexName indexNotFound
              let updatedIndex = { item.MetaData with Online = Nullable(false) }
              state.Store.UpdateItem(indexName, updatedIndex)
              item.Value.Value |> IndexWriter.close
              do! state.IndexFactory |> LazyFactory.updateState (indexName, IndexState.Offline)
          }
      
      /// Load all index from the store
      let loadAllIndex (state : State.T) = 
          state.Store.GetItems<Index.T>()
          |> Seq.map (fun i -> new Task(fun _ -> loadIndex i state |> ignore))
          |> Seq.toArray
          |> Task.WaitAll
      
      /// Add a new index
      let addIndex (index : Index.T) (state : State.T) = 
          maybe { 
              do! (index :> IValidate).Validate()
              do! state |> State.indexExists index.IndexName
              do! state |> loadIndex index
              return CreateResponse(index.IndexName)
          }
      
      /// Get index by name
      let getIndex (indexName) (state : State.T) = state.Store.GetItem(indexName)
      
      /// Get all available index
      let getAllIndices (state : State.T) = state.Store.GetItems<Index.T>().ToArray()
      
      /// Delete an existing index    
      let deleteIndex (indexName) (s : State.T) = 
          IndexWriter.close (s.IndexWriters.[indexName])
          let info = s.IndexWriters.[indexName]
          s.Store.DeleteItem(indexName)
  