pixl-server-storage 3.1.8 → 3.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/API.md +1 -1
- package/docs/Indexer.md +2 -1
- package/indexer.js +28 -7
- package/package.json +1 -1
package/docs/API.md
CHANGED
|
@@ -1367,7 +1367,7 @@ storage.getFieldSummary( FIELD_ID, CONFIG, CALLBACK );
|
|
|
1367
1367
|
The `getFieldSummary()` method fetches a summary of all word counts for an index field. This requires a field indexed with the [master list](Indexer.md#master-list) feature enabled. Then you can fetch a "summary" of the data values, which returns a hash containing all the unique words from the index, and their total counts (occurrences) in the data. Example use:
|
|
1368
1368
|
|
|
1369
1369
|
```js
|
|
1370
|
-
|
|
1370
|
+
storage.getFieldSummary( 'status', config, function(err, values) {
|
|
1371
1371
|
if (err) throw err;
|
|
1372
1372
|
|
|
1373
1373
|
// values should contain a hash with word counts:
|
package/docs/Indexer.md
CHANGED
|
@@ -231,6 +231,7 @@ Text filters provide a way to cleanup specific markup languages, leaving only se
|
|
|
231
231
|
|--------|-------------|
|
|
232
232
|
| `html` | This filter strips all HTML tags, and decodes all HTML entities prior to indexing. This also works for XML source. |
|
|
233
233
|
| `markdown` | This filter is designed for [Markdown](https://en.wikipedia.org/wiki/Markdown) source text. It filters out [fenced code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) and also applies the `html` filter as well (you can embed HTML in markdown). |
|
|
234
|
+
| `alphanum` | This filter strips everything except for alphanumerics and underscores. It's designed to reduce a string to a single indexable value. |
|
|
234
235
|
|
|
235
236
|
Note that URLs are always shortened so that only the hostname is indexed. Full URLs are notoriously difficult (and rather useless) to index for searching. See [Text Cleanup](#text-cleanup) below for details.
|
|
236
237
|
|
|
@@ -784,7 +785,7 @@ Given an array of your sorted record IDs, you can then implement your own pagina
|
|
|
784
785
|
If you have any fields indexed with the [master list](#master-list) feature enabled, you can fetch a "summary" of the data values using the [getFieldSummary()](API.md#getfieldsummary) method. This returns a hash containing all the unique words from the index, and their total counts (occurrences) in the data. Example use:
|
|
785
786
|
|
|
786
787
|
```js
|
|
787
|
-
|
|
788
|
+
storage.getFieldSummary( 'status', config, function(err, values) {
|
|
788
789
|
if (err) throw err;
|
|
789
790
|
|
|
790
791
|
// values will contain a hash with word counts:
|
package/indexer.js
CHANGED
|
@@ -239,7 +239,7 @@ module.exports = Class.create({
|
|
|
239
239
|
if (checksum != old_data.checksum) {
|
|
240
240
|
// must reindex
|
|
241
241
|
state.changed[ def.id ] = 1;
|
|
242
|
-
self.updateIndex( old_data, data, def, state, callback );
|
|
242
|
+
self.updateIndex( old_data, data, ''+value, def, state, callback );
|
|
243
243
|
}
|
|
244
244
|
else {
|
|
245
245
|
// data not changed, no action required
|
|
@@ -250,7 +250,7 @@ module.exports = Class.create({
|
|
|
250
250
|
else {
|
|
251
251
|
// index doesn't exist for this record, create immediately
|
|
252
252
|
state.changed[ def.id ] = 1;
|
|
253
|
-
self.writeIndex( data, def, state, callback );
|
|
253
|
+
self.writeIndex( data, ''+value, def, state, callback );
|
|
254
254
|
}
|
|
255
255
|
}, // iterator
|
|
256
256
|
function(err) {
|
|
@@ -454,7 +454,7 @@ module.exports = Class.create({
|
|
|
454
454
|
} ); // lock
|
|
455
455
|
},
|
|
456
456
|
|
|
457
|
-
writeIndex: function(data, def, state, callback) {
|
|
457
|
+
writeIndex: function(data, raw_value, def, state, callback) {
|
|
458
458
|
// create or update single field index
|
|
459
459
|
var self = this;
|
|
460
460
|
var words = data.words;
|
|
@@ -507,7 +507,8 @@ module.exports = Class.create({
|
|
|
507
507
|
def: def,
|
|
508
508
|
group: group,
|
|
509
509
|
base_path: base_path,
|
|
510
|
-
word_hash: word_hash
|
|
510
|
+
word_hash: word_hash,
|
|
511
|
+
raw_value: raw_value
|
|
511
512
|
});
|
|
512
513
|
} // master_list
|
|
513
514
|
|
|
@@ -585,6 +586,11 @@ module.exports = Class.create({
|
|
|
585
586
|
for (var word in word_hash) {
|
|
586
587
|
if (!summary.values[word]) summary.values[word] = 0;
|
|
587
588
|
summary.values[word]++;
|
|
589
|
+
|
|
590
|
+
if (task.def.master_labels) {
|
|
591
|
+
if (!summary.labels) summary.labels = {};
|
|
592
|
+
summary.labels[word] = task.raw_value;
|
|
593
|
+
}
|
|
588
594
|
} // foreach word
|
|
589
595
|
|
|
590
596
|
// save summary back to storage
|
|
@@ -737,7 +743,10 @@ module.exports = Class.create({
|
|
|
737
743
|
|
|
738
744
|
for (var word in word_hash) {
|
|
739
745
|
if (summary.values[word]) summary.values[word]--;
|
|
740
|
-
if (!summary.values[word])
|
|
746
|
+
if (!summary.values[word]) {
|
|
747
|
+
delete summary.values[word];
|
|
748
|
+
if (task.def.master_labels && summary.labels) delete summary.labels[word];
|
|
749
|
+
}
|
|
741
750
|
} // foreach word
|
|
742
751
|
|
|
743
752
|
// save summary back to storage
|
|
@@ -765,7 +774,7 @@ module.exports = Class.create({
|
|
|
765
774
|
} ); // lock
|
|
766
775
|
},
|
|
767
776
|
|
|
768
|
-
updateIndex: function(old_data, new_data, def, state, callback) {
|
|
777
|
+
updateIndex: function(old_data, new_data, raw_value, def, state, callback) {
|
|
769
778
|
// efficiently update single field index
|
|
770
779
|
var self = this;
|
|
771
780
|
var old_words = old_data.words;
|
|
@@ -825,6 +834,12 @@ module.exports = Class.create({
|
|
|
825
834
|
callback: callback || null
|
|
826
835
|
};
|
|
827
836
|
|
|
837
|
+
if (!group.count) {
|
|
838
|
+
this.logDebug(9, "Actually, nothing changed in index: " + def.id + " for record: " + state.id + ", skipping updateIndex");
|
|
839
|
+
if (callback) callback();
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
|
|
828
843
|
// lock index for this
|
|
829
844
|
self.lock( base_path, true, function() {
|
|
830
845
|
// update master list if applicable
|
|
@@ -838,7 +853,8 @@ module.exports = Class.create({
|
|
|
838
853
|
def: def,
|
|
839
854
|
group: group,
|
|
840
855
|
base_path: base_path,
|
|
841
|
-
word_hash: added_words
|
|
856
|
+
word_hash: added_words,
|
|
857
|
+
raw_value: raw_value
|
|
842
858
|
});
|
|
843
859
|
}
|
|
844
860
|
if (Tools.numKeys(removed_words) > 0) {
|
|
@@ -954,6 +970,11 @@ module.exports = Class.create({
|
|
|
954
970
|
return he.decode( value.replace(/<.+?>/g, '') );
|
|
955
971
|
},
|
|
956
972
|
|
|
973
|
+
filterWords_alphanum: function(value) {
|
|
974
|
+
// filter out everything except alphanum + underscore
|
|
975
|
+
return value.replace(/\W+/g, '_').replace(/_+/g, '_');
|
|
976
|
+
},
|
|
977
|
+
|
|
957
978
|
getWordList: function(value, def, config) {
|
|
958
979
|
// clean and filter text down to list of alphanumeric words
|
|
959
980
|
// return array of clean words
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pixl-server-storage",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.9",
|
|
4
4
|
"description": "A key/value/list storage component for the pixl-server framework.",
|
|
5
5
|
"author": "Joseph Huckaby <jhuckaby@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/jhuckaby/pixl-server-storage",
|