Even if an application simply shows results of search on Wikipedia, it seems like a lot of work to build one. But it’s easy if you use K5 Playground. See this tutorial and you’ll get it done in 30 minutes.
Information
Ingredients
- Template: Simple Search
- API Loigcs: Wikipedia Search Page
Functions
- Searching on Wikipedia.
- Displaying results of the search.
Create the application
Frontend
Choose the
Simple Search
Template.Customize the UI in K5 Playground.
Backend
Change the WebAPI name.
- Rename
sample_products
toarticles
.
- Rename
Edit the API Logic of
GET /articles
.Click
GET /articles
endpoint.Remove
Fetch Document
API Logic.Add the
Search Wiki Page
API Logic from Search menu at the right pane.Modify the code as follows.
Set search keyword
1
var srsearch = req.swagger.params.keyword.value;
Set total pages
1
var srlimit = req.swagger.params.limit.value;
Set offset for pages
1
var sroffset = req.swagger.params.offset.value;
Download the application.
Customize the application
Frontend
Edit the
actions/ProductActionCreators.js
.Change the parameter of dispatch called in
getProducts
method.1
2
3
4
5
6
7
8
9
10AppDispatcher.dispatch({
type: ActionTypes.GET_PRODUCTS,
data: {
products: productList.data.query.search.map(
// NOTE: Since we need _id to show detail page, use the title of page.
product => Object.assign({}, product, { _id: product.title }),
),
count: productList.data.query.searchinfo.totalhits,
},
});Edit the
components/pages/ProductListPage.js
.Change
card
function to show a result of wiki search.1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17const card = value => (
<VerticalCard002
key={value.title}
title={
<a
href={`https://en.wikipedia.org/wiki/${value._id}`}
target="_blank"
rel="noopener noreferrer"
>
{value.title}
</a>
}
contentStyle={styles.cardContent}
highlighted={value.snippet.replace(/<[^>]*>/gm, '')}
highlightedStyle={styles.cardHighlighted}
/>
);
Backend
Nothing to be edited.
Deploy the application
Finally, all you need to do is deploying backend and frontend.
Backend
1 | cd backend |
Frontend
1 | cd frontend |
Download
NOTE: Removed all actions and components not in use.
Version
- Simple Search Template: v1.0.0