Submission for Coding Challenge
-
To run this CLI application, you should have
Python 3.9
(latest) andpip
installed and configured to use.You can download it here:
-
git
for downloading code and version control.You can download it here:
- Clone and go into the root directory
git clone https://github.com/maoyalu/zen_cc_search.git
cd zen_cc_search
- Restore project requirements
# If you have both 2.x and 3.x installed
# you might need to use pip3 instead
pip install -r requirements.txt
- Run
# If you have both 2.x and 3.x installed
# you might need to use python3 instead
python -m zensearch
-
Configure cache settings.
zensearch/config.py
stores configs that enable reverse index. If it is set totrue
, additional spaces will be allocated for faster lookup, accelerating the search fromO(n)
toO(1)
.To make new configs effective, you need to restart the app.
-
Quit anytime.
Type
quit
into the prompt and hitENTER
anytime, ane then the program will request your confirmation for exit.Y
- ExitN
(default) - Cancel and go back to the main page -
Select options
Option list will be provided above the prompt.
Select the option number and hit
ENTER
. If the option number is invalid, an error message will be shown. -
Search for the value
Empty value is supported.
Simply hit
ENTER
without typing anything. -
Navigation
Main |----- Search | |----- Users | |----- Tickets | |----- View Searchable Fields
-
In order to approach O(1) time as much as possible, additional spaces are allocated. Searching generally will take O(n) time so perform lookups to prevent searching if possible.
This feature can be switched off or partially enabled depending on users' actual situation.
By defulat, this feature is enabled.
-
Users are comfortable using CLI, but they are not that technical so interactions are designed in a humanly way instead of using command argument options.
-
Memory is sufficient for storing all the data.
-
No value of 'quit' exist in the data, otherwise it will contradict with the requirement 'Exit anytime'.
-
Optional fields are observed from the json files provided.
Field Description _id * required
* unique
* intname * required
* stringcreated_at * required
* stringverified * optional
* boolean
* defaultFalse
Field Description _id * required
* unique
* stringcreated_at * required
* stringtype * optional
* string
* defaultNone
subject * required
* stringassignee_id * optional
* int
* defaultNone
tags * required
* list of string
Uses MVC structure to reduce coupling.
-
Model -
database.py
-
View -
cli.py
-
Controller -
__main__.py
-
Constants -
constants.py
,config.py
-
No changes to CLI required for changes of searchable fields.
You only need to update the enum in
constants.py
-
Easy to switch to use a database in the future.
You only need to update the implementation of
database.py
-
Use constants to prevent hardcoded string
-
Use date type instead of string for
created_at
It's ridiculous to use a date time format string to search.
And date type allows more flexible searches like date range and provides better support for multi-timezone.
-
Cache on demand
Another way to cache is storing them when they are searched along with an expiration time.
It can reduce startup time and memory used in runtime comparing to the current cache strategy.
This can be beneficial if the number of frequently searched items is very small.
-
Advanced search
Current version only implements searching with one single field.
Searches with a combination of fields generally take
O(n)
time.