private void updateSearchFunction(CouchDbConnector db, DesignDocument doc, String searchFunctionName,
                                      String javascript, long jsChecksum) {

        // get the 'fulltext' object from the design document, this is what couchdb-lucene uses to index couch
        Map<String, Map<String, String>> fullText = (Map<String, Map<String, String>>) doc.getAnonymous().get("fulltext");
        if (fullText == null) {
            fullText = new HashMap<String, Map<String, String>>();
            doc.setAnonymous("fulltext", fullText);
        }
        // now grab the search function that the user wants to use to index couch
        Map<String, String> searchObject = fullText.get(searchFunctionName);
        if (searchObject == null) {
            searchObject = new HashMap<String, String>();
            fullText.put(searchFunctionName, searchObject);
        }

        // now set the contents of the index function
        searchObject.put("index", javascript);
        // now set the checksum, so that we can make sure that we only update it when we need to
        doc.setAnonymous(getChecksumFieldName(searchFunctionName), jsChecksum);

        // save out the document
        db.update(doc);

    }
private void updateSearchFunction ( CouchDbConnector db , DesignDocument doc , String searchFunctionName , String javascript , long jsChecksum ) { Map < String , Map < String , String > > fullText = ( Map < String , Map < String , String > > ) doc . getAnonymous ( ) . get ( "fulltext" ) ; if ( fullText == null ) { fullText = new HashMap < String , Map < String , String > > ( ) ; doc . setAnonymous ( "fulltext" , fullText ) ; } Map < String , String > searchObject = fullText . get ( searchFunctionName ) ; if ( searchObject == null ) { searchObject = new HashMap < String , String > ( ) ; fullText . put ( searchFunctionName , searchObject ) ; } searchObject . put ( "index" , javascript ) ; doc . setAnonymous ( getChecksumFieldName ( searchFunctionName ) , jsChecksum ) ; db . update ( doc ) ; }
Creates the design document that we use when searching.  This contains the index function that is used by lucene
in the future we will probably want to support customer specific instances, as well as adding a checksum
to the object, so that we can test if an index needs to be upgraded

@param db                 Couch connection
@param doc                The design document that we're updating
@param searchFunctionName The name of the search function that the user wants to index couch with
@param javascript         The body of the javascript of the search function
@param jsChecksum         The checksum of the search function body