PDA

View Full Version : Problems escaping a search query in wiki.getsearch()



neilw
12-09-2008, 04:51 PM
I have a call to wiki.getsearch() that looks something like this:


var results=wiki.getsearch(searchTerm .. ' AND path:('.. searchPath ..')');


It failed because, as I eventually figured out, there were colons in searchPath, which the search engine Did Not Like. So I tried applying string.escape():


var results=wiki.getsearch(searchTerm .. ' AND path:('.. string.escape(searchPath) ..')');


This still fails; either string.escape() does not consider the colon to be an escapable character, or else the backslashes are getting swallowed somewhere. My eventual fix was to add


string.replace(searchPath, ':', '\\:')


However, this is a band-aid at best, and I simply wait to discover the next character that breaks the code.

So: is there any reliable way to escape the characters in a search query?

SteveB
12-11-2008, 01:40 AM
It would probably make sense to provide a string.escapesearch function which would take care of that for you. Please file a bug on it. Thanks.

neilw
12-11-2008, 09:18 PM
Bug filed (http://bugs.developer.mindtouch.com/view.php?id=5496).

bohappa
03-21-2009, 08:17 PM
I'm using wiki.getsearch successfully until I add a NOT clause to remove pages from the result set that exist in a specified path.
I want to make a list of pages tagged with XX and YY but not if they are in a specific location.
Why? I want to show two lists: 1. child pages for a given node, and 2. related pages (relation defined by tags).
To show pages in a given area, I use wiki.tree as these pages are closely associated with a given node. I want to define the related pages via wiki.getsearch.
I don't understand how to make NOT work with path: in the wiki.getsearch. The fact that this function is in a var makes it harder probably. Any suggestions?
I looked at the Advanced content searches pages but wasn't able to apply the examples to my case.



<p>Related Pages</p>
<div init="var ix = wiki.getsearch{query: 'tag:YY AND tag:XX NOT path:/KB_ROOT(KB_Root)/NODE1/NODE1A/' max: 200, sortby: '-date'} " style="width: 600px">
<div foreach="var p in ix">
<div style="margin-bottom: 1px; margin-left: 2px"><span style="font-size: 14px">
<li>{{web.link(p.uri, p.title); }}</li>
</span></div>
</div>
</div>

Any suggesions?