...

/

Implementing the Search Term in Cycle.js

Implementing the Search Term in Cycle.js

Learn to implement search functionality using searchRequest.

We'll cover the following...

We need a function that returns an Observable of URLs that query Wikipedia’s API using the search terms entered by the user:

Press + to interact
var MAIN_URL = 'https://en.wikipedia.org';
var WIKI_URL = MAIN_URL + '/wiki/';
var API_URL = MAIN_URL + '/w/api.php?' +
'action=query&list=search&format=json&srsearch=';
function searchRequest(responses)
{
return responses.DOM.select('.search-field').events('input')
.debounce(300)
.map(function(e)
{
return e.target.value
})
.filter(function(value)
{
return value.length > 2
})
.map(function(search)
{
return API_URL + search
});
}

First, we declare some URLs that our application will use to query Wikipedia. In the searchRequest function, we ...