Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
replace google search with elasticsearch
Browse files Browse the repository at this point in the history
  • Loading branch information
cavvia committed Feb 6, 2017
1 parent b380feb commit 4c8d9ee
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 327 deletions.
2 changes: 0 additions & 2 deletions .env.oss
Expand Up @@ -15,7 +15,5 @@ FACEBOOK_APP_ID=FAKE123123123
FACEBOOK_APP_SECRET=FAKE123123123
TWITTER_CONSUMER_KEY=FAKE123123123
TWITTER_CONSUMER_SECRET=FAKE123123123
GOOGLE_SEARCH_KEY=FAKE123123123
GOOGLE_SEARCH_CX=FAKE123123123
EMBEDLY_KEY=FAKE123123123
SEGMENT_WRITE_KEY=FAKE123123123
23 changes: 16 additions & 7 deletions apps/search/routes.coffee
@@ -1,4 +1,4 @@
GoogleSearchResults = require '../../collections/google_search_results'
SearchResults = require '../../collections/search_results'
removeDiacritics = require('diacritics').remove

module.exports.index = (req, res, next) ->
Expand All @@ -7,14 +7,23 @@ module.exports.index = (req, res, next) ->
term = removeDiacritics req.query.term
res.locals.sd.term = term

results = new GoogleSearchResults
results = new SearchResults
indexes = ['Artwork', 'Artist', 'Article', 'Fair', 'Tag', 'Gene', 'Feature', 'Profile', 'PartnerShow', 'Sale']
data = { term: term, size: 10 }
data['indexes[]'] = indexes

results.fetch(data: q: term)
.then ->
results.fetch
data: data
cache: true
cacheTime: 60
success: (results, response, options) ->
res.locals.sd.RESULTS = results.toJSON()
res.render 'template',
mainHeaderSearchBoxValue: term
referrer: req.query.referrer
results: results.moveMatchResultsToTop(term)
.catch next
.done()
results: results.models
error: ->
res.render 'template',
mainHeaderSearchBoxValue: term
referrer: req.query.referrer
results: []
22 changes: 10 additions & 12 deletions apps/search/test/template.coffee
Expand Up @@ -5,8 +5,8 @@ path = require 'path'
fs = require 'fs'
Backbone = require 'backbone'
{ fabricate } = require 'antigravity'
SearchResults = require '../../../collections/google_search_results'
SearchResult = require '../../../models/google_search_result'
SearchResults = require '../../../collections/search_results'
SearchResult = require '../../../models/search_result'
sinon = require 'sinon'

{ resolve } = require 'path'
Expand Down Expand Up @@ -44,21 +44,19 @@ describe 'Search results template', ->
beforeEach (done) ->
@artworks = _.times 2, (i)->
new SearchResult({
link: 'https://artsy.net/artwork/cool-artwork' + i
title: "Artwork Title | Artist | Artsy"
snippet: 'cool artwork snippet'
pagemap:
metatags: [{'og:type': 'artwork', 'og:description': 'artwork description'}]
cse_thumbnail: [{ src: 'imgurl' }]
model: 'artwork',
display_model: 'Artwork',
id: 'cool-artwork' + i,
image_url: 'foo.jpg'
})
@artists = _.times 3, (i) ->
new SearchResult({
link: 'https://artsy.net/artist/cool-artist' + i
title: "Artist Name | Artsy"
snippet: 'cool artist snippet'
pagemap:
metatags: [{'og:type': 'artist', 'og:description': 'artist description'}]
cse_thumbnail: [{ src: 'imgurl' }]
model: 'artist',
display_model: 'Artist',
id: 'cool-artist' + i,
image_url: 'bar.jpg'
})

@search.add @artworks
Expand Down
25 changes: 0 additions & 25 deletions collections/google_search_results.coffee

This file was deleted.

20 changes: 5 additions & 15 deletions components/search_results/test/template.coffee
Expand Up @@ -2,23 +2,14 @@ fs = require 'fs'
jade = require 'jade'
path = require 'path'
fixtures = require '../../../test/helpers/fixtures'
GooogleSearchResult = require '../../../models/google_search_result'
SearchResult = require '../../../models/search_result'

