pub async fn add_index(
        &self,
        index: IndexDeclaration,
        override_if_exists: bool,
    ) -> Result<()> {
        let mut indexes;
        {
            let guard = self.indexes.load();
            indexes = guard.as_ref().clone();
        }

        if !override_if_exists & indexes.get(index.name()).is_some() {
            return Err(Error::msg("index already exists."));
        }

        // remove the index if it exists
        self.remove_index(index.name()).await?;

        let ctx = index.create_context()?;
        let name = ctx.name();
        let built_index = Index::create(ctx).await?;

        indexes.insert(name, built_index);
        self.indexes.store(Arc::new(indexes));

        {
            self.declarations
                .lock()
                .insert(index.name().to_string(), index);
        }

        Ok(())
    }
/// Adds an index to the index from a given declaration.
///
/// This duplicates the current indexes and swaps the clone, in general
/// this is a very heavy operation and shouldn't be ran often / arbitrarily.
Adds an index to the index from a given declaration.
This duplicates the current indexes and swaps the clone, in general
this is a very heavy operation and shouldn't be ran often / arbitrarily.
Adds an index to the index from a given declaration . This duplicates the current indexes and swaps the clone in general this is a very heavy operation and shouldn ' t be ran often / arbitrarily .
pub async fn add_index(
        &self,
        index: IndexDeclaration,
        override_if_exists: bool,
    ) -> Result<()> {
        let mut indexes;
        {
            let guard = self.indexes.load();
            indexes = guard.as_ref().clone();
        }
        if !override_if_exists & indexes.get(index.name()).is_some() {
            return Err(Error::msg("index already exists."));
        }
        // remove the index if it exists
        self.remove_index(index.name()).await?;
        let ctx = index.create_context()?;
        let name = ctx.name();
        let built_index = Index::create(ctx).await?;
        indexes.insert(name, built_index);
        self.indexes.store(Arc::new(indexes));
        {
            self.declarations
                .lock()
                .insert(index.name().to_string(), index);
        }
        Ok(())
    }
pub async fn add_index ( & self , index : IndexDeclaration , override_if_exists : bool , ) -> Result < ( ) > { let mut indexes ; { let guard = self . indexes . load ( ) ; indexes = guard . as_ref ( ) . clone ( ) ; } if ! override_if_exists & indexes . get ( index . name ( ) ) . is_some ( ) { return Err ( Error :: msg ( " " ) ) ; } // remove the index if it exists self . remove_index ( index . name ( ) ) . await ? ; let ctx = index . create_context ( ) ? ; let name = ctx . name ( ) ; let built_index = Index :: create ( ctx ) . await ? ; indexes . insert ( name , built_index ) ; self . indexes . store ( Arc :: new ( indexes ) ) ; { self . declarations . lock ( ) . insert ( index . name ( ) . to_string ( ) , index ) ; } Ok ( ( ) ) }
Adds an index to the index from a given declaration.
Adds an index to the index from a given declaration .
&self
index
IndexDeclaration
override_if_exists
bool
&self
index
IndexDeclaration
override_if_exists
bool