You can learn more about how search engine software ranks web pages on the aptlynamed How Search Engines Rank Web Pages page. They follow a set of rules, with the main rules involving the location and frequency of keywords on a web page. Pages with keywords appearing in the title are assumed to be more relevant than others to the topic. Search engines will also check to see if the keywords appear near the top of a web page, such as in the headline or in the first few paragraphs of text. They assume that any page relevant to the topic will mention those word right from the beginning.
Frequency is the other major factor in how search engines determine relevancy.
A search engine will analyze how often keywords appear in relation to other words in a web page. Those with a higher frequency are often deemed more relevant than other web pages. To begin with, some search engines index more web pages than others. Some search engines also index web pages more often than others. The result is that no search engine has the exact same collection of web pages to search through.