我需要在Pouchdb和Pouchdb-Find中进行区分大小写的搜索 [英] I need to make case insensitive searchs in pouchdb and pouchdb-find
本文介绍了我需要在Pouchdb和Pouchdb-Find中进行区分大小写的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的项目工作得很完美,唯一的问题是搜索区分大小写。它可以很好地搜索子字符串,但如果我键入"test",它会忽略"test"作为有效结果。
我使用pouchdb-find来简化搜索,并使其与Cloudant搜索更相关,并使用Limit/Skip参数进行分页。
我正在使用ion-searchbar让用户键入查询的字符串。
以下是我的控件代码摘录:
@Component({
selector: 'page-notas',
templateUrl: 'notas.html'
})
export class NotasPage {
notas: Array<Object> = [];
zone: any = new NgZone({ enableLongStackTrace: false });
db: any = new PouchDB('banco_de_dados.bd');
db_limit = 10;
pouch_query: object = {
selector: { data_emissao: { $gt: null } },
sort: [ {'data_emissao' : 'desc'} ],
limit: 10,
skip: 0,
};
constructor(
private scanner: BarcodeScanner,
private toastCtrl: ToastController,
private googleAnalytics: GoogleAnalytics,
public navCtrl: NavController,
public alertCtrl: AlertController,
public modalCtrl: ModalController
) {
this.notas = [];
}
//...
// unrelated code in here
//...
onInput($event:any) {
this.googleAnalytics.trackEvent('SearchBar', 'onInput', 'Event: ' + $event);
//Here is the query options, it's working, the only problem is that it's case sensitive
this.pouch_query = {
selector: {
data_emissao: { $gt: null },
descricao: { $regex: this.search_query }
},
sort: [ {'data_emissao' : 'desc'} ],
limit: 10,
skip: 0
};
// this function is a little bigger
// butit just makes the search and list it in a ion-list
this.refresh();
}
}
这里是组件代码摘录。
<!-- MORE UNRELATED CODE -->
<ion-searchbar
[(ngModel)]="search_query"
[showCancelButton]="shoulShowCancelButton"
(ionInput)="onInput($event)"
(ionCancel)="onCancel($event)">
</ion-searchbar>
<!-- MORE UNRELATED CODE -->
推荐答案
Java脚本内置了正则表达式函数,因此您只需将激发选项添加到正则表达式中,如下所示
RegExp(<string>, "i")
您可以在w3schools中找到正则表达式选项列表。以下是完整的代码:
this.pouch_query = {
selector: {
data_emissao: { $gt: null },
descricao: { $regex: RegExp(this.search_query, "i") }
},
sort: [ {'data_emissao' : 'desc'} ],
limit: 10,
skip: 0
};
这篇关于我需要在Pouchdb和Pouchdb-Find中进行区分大小写的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文