@@ -72,8 +72,13 @@ class SimplePackageIndex implements PackageIndex {
72
72
@override
73
73
Future addPackage (PackageDocument document) async {
74
74
final PackageDocument doc = document.intern (_internPool.intern);
75
- await removePackage (doc.package);
76
- if (document.isDiscontinued == true ) return ; // isDiscontinued may be null
75
+
76
+ // isDiscontinued may be null
77
+ if (document.isDiscontinued == true ) {
78
+ await removePackage (doc.package);
79
+ return ;
80
+ }
81
+
77
82
_packages[doc.package] = doc;
78
83
_nameIndex.add (doc.package, doc.package);
79
84
_descrIndex.add (doc.package, doc.description);
@@ -531,6 +536,7 @@ class TokenMatch {
531
536
}
532
537
533
538
class TokenIndex {
539
+ final Map <String , String > _textHashes = < String , String > {};
534
540
final Map <String , Set <String >> _inverseIds = < String , Set <String >> {};
535
541
final Map <String , double > _docSizes = < String , double > {};
536
542
final int _minLength;
@@ -544,17 +550,28 @@ class TokenIndex {
544
550
545
551
void add (String id, String text) {
546
552
final Set <String > tokens = _tokenize (text, _minLength);
547
- if (tokens == null || tokens.isEmpty) return ;
553
+ if (tokens == null || tokens.isEmpty) {
554
+ if (_textHashes.containsKey (id)) {
555
+ remove (id);
556
+ }
557
+ return ;
558
+ }
559
+ final String textHash = '${text .hashCode }/${tokens .length }' ;
560
+ if (_textHashes.containsKey (id) && _textHashes[id] != textHash) {
561
+ remove (id);
562
+ }
548
563
for (String token in tokens) {
549
564
final Set <String > set = _inverseIds.putIfAbsent (token, () => new Set ());
550
565
set .add (id);
551
566
}
552
567
// Document size is a highly scaled-down proxy of the length.
553
568
final docSize = 1 + math.log (1 + tokens.length) / 100 ;
554
569
_docSizes[id] = docSize;
570
+ _textHashes[id] = textHash;
555
571
}
556
572
557
573
void remove (String id) {
574
+ _textHashes.remove (id);
558
575
_docSizes.remove (id);
559
576
final List <String > removeKeys = [];
560
577
_inverseIds.forEach ((String key, Set <String > set ) {
0 commit comments