Inverted index database system simple implementation for foxql. Search result use case p2p connection proof.
npm i @foxql/foxql-index
const foxqlIndex = require('@foxql/foxql-index');
const database = new foxqlIndex();
database.pushCollection({
collectionName : 'entrys',
fields : [
'title',
'content'
],
ref : 'documentId',
schema : {
title : {
type : 'string',
min : 3,
max : 80
},
content : {
type : 'string',
min : 7,
max : 500,
},
documentId : {
makeFrom : ['title', 'content']
}
}
});
database.useCollection('entrys').registerAnalyzer('tokenizer', (string)=>{
return string.toLowerCase().replace(/ +/g, ' ').trim();
});
database.useCollection('entrys').addDoc({
title : 'test title',
content : 'test example content, very simple usage',
documentId : 1
});
const results = database.useCollection('entrys').search("test query");
console.log(results);
const dump = database.export();
const dump = database.export();
database.import(dump);
database.useCollection('entrys').registerAnalyzer('tokenizer', (string)=>{
return string.toLowerCase().replace(/ +/g, ' ');
});
database.useCollection('entrys').registerAnalyzer('tokenizer2', (string)=>{
return string.trim();
});
//if want aboving change methods sort
database.useCollection('entrys').analyzerSteps = [
'tokenizer2',
'tokenizer'
];
database.useCollection('entrys').deleteDoc('ref id');
database.useCollection('entrys').getDoc('ref id');