我有一个操作FindPage.js,它查找页面并检索它们以显示为结果。我了解如何训练它来查找诸如“阅读Twitter搜索页面”或“阅读可搜索文本页面”之类的页面。培训将“ Twitter搜索”视为SearchTerm,下面的代码将SearchTerm与数据中的标记字段匹配。但是,我将如何训练以理解诸如“读取所有页面”之类的命令?我希望代码在通配符上进行搜索,并带回所有可用页面。
// search for informational pages
var console = require('console');
const PAGES = require('./content/pages')
pages = PAGES
console.log('pages are', pages)
exports.function = function findPage (searchTerm) {
console.log('searchTerm is', searchTerm)
var matches = []
pages = PAGES
for (var i = 0; i < pages.length; i++) {
if (searchTerm == pages[i].tag) {
matches.push(pages[i])
}
else
{ console.log('no tag matches')
}
}
console.log('matches are', matches)
return matches
}
培训:
[g:Page]阅读(Twitter搜索)[v:SearchTerm]页面。
答案 0 :(得分:1)
这行得通,尽管我觉得对从“ all”到包含通配符字符串(即“”)的转换进行硬编码有点笨拙。
exports.function = function findPage (searchTerm) {
//console.log('searchTerm is', searchTerm)
if (searchTerm == 'all') {
searchTerm = ''
console.log('searchTerm is all', searchTerm)
}
else
{ console.log('searchTerm is not all', searchTerm)
}
var matches = []
pages = PAGES
matches = pages.filter(function(pages) {
return pages.tag.includes(searchTerm);
});
const str = 'To be, or not to be, that is the question.';
console.log(str.includes('To be')); // true
console.log(str.includes('')) // true