AllenYuan

searchengine - rank

Apr 26th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. # prompt the user with "Enter Search Term: " and collect their input
  2. searchterm = input('Enter Search Term: ')
  3.  
  4. # list of relevant search results
  5. matches = []
  6. # for each document, calculate its relevance to the search term
  7. for i in range(len(index)):
  8.     relation = v.relation(v.concordance(searchterm.lower()), index[i])
  9.     if relation != 0:
  10.         matches.append((relation, documents[i][:100]))
  11.  
  12. # sort matches in descending order (most relevant first)
  13. matches.sort(reverse=True)
  14.  
  15. for i in matches:
  16.     print (i[0],i[1])
Advertisement
Add Comment
Please, Sign In to add comment