You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: search.rs
    path of file: ./repos/sway/forc-plugins/forc-doc/src
    
    the code of the file until where you have to start completion: use crate::doc::{Document, Documentation};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::fs;
use std::{collections::HashMap, path::Path};

const JS_SEARCH_FILE_NAME: &str = "search.js";

/// Creates the search index javascript file for the search bar.
pub(crate) fn write_search_index(doc_path: &Path, docs: Documentation) -> Result<()> {
    let 
    
    fn to_json_value(&self) -> Result<serde_json::Value, serde_json::Error> {
        let mut map: HashMap<String, Vec<JsonSearchItem>> = HashMap::with_capacity(self.0.len());
        for doc in self.0.iter() {
            match map.get_mut(doc.module_info.project_name()) {
                Some(items) => {
                    items.push(JsonSearchItem::from(doc));
                }
                None => {
                    map.insert(
                        doc.module_info.project_name().to_string(),
                        vec![JsonSearchItem::from(doc)],
                    );
                }
            }
        }
        serde_json::to_value(map)
    }