Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezquery.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezquery.php 8166 2001-11-01 15:32:45Z bf $
5 //
6 // Definition of eZQuery class
7 //
8 // Created on: <15-Sep-2000 14:40:06 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
53 class eZQuery
54 {
63 function __construct( $fields, $queryText, $single_string = false )
64 {
65 if ( !is_array( $fields ) )
66 $fields = array( $fields );
67 $this->Fields = $fields;
68 $this->QueryText = $queryText;
69 $this->SingleString = $single_string;
70 $this->Literal = false;
71 $this->PartialCompare = false;
72 $this->StopWordColumn = "";
73 $this->StopPercent = "0.5";
74 }
75
79 function buildQuery( )
80 {
81 $QueryText = $this->QueryText;
82 if ( is_array( $QueryText ) )
83 {
84 $queryArray = $QueryText;
85 if ( ( isset( $queryArray[0] ) and is_array( $queryArray[0] ) ) or
86 ( isset( $queryArray[1] ) and is_array( $queryArray[1] ) ) or
87 ( isset( $queryArray[2] ) and is_array( $queryArray[2] ) ) )
88 {
89 $normalArray = $queryArray[0];
90 $addArray = array();
91 $subArray = array();
92 if ( isset( $queryArray[1] ) and is_array( $queryArray[1] ) )
93 $addArray = $queryArray[1];
94 if ( isset( $queryArray[2] ) and is_array( $queryArray[2] ) )
95 $subArray = $queryArray[2];
96 }
97 }
98 else if ( $this->SingleString )
99 {
100 $queryArray = array( $QueryText );
101 }
102 else
103 {
104 $QueryText = trim( $QueryText );
105 $QueryText = preg_replace( '/\\\\"/', '"', $QueryText );
106 preg_match_all( "/((\"[^\"]+\")|([^ ]+))/", $QueryText, $m );
107 $queryArray = array();
108 foreach( $m[0] as $match )
109 {
110 $queryArray[] = $match;
111 }
112 }
113 if ( count( $queryArray ) == 0 )
114 $queryArray[] = "";
115
116 if ( $this->Literal )
117 {
118 $normalArray = $queryArray;
119 $addArray = array();
120 $subArray = array();
121 }
122 else if ( !isset( $normalArray ) and !isset( $addArray ) and !isset( $subArray ) )
123 {
124 $normalArray = array();
125 $addArray = array();
126 $subArray = array();
127 foreach( $queryArray as $queryItem )
128 {
129 switch ( $queryItem[0] )
130 {
131 case '-':
132 {
133 $subArray[] = substr( $queryItem, 1 );
134 break;
135 }
136 case '+':
137 {
138 $addArray[] = substr( $queryItem, 1 );
139 break;
140 }
141 default:
142 {
143 $normalArray[] = $queryItem;
144 }
145 }
146 }
147 }
148
149 $like = $this->PartialCompare ? "LIKE" : "=";
150 $not_like = $this->PartialCompare ? "LIKE" : "!=";
151
152 $arrs = array( array( "array" => "normalArray", "item_delim" => "OR",
153 "delim" => $this->PartialCompare ? "AND" : "OR", "compare" => $like ),
154 array( "array" => "addArray", "item_delim" => "OR",
155 "delim" => "AND", "compare" => $like ),
156 array( "array" => "subArray", "item_delim" => "AND",
157 "delim" => "AND", "compare" => $not_like ) );
158
159 $partial_sign = $this->PartialCompare ? "%" : "";
160
161 $total_query = "";
162 foreach( $arrs as $arr )
163 {
164 $queryArray = ${$arr["array"]};
165 $item_delim = $arr["item_delim"];
166 $delim = $arr["delim"];
167 $compare = $arr["compare"];
168 $query = "";
169 for ( $i=0; $i<count($queryArray); $i++ )
170 {
171 $queryVal = $queryArray[$i];
172 if ( strlen( $queryVal ) > 1 and $queryVal[0] == '"' and $queryVal[strlen($queryVal)-1] == '"' )
173 {
174 $queryVal = substr( $queryVal, 1, strlen( $queryVal ) - 2 );
175 }
176
177 $subquery = "";
178 for ( $j=0; $j<count($this->Fields); $j++ )
179 {
180 $queryItem = $queryVal;
181
182 $queryItem = $this->Fields[$j] ." $compare '$partial_sign" . $queryItem . "$partial_sign' ";
183
184 if ( $j > 0 )
185 $queryItem = $item_delim . " " . $queryItem . " ";
186
187 if ( $this->StopWordColumn != "" )
188 $subquery .= "(". $queryItem . " AND $this->StopWordColumn < '$this->StopPercent' )";
189 else
190 $subquery .= $queryItem;
191
192 }
193 $query .= "( $subquery )";
194
195 if ( count( $queryArray) != ($i+1) )
196 $query .= " $delim ";
197 }
198 if ( count( $queryArray ) )
199 {
200 if ( !empty( $total_query ) )
201 {
202 $total_query = "$total_query $delim ( $query )";
203 }
204 else
205 {
206 $total_query = "( $query )";
207 }
208 }
209 }
210 return $total_query;
211 }
212
217 function isLiteral()
218 {
219 return $this->Literal;
220 }
221
225 function partialCompare()
226 {
227 return $this->PartialCompare;
228 }
229
233 function setIsLiteral( $literal )
234 {
235 $this->Literal = $literal;
236 }
237
241 function setPartialCompare( $partial )
242 {
243 $this->PartialCompare = $partial;
244 }
245
250 function setStopWordColumn( $value )
251 {
252 $this->StopWordColumn = $value;
253 }
254
259 function setStopWordPercent( $value )
260 {
261 $this->StopPercent = $value;
262 }
263
264 var $Fields;
265 var $QueryText;
266 var $IsLiteral;
267 var $PartialCompare;
268
269 var $StopWordColumn;
270 var $StopPercent;
271
272 var $SingleString;
273 var $Literal;
274 }
275
276 ?>
$i
$i
Definition: admin/adlist.php:91
eZQuery
Definition: ezquery.php:54
eZQuery\$StopPercent
$StopPercent
Definition: ezquery.php:270
eZQuery\setIsLiteral
setIsLiteral( $literal)
Definition: ezquery.php:233
eZQuery\$SingleString
$SingleString
Definition: ezquery.php:272
eZQuery\$QueryText
$QueryText
Definition: ezquery.php:265
eZQuery\setStopWordColumn
setStopWordColumn( $value)
Definition: ezquery.php:250
eZQuery\partialCompare
partialCompare()
Definition: ezquery.php:225
eZQuery\setPartialCompare
setPartialCompare( $partial)
Definition: ezquery.php:241
eZQuery\$PartialCompare
$PartialCompare
Definition: ezquery.php:267
eZQuery\__construct
__construct( $fields, $queryText, $single_string=false)
Definition: ezquery.php:63
eZQuery\$Fields
$Fields
Definition: ezquery.php:264
eZQuery\$IsLiteral
$IsLiteral
Definition: ezquery.php:266
eZQuery\setStopWordPercent
setStopWordPercent( $value)
Definition: ezquery.php:259
eZQuery\$StopWordColumn
$StopWordColumn
Definition: ezquery.php:269
eZQuery\$Literal
$Literal
Definition: ezquery.php:273
eZQuery\buildQuery
buildQuery()
Definition: ezquery.php:79
eZQuery\isLiteral
isLiteral()
Definition: ezquery.php:217
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$j
$j
Definition: ezimagecatalogue/admin/imagelist.php:345
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.