[Geomoose-users] Query.PhP Code Update Suggestions

Eli Adam eadam at co.lincoln.or.us
Thu Jan 23 17:50:29 PST 2014


Here is the same code but in patch form.   (this is mostly just to
link to this on the email list)

Eli

On Tue, Sep 24, 2013 at 12:37 PM, Anderson, Dean
<anderson.dean at co.polk.or.us> wrote:
> Not sure who this goes to as I do not have access to github (new firewall
> stuff going on) .  My programmer Bryce made these fixes for me so thought I
> would share them as I REALLY like them.
>
> Attached you will find a new query.php.  It contains two changes to the
> standard 2.6.1 MS4W query.php code.
>
> 1. A fix to the "IN" comparitor - Changed the delimiter to ";" as spaces and
> "," are used in search strings, removed extra spaces, removed case issues.
>
> 2. Added a NEW comparitor - "LikeAll"  - This is a special comparitor that
> will match all contents of an entered string as separated by spaces.  So if
> I am searching for Dean Anderson as Owner and my owner name as stored in the
> database is "Anderson Dean et al' it will find it.  This is also much more
> like how google searches.  Finally, this works great for search of addresses
> as you can search for "202 washington" and not have to remember if it is a
> street or if it has a directions associated with it.
>
> To reference this in the mapbook.xml use: <option value="like-all">Match
> All</option>
>
> The query.php has the extra lines of code commented (Bryce Choi - Polk Co.
> 9-23-13) so they should be easy to find.
>
> --
> Dean R Anderson
> IT Director
> Polk County
>
> _______________________________________________
> Geomoose-users mailing list
> Geomoose-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geomoose-users
-------------- next part --------------
79a80
> /* - ORIGINAL FROM GEOMOOSE 2.6 
101a103,177
> */
> # modified by Bryce Choi - Polk Co. 9-23-13 - To fix some issues extra spaces and case depandencies 
> class InComparitor {
> 
> 	protected $p = array();
> 	public function __construct() {
> 		$this->p['delim'] = ';';
> 	}
> 
> 	public function setDelim($d) {
> 		$this->p['delim'] = $d;
> 	}
> 
> 	public function convert_value($value, $out_delim) {
> 		$vals = explode($this->p['delim'], $value);
> 		for($i = 0; $i < count($vals); $i++) {
> 			$vals[$i] = trim($vals[$i]); # remove any white space in the value
> 		}
> 		return strtoupper(implode($out_delim, $vals));
> 	}
> 
> 	public function toMapServer($field_name, $value) {
> 		# this one is used for the webmap
> 		return sprintf('"[%s]" in "%s"', $field_name, $this->convert_value($value, ","));
> 	}
> 
> 	public function toSQL($field_name, $value) {
> 		return sprintf("%s in ('%s')", $field_name, $this->convert_value($value, "','"));
> 	}
> }
> 
> # New LikeALL camparitor - Bryce Choi - Polk Co. 9-23-13 
> 
> class LikeAllComparitor {
> 	protected $p = array();
> 	public function __construct() {
> 		$this->p['delim'] = ' ';
> 	}
> 
> 	public function setDelim($d) {
> 		$this->p['delim'] = $d;
> 	}
> 
> 	public function toMapServer($field_name, $value) {
> 		##return sprintf('"[%s]" ~* "%s" AND "[%s]" ~* "%s"', strtoupper($field_name), $value, strtoupper($field_name), 'COOPER');
> 		##return '"[' . strtoupper($field_name) . ']" ~* "' . strtoupper($value) . '" AND "[' . strtoupper($field_name) . ']" ~* "' . 'COOPER' . '"';
> 		
> 		$vals = explode($this->p['delim'], $value);
> 		$stmt = ""; # query statement
> 		$i = 0;
> 		for(; $i < count($vals) - 1; $i++) {
> 			$vals[$i] = trim($vals[$i]); # remove any white space in the value
> 			$stmt .= '"[' . strtoupper($field_name) . ']" ~* "' . strtoupper($vals[$i]) . '" AND ';
> 		}
> 		$vals[$i] = trim($vals[$i]); # remove any white space in the value
> 		$stmt .= '"[' . strtoupper($field_name) . ']" ~* "' . strtoupper($vals[$i]) . '"';
> 		return $stmt;
> 	}
> 
> 	public function toSQL($field_name, $value) {		
> 		$vals = explode($this->p['delim'], $value);
> 		$stmt = ""; # query statement
> 		$i = 0;
> 		for(; $i < count($vals) - 1; $i++) {
> 			$vals[$i] = trim($vals[$i]); # remove any white space in the value
> 			# upper(%s) like '%%'||upper('%s')||'%%'
> 			$stmt .= strtoupper($field_name) . " like '%%'||'" . strtoupper($vals[$i]) . "'||'%%' AND ";
> 		}
> 		$vals[$i] = trim($vals[$i]); # remove any white space in the value
> 		$stmt .= strtoupper($field_name) . " like '%%'||'" . strtoupper($vals[$i]) . "'||'%%'";
> 		return $stmt;
> 	}
> }
> 
> 
122a199,202
> 
> # Added in for like all function - Bryce Choi - 9-23-13 
> 
> $comparitors['like-all'] = new LikeAllComparitor();


More information about the Geomoose-users mailing list