import * as fs from 'fs';
|
import * as path from 'path';
|
import Fuse from "fuse.js";
|
|
function countBookInDb() {
|
const text = fs.readFileSync("C:\\Users\\lyg\\Desktop\\fiction-titles.txt", 'utf8');
|
const lines = text.replace(/\r/g, '').split('\n');
|
const fuse = new Fuse(lines, {})
|
const dbIsbnMap = new Map();
|
const notContains = [];
|
for (const line of lines) {
|
dbIsbnMap.set(line.replace(/[^a-zA-Z0-9]/g,''), true);
|
}
|
const text2 = fs.readFileSync('./titles.txt', 'utf8');
|
const lines2 = text2.replace(/\r/g, '').split('\n');
|
let bookCnt = 0;
|
for (const line of lines2) {
|
if (dbIsbnMap.has(line.replace(/[^a-zA-Z0-9]/g,''))) {
|
bookCnt++;
|
} else {
|
notContains.push(line);
|
}
|
// const s = Date.now();
|
// const result = fuse.search(line, { threshold: 0.9 });
|
// console.log(Date.now() - s);
|
// console.log();
|
}
|
console.log(bookCnt);
|
// notContains.splice(0, 10).forEach(isbn => console.log(isbn));
|
}
|
|
countBookInDb();
|