当前位置:网站首页>Cloud function realizes fuzzy search function
Cloud function realizes fuzzy search function
2022-06-23 04:55:00 【JSONP$】
Cloud function realizes fuzzy search function
Core code
// Cloud function entry file
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
// Cloud function entry function
exports.main = async (event, context) => {
return db.collection('zhusir_video').where({
name:db.RegExp({
regexp:event.name,
options:'i'
})
}).get()
}
Have a look first html part
<!-- Search box -->
<view class="flex">
<van-search shape="round" value="{
{keywords}}" clearable="{
{false}}" placeholder="{
{value}}" custom-class="search" input-class="input" show-action action-text=" Cancel " bind:search="onSearch" bind:change="inputChange" bind:cancel="onCancel" bind:focus="onFocus" bind:blur="onBlur" />
</view>
Look again. js part
// pages/search/index.js
Page({
/** * Initial data of the page */
data: {
searchHistory: [],
movies: [],
value: ' Please enter the title ',
show: false,
keywords: ''
},
/** * Life cycle function -- Monitor page loading */
onLoad(options) {
this.setData({
searchHistory: wx.getStorageSync('searchHistory') || []
})
},
/** * Life cycle function -- Listening page first rendering completed */
onReady() {
},
goDetail(e) {
wx.navigateTo({
url: '../detail/detail?id=' + e.currentTarget.dataset.id,
})
},
onFocus() {
this.setData({
show: true
})
},
// onBlur() {
// this.setData({
// show: false
// })
// },
clearHistory() {
this.setData({
searchHistory: []
})
wx.removeStorageSync('searchHistory')
},
inputChange(e) {
let value = e.detail
if (!value) {
this.setData({
movies: []
})
return false
}
this.loadData(value)
},
tapSearch(e) {
const query = e.currentTarget.dataset.name
this.setData({
movies: []
})
this.searchMovie(query)
},
loadData(value) {
wx.cloud.callFunction({
name: 'searchMovie',
data: {
name: value
}
})
.then(res => {
this.setData({
movies: res.result.data
})
})
},
searchMovie(query) {
let history = this.data.searchHistory
this.setData({
value: query,
keywords: '',
show:false
})
if (query.length > 0 && query.trim().length != 0) {
if (!history.some(item => item === query)) {
let hist = [query].concat(history).slice(0, 10)
this.setData({
searchHistory: hist
})
wx.setStorageSync('searchHistory', hist)
}
this.loadData(query)
}
},
onSearch(e) {
const query = e.detail
this.setData({
movies: [],
value: query
})
if (!query) {
wx.showToast({
title: ' Please enter the search content ',
icon: 'none'
})
this.setData({
value: ' Please enter the title '
})
return false
}
this.searchMovie(query)
},
onCancel() {
if (this.data.show) {
this.setData({
show: false
})
return false
}
if (this.data.movies) {
this.setData({
movies: [],
value:' Please enter the title '
})
return false
}
wx.switchTab({
url: '../home/index',
})
},
/** * Life cycle function -- Monitor page display */
onShow() {
},
/** * Life cycle function -- Monitor page hidden */
onHide() {
},
/** * Life cycle function -- Monitor page uninstall */
onUnload() {
},
/** * Page related event handler -- Monitor user pull-down action */
onPullDownRefresh() {
},
/** * Handling function of page pull bottom event */
onReachBottom() {
},
/** * Users click the upper right corner to share */
onShareAppMessage() {
}
})
边栏推荐
猜你喜欢

独立站聊天机器人有哪些类型?如何快速创建属于自己的免费聊天机器人?只需3秒钟就能搞定!

ICer技能02makefile脚本自跑vcs仿真

Reinstallation of cadence16.3, failure and success

Abnova ACTN4纯化兔多克隆抗体说明书

McKinsey: in 2021, the investment in quantum computing market grew strongly and the talent gap expanded

Abnova PSMA磁珠解决方案

使用Live Chat促进业务销售的惊人技巧

Static two position relay gls-3004k/dc220v

论文阅读_关系抽取_CASREL

Abnova liquidcell negative enrichment cell separation and recovery system
随机推荐
Kail 渗透基本素养 基础命令
What are the types of independent station chat robots? How to quickly create your own free chat robot? It only takes 3 seconds!
Abnova acid phosphatase (wheat germ) instructions
Current relay jdl-1002a
Alkylation process test questions and simulation test in 2022
开关磁阻电机悬浮驱动IR2128小结
如何解决独立站多渠道客户沟通难题?这款跨境电商插件一定要知道!
const理解之一
20000 words + 20 pictures | details of nine data types and application scenarios of redis
DPR-34V/V双位置继电器
Abnova ACTN4纯化兔多克隆抗体说明书
win10下安装、运行MongoDB
golang使用mongo-driver操作——增(基础)
Abnova liquidcell negative enrichment cell separation and recovery system
A mvc5+easyui enterprise rapid development framework source code BS framework source code
使用Live Chat促进业务销售的惊人技巧
An understanding of free() (an error in C Primer Plus)
电流继电器JDL-1002A
Principle of 8-bit full adder
E45: ‘readonly‘ option is set (add ! to override)