HI Ravneet,
The requirement is quite simple.
In the search event handler, you have the logic to create Dynamic query, pass selection parameters & then execute the query.
You would have to just check as a pre-condition if the Role is provided by reading the entity & then if there is no Role provided, add selection parameters Role as Ship-to and sold-to.
If the role is provided then follow the standard path.
Thanks,
Ravi