code: public boolean updateSearchFunctionIfNecessary(CouchDbConnector db, String viewName, String searchFunction,
                                                     String javascriptIndexFunctionBody) {
  
          boolean updatePerformed = false;
  
          String designDocName = viewName.startsWith(DesignDocument.ID_PREFIX)
                  ? viewName : (DesignDocument.ID_PREFIX + viewName);
  
          Checksum chk = new CRC32();
          byte[] bytes = javascriptIndexFunctionBody.getBytes();
          chk.update(bytes, 0, bytes.length);
          long actualChk = chk.getValue();
  
          if (!db.contains(designDocName)) {
              // it doesn't exist, let's put one in
              DesignDocument doc = new DesignDocument(designDocName);
              db.create(doc);
              updateSearchFunction(db, doc, searchFunction, javascriptIndexFunctionBody, actualChk);
              updatePerformed = true;
          } else {
              // make sure it's up to date
              DesignDocument doc = db.get(DesignDocument.class, designDocName);
              Number docChk = (Number) doc.getAnonymous().get(getChecksumFieldName(searchFunction));
              if (docChk == null || !(docChk.longValue() == actualChk)) {
                  log.info("Updating the index function");
                  updateSearchFunction(db, doc, searchFunction, javascriptIndexFunctionBody, actualChk);
                  updatePerformed = true;
              }
          }
  
          return updatePerformed;
      }
docs: Ensures taht the given body of the index function matches that in the database, otherwise update it.
  
  @param db                          Connection to couchdb
  @param viewName                    Name of the view that we're updating
  @param searchFunction              Name of the search function, within that view
  @param javascriptIndexFunctionBody The body of the javascript for that search function
  @return whether or not the body of the document was updated.