A simple search engine that uses simple Python data structures to store the data and search for it.
-
Install dependencies
pip install -r requirements.txt
-
Prepare the data The data should be free text and in the
datafolder. Every file in thedatafolder will be indexed as a document. -
Run the search engine
Open terminal, go to the root directory of the project and run:
export PYTHONPATH=$(pwd) python src/run.py
Open PowerShell, go to the root directory of the project and run:
$env:PYTHONPATH = (Get-Location) python src\run.py
-
Search for a query The search engine will ask you to enter a query. Enter the query and press enter. The search engine will return the top 5 results.
The search engine uses a few simple steps to search for a query:
- It reads the data from the
datafolder and stores it in a dictionary. - It preprocesses the data by removing stop words, punctuations, numbers and converting the text to lowercase.
- It reads stopwords from the
stopwords.txtfile, preprocesses the stopwords and stores them in a list. - It reads the query from the user and preprocesses it.
- It calculates the score of each document for the query and ranks them in descending order. The score is calculated by the number of times the document contains the query words.
- It returns the top 5 results.