Permalink
Browse files

permit search on multiple words

  • Loading branch information...
1 parent 62a3665 commit f15e64fd7c307b199c47a6d0a2152f3c29e2cf33 @Geal committed Mar 6, 2013
Showing with 12 additions and 3 deletions.
  1. +12 −3 js/search.js
View
@@ -20,15 +20,24 @@ window.onload = function() {
function search() {
$('#results').text('')
console.log(input.val())
- var searchWord = input.val().toLowerCase()
+ var searchWords = input.val().toLowerCase().split(" ")
+ console.log(searchWords)
$.ajax({
type: 'GET',
url: '/search.json',
dataType: 'json',
timeout: 2000,
success: function(data){
- console.log(data[searchWord])
- var indexes = data[searchWord]
+ var res = $.map(searchWords, function(word, index) {
+ return data[word]
+ }).sort()
+
+ for(var i = 1; i < res.length; i++) {
+ if(res[i] === res[i-1]) {
+ res.splice(i--, 1)
+ }
+ }
+ var indexes = res
var results = $('#results')
$.map(indexes, function(item, index) {
var url = urls[item]

0 comments on commit f15e64f

Please sign in to comment.