Do you Know how search engine works?
 When user search anything on search engine (like Google, Bing etc.) the search string called "keyword". Do you think how the search engine show you the list of results at sudden?
here's the answer of your question:-
1) First search engine's crawler find the contents on the basis of your keyword from the large database from thousands of websites.

2) Then Search engine algorithms ranks the search contents on the basis of several factors like content relevancy,domain authority of website,on-site optimization,social media engagements of domain,quality factor of content etc.this process is called indexing. By the use of indexing process search engine decides the ranks of website this is called SERP(search engine result page).

3) In the last step search engine shows the results in the order which decides in indexing.

Search engine completely works on "content relevency". It always wants to show the result which user wants.