solr_highlight_rules.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. define(function (require, exports, module) {
  17. "use strict";
  18. var oop = require("../lib/oop");
  19. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  20. var SolrHighlightRules = function () {
  21. var keywords = (
  22. "AND|OR|NOT|TO|NOW|HOUR|HOURS|DAY|DAYS|MONTH|MONTHS|YEAR|YEARS"
  23. );
  24. var builtinFunctions = (
  25. "ABS|AVG|CHILDFIELD|DEF|DIST|DIV|DOCFREQ|EQ|EXISTS|FIELD|GT|GTE|HLL|HSIN|IDF|IF|LINEAR|LOG|LT|LTE|MAP|MAX|MAX|MAXDOC|MIN|MIN|MS|MUL|NORM|NUMDOCS|ORD|PAYLOAD|PERCENTILE|POW|PRODUCT|QUERY|RECIP|RORD|SCALE|SQEDIST|SQRT|STDDEV|STRDIST|SUB|SUM|SUM|SUMSQ|SUMTOTALTERMFREQ|TERMFREQ|TF|TOP|TOTALTERMFREQ|UNIQUE|VARIANCE|XOR"
  26. );
  27. var keywordMapper = this.createKeywordMapper({
  28. "support.function": builtinFunctions,
  29. "keyword": keywords
  30. }, "identifier", true);
  31. this.$rules = {
  32. start: [
  33. {
  34. token : "string", // " string
  35. regex : '".*?"'
  36. }, {
  37. token : "string", // ' string
  38. regex : "'.*?'"
  39. }, {
  40. token : "constant.numeric", // float
  41. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  42. }, {
  43. token : keywordMapper,
  44. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  45. }, {
  46. token : "keyword.operator",
  47. regex : '\\+|\\-|\\/|\\?|&|\\^|~|:|\\*|\\||!|"'
  48. }, {
  49. token : "paren.lparen",
  50. regex : "[\\(]"
  51. }, {
  52. token : "paren.rparen",
  53. regex : "[\\)]"
  54. }, {
  55. token : "text",
  56. regex : "\\s+"
  57. }
  58. ]
  59. };
  60. this.normalizeRules();
  61. };
  62. SolrHighlightRules.metaData = {
  63. fileTypes: ["solr"],
  64. name: "Solr",
  65. scopeName: "source.solr"
  66. };
  67. oop.inherits(SolrHighlightRules, TextHighlightRules);
  68. exports.SolrHighlightRules = SolrHighlightRules;
  69. });