Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete for search #51

Merged
merged 20 commits into from
Oct 5, 2019
Merged

Autocomplete for search #51

merged 20 commits into from
Oct 5, 2019

Conversation

afischer
Copy link
Member

@afischer afischer commented Jul 28, 2019

Description of Change

Adds typeahead autocomplete to Library search using Twitter's typeahead.js.
typeahead-demo
This introduces a new external dependency, but it is being served from CDNJS just as jQuery is. The script tag can probably be moved to the footer, but since it will basically always be served from cache I've left it in the head for now.

Things to discuss

There are a few things that could use some work/discussion here...

Cache methodology

As the PR stands, the /filename-listing.json endpoint is hit on page load, which will either 304 or return an updated listing (similar to the whoami endpoint). This will then be stored in the browser's localStorage. This ensures users will always have the most up to date file listing.

This will introduce a large number of HEAD requests to the server, which may or may not be an issue. This could be mitigated somewhat by including a relatively short max-age to the Cache-Control. Would be interested to hear from @isaacwhite and others.

Another solution I explored was checking the timestamp of the localStorage payload and only requesting the resource if it was older than some period. This completely eliminates the request.

Design!

A design/UX pass on the typeahead CSS and functionality would be appreciated!

One thing I've considered is sending the user directly to the article page if they select a suggestion in the menu, as (in theory) it will only correspond to one document. That could get messy with filenames that are named a prefix of another document name, though.

Search functionality

Currently, the search just returns a list of substring-matched filenames. Typeahead.js allows for pretty significant customization with regards to how searching works. We could do fuzzy searching, match against lists of frequently misspelled words/synonyms, etc. We could also make the search function customizable via the current customization architecture if we wanted...

This is all probably out of scope for this PR, though.

Related Issue

Closes #6 by @maxine, though there should definitely be another isue created for the search being too picky about string matching... "night" should definitely return "knight" in the results.

Motivation and Context

As outlined in the original issue, this should make it easier to search large

Checklist

  • Ran npm run lint and updated code style accordingly
  • npm run test passes
  • PR has a description and all contributors/stakeholder are noted/cc'ed
  • tests are updated and/or added to cover new code
  • relevant documentation is changed and/or added

@afischer afischer requested a review from isaacwhite July 28, 2019 18:31
layouts/partials/footer.ejs Outdated Show resolved Hide resolved
Copy link
Member

@isaacwhite isaacwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, @afischer. At a high level, I'm curious if we could serve the files listing similar to the tree data in memory rather than the HTML/redirect caching layer. What do you think?

@@ -16,6 +16,7 @@

<p class="help-text"><%- template('footer.helpText') %></p>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/typeahead.js/0.11.1/typeahead.jquery.min.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all the other Library scripts are in the head (and we just haven't audited this in a while). I know it's beyond the scope of this particular change, but I think it would be worthwhile for us to be consistent about where scripts are included. This script seems like it is closer to the right place than the existing ones. What do you think about moving the other includes so they can all be together? My hunch is that this wouldn't break anything but would be curious to see what you find.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah — I initially had it in the head but since it's technically not necessary for the page to paint I wanted to make sure it wasn't blocking. That said, CDNJS has extremely aggressive caching, so I wouldn't be too worried about putting it back

layouts/partials/footer.ejs Outdated Show resolved Hide resolved
server/routes/pages.js Outdated Show resolved Hide resolved
server/list.js Outdated Show resolved Hide resolved
Copy link
Member

@isaacwhite isaacwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @afischer! This looks great, just two minor questions I'm curious to get your thoughts on.

public/scripts/main.js Outdated Show resolved Hide resolved
server/list.js Outdated Show resolved Hide resolved
@isaacwhite isaacwhite merged commit 51e8e21 into nytimes:master Oct 5, 2019
@isaacwhite isaacwhite mentioned this pull request Oct 7, 2019
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add autocomplete for search
2 participants