Skip to content

Commit

Permalink
Create QuickScore class to replace createScorer() (#1)
Browse files Browse the repository at this point in the history
* Add debug harness

Remove debug statements from quick-score.js and move them to debug-statements.js.
quick-score-debug.js reinserts the debug statements after reading in the source.
Add a maxDifference param to scoreNearly().

* Add uppercase and word separator tests to improve coverage

Add some tests to quick-score-test.js.

* Replicate bugs in QSSense.m

Deliberately introduce bugs in quick-score.js to replicate the scores produced by QSSense.m, as described here: quicksilver/Quicksilver#2450
Add hitmask test that replicates the results from TestQSSense.m.

* Remove buggy lines from quick-score.js

Update tests in quick-score.test.js with scores from the non-buggy code.
Add zero scores and search ranges test suites.
Add engines in package.json to require at least node 8.0, so that the eval() in the quick-score-debug.js works.

* Convert to one var declaration per line

Convert var to let declarations, and use default params.
Add loop to quick-score-test.js that demonstrates increasing the search range.
Don't show the discount score values that aren't being used currently.
Change indent so it starts at a 1-based column 10.

* Change how debug statements are inserted by quick-score-debug.js

Search for strings in quick-score.js and insert the debug statements before or after them.
Convert some lets to consts in quick-score.js.

* Rename debug files

Fix path to src/quick-score.js from debug-harness.js.
Add debug npm script and repository link.

* Convert some lets to consts

Convert substr() calls to substring().
Add --runInBand and --env node to jest calls to try to speed it up.
Add test-watch script.

* Add rollup to build the library

Switch to using import and export instead of require() in src files.
Build files to lib/ and dist/.
Add index.js to combine the files into a single export.
Add babel config to package.json to transform modules when testing with jest, but not when building with rollup.
Remove webpack.
Switch to let and const in debug-harness.js.

* Add minified output to dist

Change filenames in dist to quick-score.
Add rollup-plugin-babel-minify.

* Simplify exports from index.js

Add prepare script and files array to package.json.
Added some info to README.md.

* Fix prepare in package.json

* Change lib UMD output to index.js

* Add test for index.js

Include dist and lib in the npm package.
Indent package.json with spaces.

* Add eslint

Add pretest script.
Export named quickScore and default.

* 0.1.0

* Add score-array.js and test

Add tabs.js for example data.
Tweak eslint rules and change to tab-delimited.

* Use for-loop instead of reduce() when scoring arrays

Add another Tabs scoring test and refactor it.

* Add default scoreArray() export to score-array.js

Add a "qk" score test.
Add beginning of some examples to README.md.

* Make the scorer function default to quickScore

* Add test for configuring individual scorers per key

Add minimum node version to package.json.
Collect coverage only from src/.

* Add scoreKey to indicate which key had the high score

* Remove default exports

Update tests for index.js.

* Rename some parameters

* Check max() only once in addIndexesInRange()

* Rename hits to matches

* Switch to returning ranges in matches array

Remove addIndexesToRange() function.
Fix quick-score.test.js. and score-array.test.js.
Fix array-element-newline eslint rule.

* Add version that returns the same scores as the QuicKey algo

* Add configOptions to scoreArray()

* Refactor quickScore() to use a config object for calculating scores

Lowercase the string and query once rather than on every substring search.
Add config.js.
Add QuicksilverConfig to score strings like the default Quicksilver algo.

* Update quick-score.js with code from quickey-quick-score.js

Clean up order of params in adjustRemainingScore().
Include exports from config in index.js.
Update scoreArray() to not default the config to null, so that DefaultConfig gets used.
Remove quickey-quick-score.js.
Fix index.test.js with new arity for quickScore().
Update .eslintrc.

* Return ignoredScore for empty queries

Add a test for an empty query that returns 0.9.

* Refactor QuickScoreConfig to extend BaseConfig

Add useSkipReduction() method and emptyQueryScore to the config.
Move constants into config object so they can be overridden.
Use emptyQueryScore = 0 with the default config.
Rename config() to createConfig().
Create a config from the configOptions in createScorer().
Fix zero score tests.
Remove babel key from package.json.
Add babel-plugin-external-helpers to avoid duplicate class call checks.
Update eslintrc.

* Add a comment

* Tweak .eslintrc.js

* Create QuickScore class to replace createScorer()

Squashed commit of the following:

commit 99c2915
Author: John Dunning <fw@johndunning.com>
Date:   Sat Sep 8 21:31:56 2018 -0700

    Turn off linebreak-style rule

commit 6709cd6
Author: John Dunning <fw@johndunning.com>
Date:   Sat Sep 8 21:21:33 2018 -0700

    Refactor QuickScore

    Change QuickScore.score() to search().
    Add setKeys() and default params to QuickScore.
    In createConfig(), don't create a new QuickScoreConfig if the param is an instance of Config, so that BaseConfig isn't affected.
    Make createConfig() available on quickScore().
    Add more QuickScore tests.
    Add setup.js and utils.js.
    Get rid of default searchRange in getRangeOfSubstring().
    Clean up package.json scripts.
    Add license to README.md.

commit 9797460
Author: John Dunning <fw@johndunning.com>
Date:   Fri Sep 7 19:18:41 2018 -0700

    Add badges to README.md

commit e4ea4d1
Author: John Dunning <fw@johndunning.com>
Date:   Fri Sep 7 19:11:52 2018 -0700

    Add npm install to .travis.yml

commit db891c1
Author: John Dunning <john_dunning@yahoo.com>
Date:   Fri Sep 7 17:37:14 2018 -0700

    Move scorer to QuickScore to avoid circular import

    Add .travis.yml.
    Add codecov.io support.

commit 9e2bdaa
Author: John Dunning <fw@johndunning.com>
Date:   Thu Sep 6 15:50:35 2018 -0700

    Move scorer to config

commit 5d99f3a
Author: John Dunning <fw@johndunning.com>
Date:   Thu Sep 6 00:15:12 2018 -0700

    Add QuickScore class

    Add QuickScore.test.js.
    Add babel key back to package.json so that the tests work again.
  • Loading branch information
fwextensions committed Sep 15, 2018
1 parent 9fa0c4b commit d091db5
Show file tree
Hide file tree
Showing 24 changed files with 2,604 additions and 1,988 deletions.
303 changes: 303 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,303 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2015,
"sourceType": "module"
},
"rules": {
"accessor-pairs": "error",
"array-bracket-newline": "error",
"array-bracket-spacing": "error",
"array-callback-return": "error",
"array-element-newline": [
"error",
"consistent"
],
"arrow-body-style": "error",
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": "error",
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": "off",
"callback-return": "error",
"camelcase": "error",
"capitalized-comments": [
"off",
"never"
],
"class-methods-use-this": "off",
"comma-dangle": "error",
"comma-spacing": [
"error",
{
"after": true,
"before": false
}
],
"comma-style": "error",
"complexity": "off",
"computed-property-spacing": "error",
"consistent-return": "error",
"consistent-this": "error",
"curly": "error",
"default-case": "error",
"dot-location": "error",
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": "off",
"func-call-spacing": "error",
"func-name-matching": "error",
"func-names": "off",
"func-style": [
"error",
"declaration"
],
"function-paren-newline": "off",
"generator-star-spacing": "error",
"global-require": "error",
"guard-for-in": "error",
"handle-callback-err": "error",
"id-blacklist": "error",
"id-length": "off",
"id-match": "error",
"implicit-arrow-linebreak": "error",
"indent": "off",
"indent-legacy": "off",
"init-declarations": "error",
"jsx-quotes": "error",
"key-spacing": "error",
"keyword-spacing": [
"error",
{
"after": true,
"before": true
}
],
"line-comment-position": "error",
"linebreak-style": "off",
"lines-around-comment": "error",
"lines-around-directive": "error",
"lines-between-class-members": [
"error",
"always"
],
"max-classes-per-file": "off",
"max-depth": "off",
"max-len": "off",
"max-lines": "error",
"max-lines-per-function": "off",
"max-nested-callbacks": "error",
"max-params": "off",
"max-statements": "off",
"max-statements-per-line": "error",
"multiline-comment-style": [
"error",
"separate-lines"
],
"multiline-ternary": "off",
"new-cap": "error",
"new-parens": "error",
"newline-after-var": [
"error",
"always"
],
"newline-before-return": "error",
"newline-per-chained-call": "error",
"no-alert": "error",
"no-array-constructor": "error",
"no-async-promise-executor": "error",
"no-await-in-loop": "error",
"no-bitwise": "error",
"no-buffer-constructor": "error",
"no-caller": "error",
"no-catch-shadow": "error",
"no-confusing-arrow": [
"error",
{
"allowParens": true
}
],
"no-continue": "off",
"no-div-regex": "error",
"no-duplicate-imports": [
"error",
{
"includeExports": false
}
],
"no-else-return": "off",
"no-empty-function": "error",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-extra-parens": "off",
"no-floating-decimal": "off",
"no-implicit-coercion": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inline-comments": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-misleading-character-class": "error",
"no-mixed-operators": [
"error",
{
"allowSamePrecedence": true
}
],
"no-mixed-requires": "error",
"no-multi-assign": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-native-reassign": "error",
"no-negated-condition": "off",
"no-negated-in-lhs": "error",
"no-nested-ternary": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-param-reassign": "error",
"no-path-concat": "error",
"no-plusplus": "off",
"no-process-env": "error",
"no-process-exit": "error",
"no-proto": "error",
"no-prototype-builtins": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-sync": "error",
"no-tabs": "off",
"no-template-curly-in-string": "error",
"no-ternary": "off",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-undefined": "error",
"no-underscore-dangle": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": "error",
"no-unused-expressions": "error",
"no-unused-vars": ["error", {"args": "none"}],
"no-use-before-define": "off",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"nonblock-statement-body-position": "error",
"object-curly-newline": "error",
"object-curly-spacing": [
"error",
"never"
],
"object-property-newline": "error",
"object-shorthand": [2, "consistent"],
"one-var": "off",
"one-var-declaration-per-line": "error",
"operator-assignment": [
"error",
"always"
],
"operator-linebreak": [
"error",
"after"
],
"padded-blocks": "off",
"padding-line-between-statements": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-destructuring": "error",
"prefer-numeric-literals": "error",
"prefer-object-spread": "off",
"prefer-promise-reject-errors": "error",
"prefer-reflect": "off",
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "off",
"quote-props": "off",
"quotes": [
"error",
"double"
],
"radix": "error",
"require-atomic-updates": "error",
"require-await": "error",
"require-jsdoc": "off",
"require-unicode-regexp": "error",
"rest-spread-spacing": "error",
"semi": "error",
"semi-spacing": [
"error",
{
"after": true,
"before": false
}
],
"semi-style": [
"error",
"last"
],
"sort-imports": "off",
"sort-keys": "off",
"sort-vars": "off",
"space-before-blocks": "error",
"space-before-function-paren": "off",
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"strict": "error",
"switch-colon-spacing": "error",
"symbol-description": "error",
"template-curly-spacing": "error",
"template-tag-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"valid-jsdoc": "error",
"vars-on-top": "error",
"wrap-regex": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
}
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/node_modules
/coverage
/dist
/lib
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: node_js

