1 /*
2 * Copyright 2015-2018 HuntLabs.cn
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 module hunt.sql.dialect.mysql.ast.expr.MySqlMatchAgainstExpr;
17
18
19
20 import hunt.collection;
21
22 import hunt.sql.ast.SQLExpr;
23 import hunt.sql.ast.SQLExprImpl;
24 import hunt.sql.ast.SQLObject;
25 import hunt.sql.dialect.mysql.visitor.MySqlASTVisitor;
26 import hunt.sql.visitor.SQLASTVisitor;
27 import hunt.sql.dialect.mysql.ast.expr.MySqlExpr;
28 import std.uni;
29
30 public class MySqlMatchAgainstExpr : SQLExprImpl , MySqlExpr {
31
32 private List!(SQLExpr) columns;
33
34 private SQLExpr against;
35
36 private SearchModifier searchModifier;
37
38 this(){
39 columns = new ArrayList!(SQLExpr)();
40 }
41
42 override public MySqlMatchAgainstExpr clone() {
43 MySqlMatchAgainstExpr x = new MySqlMatchAgainstExpr();
44 foreach (SQLExpr column ; columns) {
45 SQLExpr column2 = column.clone();
46 column2.setParent(x);
47 x.columns.add(column2);
48 }
49 if (against !is null) {
50 x.setAgainst(against.clone());
51 }
52 x.searchModifier = searchModifier;
53 return x;
54 }
55
56 public List!(SQLExpr) getColumns() {
57 return columns;
58 }
59
60 public void setColumns(List!(SQLExpr) columns) {
61 this.columns = columns;
62 }
63
64 public SQLExpr getAgainst() {
65 return against;
66 }
67
68 public void setAgainst(SQLExpr against) {
69 if (against !is null) {
70 against.setParent(this);
71 }
72 this.against = against;
73 }
74
75 public SearchModifier getSearchModifier() {
76 return searchModifier;
77 }
78
79 public void setSearchModifier(SearchModifier searchModifier) {
80 this.searchModifier = searchModifier;
81 }
82
83 public static struct SearchModifier {
84 enum SearchModifier IN_BOOLEAN_MODE = SearchModifier("IN BOOLEAN MODE"); //
85 enum SearchModifier IN_NATURAL_LANGUAGE_MODE = SearchModifier("IN NATURAL LANGUAGE MODE"); //
86 enum SearchModifier IN_NATURAL_LANGUAGE_MODE_WITH_QUERY_EXPANSION = SearchModifier("IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION");
87 enum SearchModifier WITH_QUERY_EXPANSION = SearchModifier("WITH QUERY EXPANSION");
88
89 public string name;
90 public string name_lcase;
91
92
93
94 this(string name){
95 this.name = name;
96 this.name_lcase = toLower(name);
97 }
98
99 bool opEquals(const SearchModifier h) nothrow {
100 return name == h.name ;
101 }
102
103 bool opEquals(ref const SearchModifier h) nothrow {
104 return name == h.name ;
105 }
106 }
107
108
109 override protected void accept0(SQLASTVisitor visitor) {
110 MySqlASTVisitor mysqlVisitor = cast(MySqlASTVisitor) visitor;
111 if (mysqlVisitor.visit(this)) {
112 acceptChild!SQLExpr(visitor, this.columns);
113 acceptChild(visitor, this.against);
114 }
115 mysqlVisitor.endVisit(this);
116 }
117
118 override
119 public List!SQLObject getChildren() {
120 List!(SQLObject) children = new ArrayList!(SQLObject)();
121 children.addAll(cast(List!SQLObject)(this.columns));
122 children.add(this.against);
123 return children;
124 }
125
126 override
127 public size_t toHash() @trusted nothrow {
128 int prime = 31;
129 size_t result = 1;
130 result = prime * result + ((against is null) ? 0 : (cast(Object)against).toHash());
131 result = prime * result + ((columns is null) ? 0 : (cast(Object)columns).toHash());
132 result = prime * result + hashOf(searchModifier);
133 return result;
134 }
135
136 override
137 public bool opEquals(Object obj) {
138 if (this == obj) {
139 return true;
140 }
141 if (obj is null) {
142 return false;
143 }
144 // if ( typeid(this) != typeid(obj)) {
145 // return false;
146 // }
147 MySqlMatchAgainstExpr other = cast(MySqlMatchAgainstExpr) obj;
148 if(other is null)
149 return false;
150 if (against is null) {
151 if (other.against !is null) {
152 return false;
153 }
154 } else if (!(cast(Object)(against)).opEquals(cast(Object)(other.against))) {
155 return false;
156 }
157 if (columns is null) {
158 if (other.columns !is null) {
159 return false;
160 }
161 } else if (!(cast(Object)(columns)).opEquals(cast(Object)(other.columns))) {
162 return false;
163 }
164 if (searchModifier != other.searchModifier) {
165 return false;
166 }
167 return true;
168 }
169
170 }