Customize Results of Global Search

The global search returns results with fields such as “Name”, “Date Created” and “Search Score”.
How do I remove a field (e.g. Name) from the global search results?

I believe Global search uses the module’s list view

Go to admin > studio > module name > Layouts > List View

If you want the fields to remain in the module list view but not the global search view I think custom coding would be required

Thanks Taufique for your kind reply.
I don’t think Global search uses the module’s list view.
Because the module’s list view has so many more fields that do not appear in the result of Global search.
Could other member in this forum second that custom coding is required?

i’ve just found out how to change the display layout of the Global Search (Unified Search).
I don’t know if this is the best way to do it (because it is NOT upgrade safe), but it works for now.

File to edit: suitecrm/modules/Home/UnifiedSearch.php

Here you can find the

that displays the search results. " ."" ."" //this is my custom field ."" ."" ."" ."" ."" .""; } }else{ echo ""; } ?>

Note that this change is not upgrade safe. If someone has an advice to make this upgrade safe or even a simpler method, please let me know.

tags are for the labels in the table header. You can display labels from other modules as well, for example I am showing the Account Name of the Leads Module:
        <th scope='col' width='10%' data-toggle="true">
				<span sugar="sugar1">
                    <div style='white-space: nowrap;'width='100%' align='left'>
                        <?php echo translate("LBL_ACCOUNT_NAME","Leads"); ?>
                    </div>
                </span sugar='sugar1'>
        </th>

Right under the

tags is the PHP-Code for the search results in the table. Always make sure that the number of the tags above match the tags here.
Now it gets a little complicated. First i tried to just duplicate a line and rename the variable to the field i want to output, but in my case that didnt work. So I copied the PHP function getRecordSummary(SugarBean $bean) { … } and altered the content, to get the Field i like to output.

The function for “Account Name” of the Leads Module now looks like that (i placed it right above the function getRecordSummary):

function getAccountName(SugarBean $bean){
    global $listViewDefs;
    if (!isset($listViewDefs) || !isset($listViewDefs[$bean->module_dir]) ){
        if(file_exists('custom/modules/'.$bean->module_dir.'/metadata/listviewdefs.php')){
            require('custom/modules/'.$bean->module_dir.'/metadata/listviewdefs.php');
        }else if(file_exists('modules/'.$bean->module_dir.'/metadata/listviewdefs.php')){
            require('modules/'.$bean->module_dir.'/metadata/listviewdefs.php');
        }
    }
    if ( !isset($listViewDefs) || !isset($listViewDefs[$bean->module_dir]) ){
        return $bean->get_summary_text();
    }
    
    foreach($listViewDefs[$bean->module_dir] as $key => $entry){
        $key = strtolower($key);
		if(in_array($key,array('account_name'))){ //change account_name to your field
			$account_name = $bean->$key;
			break;
		}
    }
    
    return $account_name;
}

As you can see, it’s nearly the same function as getRecordSummary, but i made the “if” to get only the field account_name out of the existing array. Then i created the variable $account_name, and returned it.

When you scroll down a bit, you can find a section, where the $newHit variables are created. I added mine like this:

            $newHit = new stdClass;
            $newHit->record_module = $hit->record_module;
            $newHit->record_id = $hit->record_id;
            $newHit->score = $hit->score;
            $newHit->label = getModuleLabel($bean->module_name);
            $newHit->name = $bean->get_summary_text();
            $newHit->summary = getRecordSummary($bean);
            $newHit->date_entered = $bean->date_entered;
            $newHit->date_modified = $bean->date_modified;
            $newHit->account = getAccountName($bean); //this is my custom added field
            $hits[] = $newHit;

Now back in the PHP-Code where the

tags for the results in the tables are generated, I added my field like this: <?php if($hits){ foreach($hits as $hit){ echo "
".$hit->label."".$hit->account."".$hit->name."".$hit->summary."".$hit->date_entered."".$hit->date_modified."".getScoreDisplay($hit)."
".translate("LBL_SEARCH_RESULT_EMPTY","AOD_Index")."

For any who is seeking an Enhanced way of searching, please have a look.

https://store.outrightcrm.com/product/enhanced-global-search/

Is it possible to add this module in Elastic Search?

Do you mean my extension “Faster global search” ?