/**
 * Routes for search.
 */

'use strict';

/**
 * Modules.
 */

const Router = require('koa-router');

/**
 * Controllers.
 */


/**
 * Create this router branch.
 */
const router = new Router();

/**
 * Define routes start.
 */

/**
 * 搜索内容
 * POST /search/word/:word
 * Request:
 *      Param:
 *          word String //搜索的关键词，目前只支持单个关键词
 * Response:
 *      Body:
 *          {
 *              "doctors": [
 *                  {Doctor Object}
 *              ],
 *              "videos": [
 *                  {Video Object}
 *              ]
 *          }
 */
router.post('search/word/:word', function *() {
    let labelIds = yield MODEL.Label.distinct('_id', {"name": new RegExp(this.params.word)});
    this.body = {
        "doctors": yield MODEL.Doctor.find({
            "$or": [
                {"name": this.params.word},
                {"speciality": this.params.word}
            ]
        }),
        "videos": yield MODEL.Video.find({"label": {"$in": labelIds}})
    };
});

/**
 * 查找项目
 * POST /search/category/:category
 * Request:
 *      Param:
 *          category String //项目关键词，目前只支持单个关键词
 * Response:
 *      Body:
 *          [
 *              {Video Object}
 *          ]
 */
router.post('search/category/:category', function *() {
    let category = yield MODEL.Category.findOne({"name": this.params.category});
    if (category == null) {
        this.body = [];
    } else {
        this.body = yield MODEL.Video.find({"label": {"$in": category.label}});
    }
});

/**
 * Define routes end.
 */

/**
 * Export the router.
 */
module.exports = router;

@@ -698,24 +698,543 @@
 ms.word)%7D);%0A
+%0A    let categoryLabelArray = yield MODEL.Category.distinct('label', %7B%22name%22: new RegExp(this.params.word)%7D);%0A    let categoryLabels = %5B%5D;%0A    /**%0A     * Fast unique.%0A     */%0A    %7B%0A        let tempObject = %7B%7D;%0A%0A        for (let labelId of categoryLabelArray) %7B%0A            tempObject%5BlabelId.toString()%5D = 0;%0A        %7D%0A        for (let labelId of labelIds) %7B%0A            tempObject%5BlabelId.toString()%5D = 0;%0A        %7D%0A%0A        for (let labelId in tempObject) %7B%0A            categoryLabels.push(labelId);%0A        %7D%0A    %7D%0A%0A
     this.bod
@@ -1483,23 +1483,29 @@
 %7B%22$in%22: 
-l
+categoryL
 abel
-Id
 s%7D%7D)%0A   

Add more information for search results.