One level up manager and one level down for subordinates in search results?

Update for Org Chart 4.

// Variable to distingush the drill-down from search and from chart
let drilledFromSearch = false;
//Variable to save the clicked person
let clickedPersonData;

// Function to expand the items for two levels based on condition
function expand(item) {
    api.showLoadingPanel();
    api.expandNodeLevelsConditionally(3,
        function (itemData) {
            // Check if the box contains the found person or the person's manager
            return itemData.AccountName == item.parentId || itemData.AccountName == item.id;
        },
        function () {
            api.hideLoadingPanel();
        });
}

// When the search result is clicked
api.searchResultClickedAction = function (itemId) {
    api.dataProvider.getBoxGroupItemDataById(itemId, function (item) {
        // The drill-down is from search
        drilledFromSearch = true;
        // Save the data of the clicked person
        clickedPersonData = item;
        // Drill down to the manager of the found person
        api.drillDown(item.parentId.split("|").pop());
    });
}

api.onDrilledDown(() => {
    // If the drill-down was from search
    if (drilledFromSearch) {
        // Execute the 'expand' function
        expand(clickedPersonData);
    }
    // Set the drill-down switcher to 'false'
    drilledFromSearch = false;
});