@@ -79,6 +79,7 @@ def validate_tokens(
7979 self .check_unbalanced_parentheses ()
8080 self .add_artificial_parentheses_for_operator_precedence ()
8181 self .check_operator_capitalization ()
82+ self .check_invalid_near_within_operators ()
8283
8384 self .check_search_field_general ()
8485 return self .tokens
@@ -111,6 +112,37 @@ def check_invalid_syntax(self) -> None:
111112 f"'{ match .group (0 )} ' is invalid." ,
112113 )
113114
115+ def check_invalid_near_within_operators (self ) -> None :
116+ """
117+ Check for invalid NEAR and WITHIN operators in the query.
118+ EBSCO does not support NEAR and WITHIN operators.
119+ """
120+
121+ for token in self .tokens :
122+ if token .type == TokenTypes .PROXIMITY_OPERATOR :
123+ if token .value .startswith ("NEAR" ):
124+ details = (
125+ f"Operator { token .value } "
126+ "is not supported by EBSCO. Must be N/x instead."
127+ )
128+ self .add_linter_message (
129+ QueryErrorCode .INVALID_PROXIMITY_USE ,
130+ positions = [token .position ],
131+ details = details ,
132+ )
133+ token .value = token .value .replace ("NEAR/" , "N" )
134+ if token .value .startswith ("WITHIN" ):
135+ details = (
136+ f"Operator { token .value } "
137+ "is not supported by EBSCO. Must be W/x instead."
138+ )
139+ self .add_linter_message (
140+ QueryErrorCode .INVALID_PROXIMITY_USE ,
141+ positions = [token .position ],
142+ details = details ,
143+ )
144+ token .value = token .value .replace ("WITHIN/" , "W" )
145+
114146 def check_search_field_general (self ) -> None :
115147 """Check field 'Search Fields' in content."""
116148
@@ -206,6 +238,37 @@ def check_invalid_token_sequences(self) -> None:
206238 details = f"Cannot end with { self .tokens [- 1 ].type .value } " ,
207239 )
208240
241+ def check_invalid_near_within_operators_query (self , query : Query ) -> None :
242+ """
243+ Check for invalid NEAR and WITHIN operators in the query.
244+ EBSCO does not support NEAR and WITHIN operators.
245+ """
246+ if query .operator :
247+ if query .value .startswith ("NEAR" ):
248+ details = (
249+ f"Operator { query .value } "
250+ "is not supported by EBSCO. Must be N/x instead."
251+ )
252+ self .add_linter_message (
253+ QueryErrorCode .INVALID_PROXIMITY_USE ,
254+ positions = [query .position or (- 1 , - 1 )],
255+ details = details ,
256+ )
257+
258+ if query .value .startswith ("WITHIN" ):
259+ details = (
260+ f"Operator { query .value } "
261+ "is not supported by EBSCO. Must be W/x instead."
262+ )
263+ self .add_linter_message (
264+ QueryErrorCode .INVALID_PROXIMITY_USE ,
265+ positions = [query .position or (- 1 , - 1 )],
266+ details = details ,
267+ )
268+
269+ for child in query .children :
270+ self .check_invalid_near_within_operators_query (child )
271+
209272 def validate_query_tree (self , query : Query ) -> None :
210273 """
211274 Validate the query tree.
0 commit comments