|
379 | 379 | deepGet(value, path, index + 1); |
380 | 380 | } |
381 | 381 | } |
382 | | - }; |
| 382 | + }; // Backwards compatibility (since path used to be a string) |
| 383 | + |
383 | 384 |
|
384 | | - deepGet(obj, path, 0); |
| 385 | + deepGet(obj, isString(path) ? path.split('.') : path, 0); |
385 | 386 | return arr ? list : list[0]; |
386 | 387 | } |
387 | 388 |
|
|
1920 | 1921 | var _this = this; |
1921 | 1922 |
|
1922 | 1923 | var expression = parse(query, this.options); |
1923 | | - var records = this._myIndex.records; |
1924 | | - var resultMap = {}; |
1925 | | - var results = []; |
1926 | 1924 |
|
1927 | | - var evaluateExpression = function evaluateExpression(node, item, idx) { |
1928 | | - if (node.children) { |
1929 | | - var operator = node.operator; |
1930 | | - var res = []; |
| 1925 | + var evaluate = function evaluate(node, item, idx) { |
| 1926 | + if (!node.children) { |
| 1927 | + var keyId = node.keyId, |
| 1928 | + searcher = node.searcher; |
1931 | 1929 |
|
1932 | | - for (var k = 0; k < node.children.length; k += 1) { |
1933 | | - var child = node.children[k]; |
1934 | | - var matches = evaluateExpression(child, item, idx); |
| 1930 | + var matches = _this._findMatches({ |
| 1931 | + key: _this._keyStore.get(keyId), |
| 1932 | + value: _this._myIndex.getValueForItemAtKeyId(item, keyId), |
| 1933 | + searcher: searcher |
| 1934 | + }); |
1935 | 1935 |
|
1936 | | - if (matches && matches.length) { |
1937 | | - res.push({ |
1938 | | - idx: idx, |
1939 | | - item: item, |
1940 | | - matches: matches |
1941 | | - }); |
| 1936 | + if (matches && matches.length) { |
| 1937 | + return [{ |
| 1938 | + idx: idx, |
| 1939 | + item: item, |
| 1940 | + matches: matches |
| 1941 | + }]; |
| 1942 | + } |
| 1943 | + |
| 1944 | + return []; |
| 1945 | + } |
| 1946 | + /*eslint indent: [2, 2, {"SwitchCase": 1}]*/ |
1942 | 1947 |
|
1943 | | - if (operator === LogicalOperator.OR) { |
1944 | | - // Short-circuit |
1945 | | - break; |
| 1948 | + |
| 1949 | + switch (node.operator) { |
| 1950 | + case LogicalOperator.AND: |
| 1951 | + { |
| 1952 | + var res = []; |
| 1953 | + |
| 1954 | + for (var i = 0, len = node.children.length; i < len; i += 1) { |
| 1955 | + var child = node.children[i]; |
| 1956 | + var result = evaluate(child, item, idx); |
| 1957 | + |
| 1958 | + if (result.length) { |
| 1959 | + res.push.apply(res, _toConsumableArray(result)); |
| 1960 | + } else { |
| 1961 | + return []; |
| 1962 | + } |
1946 | 1963 | } |
1947 | | - } else if (operator === LogicalOperator.AND) { |
1948 | | - res.length = 0; // Short-circuit |
1949 | 1964 |
|
1950 | | - break; |
| 1965 | + return res; |
1951 | 1966 | } |
1952 | | - } |
1953 | 1967 |
|
1954 | | - return res; |
1955 | | - } else { |
1956 | | - var keyId = node.keyId, |
1957 | | - searcher = node.searcher; |
| 1968 | + case LogicalOperator.OR: |
| 1969 | + { |
| 1970 | + var _res = []; |
1958 | 1971 |
|
1959 | | - var value = _this._myIndex.getValueForItemAtKeyId(item, keyId); |
| 1972 | + for (var _i = 0, _len = node.children.length; _i < _len; _i += 1) { |
| 1973 | + var _child = node.children[_i]; |
1960 | 1974 |
|
1961 | | - return _this._findMatches({ |
1962 | | - key: _this._keyStore.get(keyId), |
1963 | | - value: value, |
1964 | | - searcher: searcher |
1965 | | - }); |
| 1975 | + var _result = evaluate(_child, item, idx); |
| 1976 | + |
| 1977 | + if (_result.length) { |
| 1978 | + _res.push.apply(_res, _toConsumableArray(_result)); |
| 1979 | + |
| 1980 | + break; |
| 1981 | + } |
| 1982 | + } |
| 1983 | + |
| 1984 | + return _res; |
| 1985 | + } |
1966 | 1986 | } |
1967 | 1987 | }; |
1968 | 1988 |
|
| 1989 | + var records = this._myIndex.records; |
| 1990 | + var resultMap = {}; |
| 1991 | + var results = []; |
1969 | 1992 | records.forEach(function (_ref3) { |
1970 | 1993 | var item = _ref3.$, |
1971 | 1994 | idx = _ref3.i; |
1972 | 1995 |
|
1973 | 1996 | if (isDefined(item)) { |
1974 | | - var expResults = evaluateExpression(expression, item, idx); |
| 1997 | + var expResults = evaluate(expression, item, idx); |
1975 | 1998 |
|
1976 | 1999 | if (expResults.length) { |
1977 | 2000 | // Dedupe when adding |
|
0 commit comments