You coud just do:
In SearchActivity
Intent i = new Intent(this, ActivityA.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
In ActivityA
Intent i = new Intent(this, SearchActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
which will take you back from B to Search and then to Main on two presses of the back button.
However
If you go from Main to Search to A to Search and then hit the back buttons, you would go from Search to Search to Main. (Two instances of search, probably not what you want)
It's better to set the flags in Activity A to be:
Intent i = new Intent(this, SearchActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
This will stop the above behaviour and still give you what you want when you hit back from B