js中的正则表达式 使用Docker和Elasticsearch搭建全文本搜索引(17)

电脑杂谈  发布时间:2018-02-22 10:22:50  来源:网络整理

/**

* GET /paragraphs

* Get a range of paragraphs from the specified book

* Query Params -

* bookTitle: string under 256 characters

* start: positive integer

* end: positive integer greater than start

*/

router. get( '/paragraphs',

validate({

query: {

bookTitle: joi. string().max( 256).required(),

start: joi.number().integer().min( 0). default( 0),

end: joi.number().integer().greater(joi. ref( 'start')). default( 10)

}

}),

async(ctx, next) => {

const{ bookTitle, start, end } = ctx.request.query

ctx.body = awaitsearch.getParagraphs(bookTitle, start, end)

}

)

8.2 添加UI界面

本节添加前端查询功能,并显示书中包含查询内容的整页信息。在/public/app.js methods功能块中添加如下内容:

/** Call the API to get current page of paragraphs */

asyncgetParagraphs(bookTitle, offset) {

try{

this.bookOffset = offset

conststart = this.bookOffset

constend = this.bookOffset + 10

constresponse = awaitaxios. get(`${ this.baseUrl}/paragraphs`, { params: { bookTitle, start, end } })

returnresponse.data.hits.hits

} catch(err) {

console.error(err)

}

},

/** Get next page (next 10 paragraphs) of selected book */

asyncnextBookPage() {

this.$refs.bookModal.scrollTop = 0

this.paragraphs = awaitthis.getParagraphs( this.selectedParagraph._source.title, this.bookOffset + 10)

},

/** Get previous page (previous 10 paragraphs) of selected book */

asyncprevBookPage() {

this.$refs.bookModal.scrollTop = 0

this.paragraphs = awaitthis.getParagraphs( this.selectedParagraph._source.title, this.bookOffset - 10)

},

/** Display paragraphs from selected book in modal window */


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-88488-17.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 闵天宇
      闵天宇

      你有种吗

    • 秦红杰
      秦红杰

      抗日得时候多少人抵制日货又能怎么样

    热点图片
    拼命载入中...