liyugang
3 天以前 8c24730e9a52dc2c8933e8d41d2f9651de48a231
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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();