describe 'result.jade', ->

before ->
@fixture = {
kind: 'customsearch#result',
title: 'The Friendship and Flight of Andy Warhol, Philip Pearlstein, and ...',
htmlTitle: 'The Friendship and Flight of <b>Andy Warhol</b>, Philip Pearlstein, and <b>...</b>',
link: 'https://www.artsy.net/article/artsy-editorial-from-pittsburgh-to-promise-the-friendship-and-flight',
displayLink: 'www.artsy.net',
snippet: '',
cacheId: '8b2RC8ZkxYUJ',
formattedUrl: 'https://www.artsy.net/.../artsy-editorial-from-pittsburgh-to-promise-the- friendship-and-flight',
htmlFormattedUrl: 'https://www.artsy.net/.../artsy-editorial-from-pittsburgh-to-promise-the- friendship-and-flight',
pagemap: { },
ogType: 'article',
model: 'article',
display_model: 'Article',
display: 'The Friendship and Flight of Andy Warhol, Philip Pearlstein, and ...',
image_url: 'https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSlZL9Q-fcFKGOvBsHCfxI6JpcJr5-hUMACOlhD-1j2l-rOahjx-ZUKmAg',
display_model: 'article',
Expand All @@ -28,8 +19,7 @@ describe 'result.jade', ->
filename = path.resolve __dirname, "../result.jade"
@render = jade.compile(fs.readFileSync(filename), { filename: filename })


it 'doesnt allow unsafe xss-ey html', ->
@fixture.about = '<script>alert(1)</script>'
@render(result: new GooogleSearchResult @fixture).should.not
.containEql '<script>'
html = @render(result: new SearchResult @fixture)
html.should.not.containEql '<script>'
2 changes: 0 additions & 2 deletions config.coffee
Expand Up @@ -33,8 +33,6 @@ module.exports =
TWITTER_CONSUMER_SECRET: null
OPENREDIS_URL: null
MAX_SOCKETS: -1
GOOGLE_SEARCH_KEY: null
GOOGLE_SEARCH_CX: null
SECURE_IMAGES_URL: 'https://d1ycxz9plii3tb.cloudfront.net'
EMBEDLY_KEY: null
EDITORIAL_ADMINS: 'craig,halley,marina,casey,molly,cab,charles'
Expand Down
5 changes: 2 additions & 3 deletions models/fair_location.coffee
Expand Up @@ -2,10 +2,9 @@ _ = require 'underscore'
sd = require('sharify').data
Backbone = require 'backbone'
Relations = require './mixins/relations/location.coffee'
Location = require './location.coffee'

module.exports = class FairLocation extends Backbone.Model

_.extend @prototype, Relations
module.exports = class FairLocation extends Location

singleLine: ->
@get 'display'
Expand Down
92 changes: 0 additions & 92 deletions models/google_search_result.coffee

This file was deleted.

9 changes: 9 additions & 0 deletions models/location.coffee
Expand Up @@ -12,3 +12,12 @@ module.exports = class Location extends Backbone.Model
@get 'state' || ''
@get 'country' || ''
]).join(', ')

singleLine: ->
_.compact([
@get 'city' or ''
_.compact([
@get 'address' or ''
@get 'address_2' or ''
]).join(' ')
]).join(', ')
4 changes: 2 additions & 2 deletions models/partner_location.coffee
Expand Up @@ -4,11 +4,11 @@ querystring = require 'querystring'
Backbone = require 'backbone'
{ Markdown } = require 'artsy-backbone-mixins'
Relations = require './mixins/relations/location.coffee'
Location = require './location.coffee'

module.exports = class PartnerLocation extends Backbone.Model
module.exports = class PartnerLocation extends Location

_.extend @prototype, Markdown
_.extend @prototype, Relations

fullAddress: ->
lines = [
Expand Down

0 comments on commit 4c8d9ee

Please sign in to comment.