node_js:
- "8"

cache:
directories:
- node_modules

install:
- npm install -g codecov
- npm install

script:
- npm run test:coverage
- codecov
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,62 @@
# quick-score

`quick-score` is a JavaScript string-scoring library based on the Quicksilver algorithm.
![travis](https://travis-ci.com/fwextensions/quick-score.svg?branch=quickscore-class) [![codecov](https://codecov.io/gh/fwextensions/quick-score/branch/quickscore-class/graph/badge.svg)](https://codecov.io/gh/fwextensions/quick-score)

> `quick-score` is a JavaScript string-scoring and fuzzy-matching library based on the Quicksilver algorithm, and is perfect for interactive matching as a user types a query.
intended for long strings
return matches in a "sensible" order


## Install

```sh
npm install --save quick-score
```


## Usage

You can import the `quickScore` function from a property of the CommonJS module:

```js
const quickScore = require("quick-score").quickScore;
```

Or as an ES6 module:

```js
import {quickScore} from "quick-score";
```



```js
quickScore("thought", "gh"); // 0.7000000000000001
quickScore("GitHub", "gh"); // 0.9166666666666666
```

```js
const scoreArray = require("quick-score").scoreArray;
```

```js
import {scoreArray} from "quick-score";

const strings = ["thought", "giraffe", "GitHub", "hello, Garth"];
const result = scoreArray(strings, "gh");

console.log(result); //
```


will modify array of strings passed in

always case-insensitive, uses `toLocaleLowerCase()`

first key in array is used for sorting strings with the same score


## License

MIT
Loading

0 comments on commit d091db5

Please sign in to comment.