This is a simple test of an Autocomplete web service for Emapta-Zesty.io. The purpose is to return a list of Shakespeare's works based on the fragment that the user will provide or input. In this case, we will be using a query to simulate user's input. Shakespeare's works' list will be extracted from a JSON file. Each item on the JSON file contains only 2 itemms.
{
"Title": "Title of the work",
"ReadCount": 0
}
The result is based on how frequent the user has accessed an item which is the ReadCount
. If more than 1 item have equal frequency, the service will then lookup for the closest Title
from the fragment provided. If still more than 1 item are equal, result will now be based alphabetically. Moreover, result is limited to 25 results only. This limit can be adjusted by modifying the constant value of the resultLimit
inside main.go file.
Feel free to edit the JSON file. Update each ReadCount
values to your likings. I already updated a couple of ReadCount
values for Twelfth Night (4)
and Two Gentlemen of Verona(3)
so results will more likely to show these two Titles
. The rest are valued 0
.
You can also update the threshold for determining the amount of levenshtein distance by modifying the multiplier value of thresholdMultiplier
inside main.go.
- Open a new window of VSCode.
- Drag the folder 'autocomplete-test' to the newly opened VSCode window.
- Open a new terminal (Testminal->New Terminal) or press Ctrl+Shift-`
- Type
go run main.go
and hit Enter. If no errors, server is already running. - Copy and paste this URL to any browser: http://localhost:9000/autocomplete?term=th
- Make sure Docker is running.
- Make sure that the DockerFile file is included in the files.
- In the terminal, type and run
docker build -t <NameYourImage> .
. - Then type
docker run -p 9000:9000 -tid <NameYourImage>
. - Copy and paste this URL to any browser: http://localhost:9000/autocomplete?term=th
- There are 2 files included, main.exe and main, for Windows and Linux respectively.
- Make sure those files are in the root directory where the main.go resides.
- Simply run the main.exe file. A console window will open.
- Copy and paste this URL to any browser: http://localhost:9000/autocomplete?term=th
- Note that, I wasn't able to test this on a linux machine. Only on a linux docker image.
- Make sure the server is running.
- Type in
curl http://localhost:9000/autocomplete?term=th
in a terminal window and hit Enter.
These are the results based on the test run that I did on my end:
Twelfth Night
Two Gentlemen of Verona
Taming of the Shrew
Tempest
Timon of Athens
Titus Andronicus
Troilus and Cressida
Troilus and Cressida
King John
King Lear
Midsummer Night's Dream
Pericles
Richard II
Richard III
Timon of Athens
Titus Andronicus
Winter's Tale
None
Julius Caesar
Much Ado about Nothing
Winter's Tale
All's Well That Ends Well
Antony and Cleopatra
As You Like It
Troilus and Cressida
All's Well That Ends Well
Henry IV, Part I
Henry IV, Part II
Henry V
Henry VI, Part I
Henry VI, Part II
Henry VI, Part III
Henry VIII
Measure for Measure
Merchant of Venice
Merry Wives of Windsor
Pericles
Tempest
Henry IV, Part I
Henry IV, Part II
Henry V
Henry VI, Part I
Henry VI, Part II
Henry VI, Part III
Henry VIII
Measure for Measure
Merchant of Venice
Merry Wives of Windsor
Pericles
Tempest
All's Well That Ends Well
Pericles