Skip to content

MicahParks/shakesearch

 
 

Repository files navigation

shakesearch

Go Report Card Go Reference

Test it yourself

This is deployed right now. Head over to https://shakesearch.micahparks.com or use the command line:

curl "https://shakesearch.micahparks.com/api/search?q=Porter&maxResults=2" | python3 -m json.tool

Output:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   165  100   165    0     0    283      0 --:--:-- --:--:-- --:--:--   282
[
    {
        "line": "PORTER.",
        "lineNumbers": [
            81739,
            81764,
            81771,
            81783
        ],
        "matchedIndexes": [
            0,
            1,
            2,
            3,
            4,
            5
        ]
    },
    {
        "line": "A PORTER",
        "lineNumbers": [
            50287
        ],
        "matchedIndexes": [
            2,
            3,
            4,
            5,
            6,
            7
        ]
    }
]

Screenshot

I kept most of the lovely frontend the same, but I fixed up the backend and added new features as instructed.

porterQuery.png

You can click on the hyperlink of the line number to jump to a snippet from Shakespeare's complete works. From there you can scroll up and down for a few hundred lines, but it's only a snippet. Transferring the entire document would take too long.

porterSnippet.png

New features

  • Swagger 2.0 specification file. This helps communicate API and data structures to other developers.
  • Line numbers link to snippets of the complete works.
    • This uses Go templating.
  • Fuzzy search the given query using fuzzy.
  • Rate limit requests with tollbooth.
  • Using a logger (zap).
  • Deployment assets: Dockerfile, docker-compose.yml, and Caddyfile.
  • Proper error handing.
  • Configurable hostname, port, and file location for Shakespeare's works in the file system.
  • Limit the number of results using query.
  • More data returned from search endpoint.
  • Endpoints moved to /api. Ex: /api/search.
  • Separation of frontend and backend code. (Using Caddy as a file server).
  • HTTPS (thanks to Let's Encrypt and Caddy).
  • No more panics when a query causes an impossible index. Ex. Search for something near the top or bottom of the file like Project.
  • Bold the text that matched the query.
  • Line number where the text came from.
  • Less whitespace in memory.

Configuration

Environment variable table:

Name Description Default Value Example Value
HOST The host to bind the service to. localhost 0.0.0.0
PORT The port to bind the service to. random 30000
SHAKESPEARES_WORKS The full or relative file path to a text file containing the complete works of Shakespeare. completeworks.txt /home/william/works.txt
SNIPPET_TEMPLATE The full or relative file path to the HTML template for a snippet of Shakespeare's works. snippet.gohtml customTempalte.gohtml

Generated code and directories explained

This project uses a swagger 2.0 API (swagger.yml) and the goswagger project. The swagger.yml file was used to generate the code in the cmd, models, and restapi directories. One file was edited at restapi/configure_shakesearch.go.

The other directories are not from the code generator. Both configure and endpoints contain hand written code and the static directory was given, except static/app.js was modified a bit to help show matching results with bold text.

About

The Pulley ShakeSearch Take-home Challenge

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 64.7%
  • CSS 23.0%
  • JavaScript 7.2%
  • Dockerfile 2.8%
  • HTML 2.3%