Skip to content

Instantly share code, notes, and snippets.

@emanualjade
Last active August 22, 2018 23:39
Show Gist options
  • Save emanualjade/5b148c03f5274f9821ca5a0c8ea1e815 to your computer and use it in GitHub Desktop.
Save emanualjade/5b148c03f5274f9821ca5a0c8ea1e815 to your computer and use it in GitHub Desktop.
SearchConcept
// CLIENT SIDE
// search terms will look like
// www.apifini.com, apifini.com, dev.apifini.com, www.dev.apifini.com etc
// First search on host
const host = window.location.host
// If the host search has no results we can do a full url search on the social fields
const fullUrlWithoutParamsOrHash = window.location.origin + window.location+pathname
// passing multiple terms is just a concept. We could just pass the URL and let all the splitting etc be handled on the server
const searchTermsComingFromClientSide = {host, fullUrlWithoutParamsOrHash}
// SERVER SIDE
// return 0, 1, or many results depending on what we find
// Client side will handle displaying 0,1,many
// Our goal is to make chrome extension context aware so returning a single good result is what we're aiming for
// Search should behave as follows
// =======
// SearchTerm: apfini.com
// DB: www.apifini.com || dev.apifini.com
// MATCH
// =======
// * In the future I can see domains coming from agencies like myIcoName.agencyName.com
// * If we got just the agency name like agencyName.com we should return MANY
const searchResult = findIcoByWebsiteHost(searchTermsComingFromClientSide.host)
if(!searchResult) {
const hostParts = searchTermOneComingFromClientSide.host.split(".")
if(hostParts.length > 2) {
// Get less specific. strip www and any subdomains before searching again
const searchTermTwo = hostParts.slice(-2).join(".")
const result = findIcoByWebsiteHost(searchTermTwo)
if(!result){
// finally if cannot find by host lets check social URLs
findICOBySocialUrl(searchTermsComingFromClientSide.fullUrlWithoutParamsOrHash)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment