<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
<font style="font-size:10pt;" color="#366092" face="Arial" size="2">Hi Michel,<br><br><font style="font-size: 10pt;" size="2">Man<font style="font-size: 10pt;" size="2">y thanks for your answe<font style="font-size: 10pt;" size="2">r, <font style="font-size: 10pt;" size="2">that <font style="font-size: 10pt;" size="2">session.query </font>works well in GA, </font></font></font></font>f<font style="font-size: 10pt;" size="2">or that I had to define a class TsVector for the tsvector ty<font style="font-size: 10pt;" size="2">pe</font> first<font style="font-size: 10pt;" size="2">, and after assi<font style="font-size: 10pt;" size="2">g<font style="font-size: 10pt;" size="2"><font style="font-size: 10pt;" size="2">ning</font> it to </font></font></font></font>my tsvector column (<font style="font-size: 10pt;" size="2">ts in my table), I run that line as p<font style="font-size: 10pt;" size="2">art of my model.p<font style="font-size: 10pt;" size="2">y (p<font style="font-size: 10pt;" size="2">ython my_model.py</font></font></font></font>). I just tried your suggestion, but <font style="font-size: 10pt;" size="2">with no much luc<font style="font-size: 10pt;" size="2">k</font></font>:<br><br><font style="font-size: 10pt;" size="2">http://www.web.web/fs/Boreholes?format=GeoJSON&ts__ilike=ODP&queryable=ts</font><br><br>using:<br><br>*** GeoAlchemy.py.bk    2012-12-15 23:15:46.000000000 +0100<br>--- GeoAlchemy.py       2012-12-19 20:41:32.000000000 +0100<br>***************<br>*** 57,65 ****<br>  <br>      def feature_predicate(self, key, operator_name, value):<br>          if operator_name == 'like':<br>!             return key.like('%'+value+'%')<br>          elif operator_name == 'ilike':<br>!             return key.ilike('%'+value+'%')<br>          else:<br>              return self.query_operators[operator_name](key,value)<br>  <br>--- 57,65 ----<br>  <br>      def feature_predicate(self, key, operator_name, value):<br>          if operator_name == 'like':<br>!             return key.ts.op('@@')(func.to_tsquery("value"))<br>          elif operator_name == 'ilike':<br>!             return key.ts.op('@@')(func.to_tsquery("value"))<br>          else:<br>              return self.query_operators[operator_name](key,value)<br><br>the error is similar to the<font style="font-size: 10pt;" size="2"> one in my last email</font><font style="font-size: 10pt;" size="2">:</font></font><br id="FontBreak"><pre>An error occurred: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Boreholes.ts has an attribute 'ts'
  File "/var/www/html/mop/fs/web_request/handlers.py", line 230, in cgi
    accepts = accepts )
  File "/var/www/html/mop/fs/FeatureServer/Server.py", line 245, in dispatchRequest
    result = method(action)
  File "/var/www/html/mop/fs/FeatureServer/DataSource/GeoAlchemy.py", line 159, in select
    for k, v in action.attributes.iteritems()]
  File "/var/www/html/mop/fs/FeatureServer/DataSource/GeoAlchemy.py", line 62, in feature_predicate
    return key.ts.op('@@')(func.to_tsquery("value"))
  File "/usr/lib/python2.6/site-packages/sqlalchemy/orm/attributes.py", line 211, in __getattr__
    key)


{'queryable': 'ts', 'ts__ilike': 'ODP', 'format': 'GeoJSON'}</pre><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br>I<font style="font-size: 10pt;" size="2"> think somet<font style="font-size: 10pt;" size="2">hing else <font style="font-size: 10pt;" size="2">is necessary</font></font></font> but no idea what it is. Thanks <font style="font-size: 10pt;" size="2">for putting this in your todo list, one question<font style="font-size: 10pt;" size="2">, <font style="font-size: 10pt;" size="2">do you <font style="font-size: 10pt;" size="2">have <font style="font-size: 10pt;" size="2">a date for <font style="font-size: 10pt;" size="2">FS </font><font style="font-size: 10pt;" size="2">2.0?</font></font></font></font></font><br><br><font style="font-size: 10pt;" size="2">Cheers,<br><br><font style="font-size: 10pt;" size="2">Gery</font><br></font><br></font>__________________________________________________________________________________________<br>Piensa en el medio ambie<font style="" face="Arial">nte - mantenlo en la pantalla. NO lo imprimas si NO es necesario.</font></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2">Think green - keep it on the screen. Do NOT print if it is NOT necessary.</font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><span id="ecxresult_box" class="ecxshort_text" lang="de"><span class="ecxhps">Denken Sie an</span> <span class="ecxhps">die Umwelt</span></span></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><span id="ecxresult_box" lang="de"><span class="ecxhps"></span> <span class="ecxhps">-</span> <span class="ecxhps">bewahren Sie es</span> <span class="ecxhps">auf dem Bildschirm.</span> <span class="ecxhps">Drucken Sie NICHT</span><span>, wenn</span> <span class="ecxhps">es NICHT notwendig ist</span><span>.</span></span></font><br><br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">Subject: Re: [FeatureServer] query using tsvector<br>From: michel.ott@me.com<br>Date: Wed, 19 Dec 2012 14:12:30 +0100<br>CC: featureserver@lists.osgeo.org<br>To: gamejihou@hotmail.com<br><br><div>Hi Gery</div><div><br></div><div>Your wrote that in GA it should look like this:</div><div><blockquote><span style="font-family:Tahoma;font-size:13px">session.query(Boreholes).filter(Boreholes.tsvector.op('@@')(func.to_tsquery("ODP"))).all()</span><font style="font-family:Tahoma;font-size:10pt" size="2">"</font></blockquote></div><div><br></div><div>what if you change your plainto_tsquery to the same appearance as in your filter() example above? Something like the following line:</div><div><font face="Courier">key.tsvector.op('@@')(func.to_tsquery("value"))</font></div><div><br></div><div>Cheers</div><div>Michel</div><div><br></div><div>P.S.: I should put this on my todo list for release 2.0</div><div><br></div><div><br></div><div><br></div><br><div><div>On Dec 19, 2012, at 12:22 PM, Gery . <<a href="mailto:gamejihou@hotmail.com">gamejihou@hotmail.com</a>> wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div class="ecxhmmessage" style="font-size:10pt;font-family:Tahoma;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px"><div dir="ltr"><font style="font-size:10pt" color="#366092" face="Arial" size="2">I've been<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">changing the GeoAlche<font style="font-size:10pt" size="2">my<font style="font-size:10pt" size="2">.py a bit in this way,in order to keep using the operator 'ilike' but as plain<font style="font-size:10pt" size="2">to_tsquery</font>:<br><br>*** GeoAlchemy.py.bk    2012-12-15 23:15:46.000000000 +0100<br>--- GeoAlchemy.py       2012-12-19 12:00:13.000000000 +0100<br>***************<br>*** 57,65 ****<br> <span class="ecxApple-converted-space"> </span><br>      def feature_predicate(self, key, operator_name, value):<br>          if operator_name == 'like':<br>!             return key.like('%'+value+'%')<br>          elif operator_name == 'ilike':<br>!             return key.ilike('%'+value+'%')<br>          else:<br>              return self.query_operators[operator_name](key,value)<br> <span class="ecxApple-converted-space"> </span><br>--- 57,65 ----<br> <span class="ecxApple-converted-space"> </span><br>      def feature_predicate(self, key, operator_name, value):<br>          if operator_name == 'like':<br>!             return key.plainto_tsquery(''+value+'')<br>          elif operator_name == 'ilike':<br>!             return key.plainto_tsquery(''+value+'')<br>          else:<br>              return self.query_operators[operator_name](key,value)<br><br>and using the same call but wit<font style="font-size:10pt" size="2">h the tsvector column</font><span class="ecxApple-converted-space"> </span>(ie.<span class="ecxApple-converted-space"> </span></font></font></font></font><font style="font-size:10pt" color="#366092" face="Arial" size="2"><a href="http://www.myweb.web/fs/Boreholes?format=GeoJSON&ts__ilike=ODP&queryable=ts" target="_blank">http://www.myweb.web/fs/Boreholes?format=GeoJSON&ts__ilike=ODP&queryable=ts</a>), I get this:</font><br id="ecxFontBreak"><pre>An error occurred: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Boreholes.ts has an attribute 'plainto_tsquery'
  File "/var/www/html/mop/fs/web_request/handlers.py", line 230, in cgi
    accepts = accepts )
  File "/var/www/html/mop/fs/FeatureServer/Server.py", line 245, in dispatchRequest
    result = method(action)
  File "/var/www/html/mop/fs/FeatureServer/DataSource/GeoAlchemy.py", line 159, in select
    for k, v in action.attributes.iteritems()]
  File "/var/www/html/mop/fs/FeatureServer/DataSource/GeoAlchemy.py", line 62, in feature_predicate
    return key.plainto_tsquery(''+value+'')
  File "/usr/lib/python2.6/site-packages/sqlalchemy/orm/attributes.py", line 211, in __getattr__
    key)


{'queryable': 'ts', 'ts__ilike': 'ODP', 'format': 'GeoJSON'}
</pre><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><font style="font-size:10pt" size="2">if I add "<font style="font-size:10pt" size="2">@@<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>plainto_tsquery" instead, it gives a syntax er<font style="font-size:10pt" size="2">ror in t<font style="font-size:10pt" size="2">he fs_error<font style="font-size:10pt" size="2">.log.<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">My idea is to replace<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">only</font></font><span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">the return of<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>the</font>'ilike'<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span></font>or 'like' operators (<font style="font-size:10pt" size="2">a<font style="font-size:10pt" size="2">nd not the name itsel<font style="font-size:10pt" size="2">f)</font></font></font><span class="ecxApple-converted-space"> </span>and use inst<font style="font-size:10pt" size="2">ead the '@@ plainto_<font style="font-size:10pt" size="2">tsquery</font></font></font></font></font></font></font></font></font></font></font><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"></font></font>', so I can keep using the same call<font style="font-size:10pt" size="2">, ie<font style="font-size:10pt" size="2">:<br></font></font><br><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" color="#366092" face="Arial" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><a href="http://www.myweb.web/fs/Boreholes?format=GeoJSON&ts__ilike=ODP&queryable=ts" target="_blank">http://www.myweb.web/fs/Boreholes?format=GeoJSON&ts__ilike=ODP&queryable=ts</a></font></font></font></font></font></font></font></font></font></font><br><br><font style="font-size:10pt" size="2">so,<br><br></font>it calls in<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">SQL</font><span class="ecxApple-converted-space"> </span>(actually this<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">doesn'<font style="font-size:10pt" size="2">t work in postgresql/postgis<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">for tsvector<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">type</font></font><span class="ecxApple-converted-space"> </span>"ERROR:  operator does not exist: tsvector ~~* unknown)</font>:<br>select * from<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>b<font style="font-size:10pt" size="2">o<font style="font-size:10pt" size="2">reholes_table where ts ilike '%ODP%';</font></font></font><br><br><font style="font-size:10pt" size="2">and with the ch<font style="font-size:10pt" size="2">ange above<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">(doesn<font style="font-size:10pt" size="2">'t work so far)<font style="font-size:10pt" size="2">, should call (this works in postgresql/postgis):</font></font></font><br><font style="font-size:10pt" size="2">select * from boreholes_<font style="font-size:10pt" size="2">table where ts @@ p<font style="font-size:10pt" size="2">lainto_tsquer<font style="font-size:10pt" size="2">y('ODP');</font></font></font><br><br><font style="font-size:10pt" size="2">Thanks in advance for any hint on this,<br><br></font><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"></font></font></font>Gery<br>__________________________________________________________________________________________<br>Piensa en el medio ambie<font face="Arial">nte - mantenlo en la pantalla. NO lo imprimas si NO es necesario.</font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2">Think green - keep it on the screen. Do NOT print if it is NOT necessary.</font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><span id="ecxresult_box" class="ecxshort_text" lang="de"><span class="ecxhps">Denken Sie an</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">die Umwelt</span></span></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><span id="ecxresult_box" lang="de"><span class="ecxhps"></span> <span class="ecxhps">-</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">bewahren Sie es</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">auf dem Bildschirm.</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">Drucken Sie NICHT</span><span>, wenn</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">es NICHT notwendig ist</span><span>.</span></span></font><br><br><br><div><div id="ecxSkyDrivePlaceholder"></div><hr id="ecxstopSpelling">From: <a href="mailto:gamejihou@hotmail.com">gamejihou@hotmail.com</a><br>To: <a href="mailto:featureserver@lists.osgeo.org">featureserver@lists.osgeo.org</a>; <a href="mailto:iocast@me.com">iocast@me.com</a><br>Subject: query using tsvector<br>Date: Tue, 18 Dec 2012 16:02:17 +0000<br><br><div dir="ltr"><font style="font-size:10pt" color="#366092" face="Arial" size="2">Hello,<br><br><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2">I've<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2">been</font><span class="ecxApple-converted-space"> </span>testing<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">FS<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">with G<font style="font-size:10pt" size="2">A and<span class="ecxApple-converted-space"> </span></font></font></font></font></font></font></font></font>fou<font style="font-size:10pt" size="2">nd somethi<font style="font-size:10pt" size="2">ng that don't get how to pu<font style="font-size:10pt" size="2">t it.<br><br>For instance, this call works very well in FS:<br><br><font style="font-size:10pt" size="2">F<font style="font-size:10pt" size="2">irst example:</font></font><br>[code]<br>in FS<font style="font-size:10pt" size="2">:<span class="ecxApple-converted-space"> </span></font><a href="http://www.myweb.web/fs/Boreholes?format=GeoJSON&source__ilike=ODP&queryable=source" target="_blank">http://www.myweb.web/fs/Boreholes?format=GeoJSON&source__ilike=ODP&queryable=source</a><br>in SQL:<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">SELECT *<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">FROM bor<font style="font-size:10pt" size="2">e<font style="font-size:10pt" size="2">holes_table<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">wh<font style="font-size:10pt" size="2">e<font style="font-size:10pt" size="2">re source ilike '%ODP%'<br><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"></font></font><font style="font-size:10pt" size="2">[/code]<br><br>and<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>what I'm looking f<font style="font-size:10pt" size="2">or<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">is quer<font style="font-size:10pt" size="2">ying this table but using the t<font style="font-size:10pt" size="2">svector column,<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>so</font></font></font><span class="ecxApple-converted-space"> </span>this works in SQL but don't know how to<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">put it in FS:<br><br><font style="font-size:10pt" size="2">Second example:</font><br><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"></font>[code]<br><font style="font-size:10pt" size="2">in<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>FS: ??<br><font style="font-size:10pt" size="2">in SQL: select * from boreholes_<font style="font-size:10pt" size="2">table</font><span class="ecxApple-converted-space"> </span>where tsvector @@ plainto_tsquery('ODP');<br><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2">(in an<font style="font-size:10pt" size="2">y cas<font style="font-size:10pt" size="2">e this is for</font></font></font><font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>GA: "</font>session.query(Boreholes).filter(Boreholes.tsvector.op('@@')(func.to_tsquery("ODP"))).all()<font style="font-size:10pt" size="2">"</font>)<br><font style="font-size:10pt" size="2">[<font style="font-size:10pt" size="2">/code]<br><br><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2"><font style="font-size:10pt" size="2">based on the first SQL (and FS)<span class="ecxApple-converted-space"> </span></font></font></font>example, how co<font style="font-size:10pt" size="2">uld I put<font style="font-size:10pt" size="2"><span class="ecxApple-converted-space"> </span>it for the second<span class="ecxApple-converted-space"> </span></font></font>SQL exa<font style="font-size:10pt" size="2">mple?</font><br><br><font style="font-size:10pt" size="2">Any hint<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">is apprec<font style="font-size:10pt" size="2">iated,<span class="ecxApple-converted-space"> </span><font style="font-size:10pt" size="2">t</font></font></font>hanks in advance,<br><br><font style="font-size:10pt" size="2">Best regards,<br><br><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2">__________________________________________________________________________________________<br>Piensa en el medio ambie<font face="Arial">nte - mantenlo en la pantalla. NO lo imprimas si NO es necesario.</font></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2">Think green - keep it on the screen. Do NOT print if it is NOT necessary.</font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><br></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><span id="ecxresult_box" class="ecxshort_text" lang="de"><span class="ecxhps">Denken Sie an</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">die Umwelt</span></span></font><font style="font-size:10pt" color="#1F497D" face="Arial" size="2"><span id="ecxresult_box" lang="de"><span class="ecxhps"></span> <span class="ecxhps">-</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">bewahren Sie es</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">auf dem Bildschirm.</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">Drucken Sie NICHT</span><span>, wenn</span><span class="ecxApple-converted-space"> </span><span class="ecxhps">es NICHT notwendig ist</span><span>.</span></span></font><br></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></div></div></font></font></font></font></font></div>_______________________________________________<br>FeatureServer mailing list<br><a href="mailto:FeatureServer@lists.osgeo.org">FeatureServer@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/featureserver" target="_blank">http://lists.osgeo.org/mailman/listinfo/featureserver</a></div></blockquote></div><br></div>                                           </div></body>
</html>