A command line book search tool written in Java that uses an inverted index to search book content and return results ordered by user ratings
- Builds an inverted index from a directory of plain text book files
- Supports queries with multiple terms and case-insensitive matching
- Returns results ordered by average rating and rating count through the Book comparison logic
- Allows users to add ratings through an interactive command line interface
- Includes JUnit tests for rating logic, average rating, index construction, and term handling
Book files are stored in the books directory. Each file contains a title line, an author line, and the remaining content of the book.
On startup, the search engine:
- Loads all book files from the directory
- Creates Book objects implementing the Media interface
- Builds an inverted index mapping each normalized term to the books that contain it
- Seeds each book with random ratings so results can be ranked
Users interact through a simple command line interface that allows searching for terms or adding ratings to books.
Results are sorted based on average rating, number of ratings, and title.
- Media – interface representing media with title, creators, content, and rating-related methods
- Book – implementation of Media; stores tokens, tracks ratings, and defines ordering through Comparable
- SearchClient – main command line program; loads books, builds the inverted index, and processes user commands
- InvertedIndex – helper for constructing the mapping from tokens to the set of books containing them
- QueryCracker – novelty class unrelated to search logic, used to “unlock” results
- Testing – JUnit tests verifying correctness of Book behavior and index creation
To run the project:
- Clone the repository
- Ensure Java is installed
- Compile the Java files
- Run the SearchClient class
- Use the interactive prompt to search or rate books
The program reads all book files, builds the inverted index, and displays search results ordered by rating
- The JUnit tests validate:
- Book object construction
- Rating count and average rating calculations
- Correct handling of tokens
- Correct mapping of terms to books in the inverted index
These tests help ensure the stability and accuracy of the search engine