TextMatchExpression.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. "use strict";
  2. var LeafMatchExpression = require('./LeafMatchExpression.js');
  3. var TextMatchExpression = module.exports = function TextMatchExpression() {
  4. base.call(this, 'TEXT');
  5. }, klass = TextMatchExpression, base = LeafMatchExpression, proto = klass.prototype = Object.create(base.prototype, {constructor: {value: klass}});
  6. /**
  7. *
  8. * Initializes the class object.
  9. *
  10. * @param query
  11. * @param language
  12. * @returns {*}
  13. */
  14. proto.init = function init(query, language) {
  15. this._query = query;
  16. this._language = language;
  17. return this.initPath('_fts');
  18. };
  19. /**
  20. * Gets the query.
  21. *
  22. * @returns {*}
  23. */
  24. proto.getQuery = function getQuery() {
  25. return this._query;
  26. };
  27. /**
  28. * Gets the language.
  29. *
  30. * @returns {*}
  31. */
  32. proto.getLanguage = function getLanguage() {
  33. return this._language;
  34. };
  35. /**
  36. * Check if the input element matches.
  37. *
  38. * @param e
  39. * @returns {boolean}
  40. */
  41. proto.matchesSingleElement = function matchesSingleElement(e) {
  42. return true;
  43. };
  44. /**
  45. * Debug a string.
  46. *
  47. * @param level
  48. * @returns {string}
  49. */
  50. proto.debugString = function debugString(level) {
  51. var rtn = this._debugAddSpace(level);
  52. rtn += 'TEXT : query=' + ', language=' + this._language + ', tag=';
  53. var tagData = this.getTag();
  54. if (tagData !== null) {
  55. tagData.debugString(level);
  56. } else {
  57. rtn += 'NULL';
  58. }
  59. return rtn + '\n';
  60. };
  61. /**
  62. * Verifies the equivalency of two operands.
  63. *
  64. * @param other
  65. * @returns {boolean}
  66. */
  67. proto.equivalent = function equivalent(other) {
  68. if (this.matchType() !== other.matchType()) {
  69. return false;
  70. }
  71. if (other.getQuery() !== this._query) {
  72. return false;
  73. }
  74. if (other.getLanguage() !== this._language) {
  75. return false;
  76. }
  77. return true;
  78. };
  79. /**
  80. * Clone this instance into a new one.
  81. *
  82. * @returns {TextMatchExpression}
  83. */
  84. proto.shallowClone = function shallowClone() {
  85. var next = new TextMatchExpression();
  86. next.init(this._query, this._language);
  87. if (this.getTag()) {
  88. next.getTag(this.getTag().clone());
  89. }
  90. return next;
  91. };