I have a class named TextFile
with a Title
and Body
which are both strings.
In my application I want the end user to be able to perform searches on these files.
I want to create my algorithm that first the files with the search term in the title are ordered first, followed by the files that have the search term in the body.
Example Search term: 'Farmer'
File 1:
Title: 'Farmers in Europe'
Body: contains 'Farmer' 50 times
File 2:
Title: 'Vegetable land'
Body: contains 'Farmer' 10 times
File 3:
Title: 'Farmers in the world'
Body: contains 'Farmer' 10 times
The result would be (ordered by amount descending):
- File 1
- File 3
- File 2
My question: how do I start ordering when files have the search term in the title the exact amount of times (see file 1 and file 3) ?
How would I order by Title first and then by the amount of occurrences in the body?