This question about Topic Markup Language and applications: Answered

How to search for multiple tag values in a field

I created simple form to store topic tags:

<input type="text" name="tags" class="foswikiInputField" size="32" >

My search query is as follows:

 "Keywords ~ '*%URLPARAM{"tags" encode="quote"}%*'" 
 format="| [[$web.$topic][$web.$topic]]   | $formfield(Keywords)    | $formfield(ShortDescription)    |"

so I am not searching for exact tag, but something which is like my tag. Is there any better way to do that?

-- MateuszKDzior - 02 Mar 2015

I need to check a couple of points to make sure I'm following your question. You indicated that you created a simple form to store topic tags, but you presented an html form element which looks like it would be used as part of a search form. Here's what I think your saying:
  • You have a DataForms with field called "Keywords".
  • You have an html search form with the field you presented above. It would allow entry of one or more "tags", separated by spaces or commas (more on this below).
  • The search you looking for would return any topics that contain any of the tags entered in the search form within the Keywords field.

OK, if these assumptions are correct, you'd need to make a couple of changes to your search:
  • We need to accomplish an "OR" search for each of the entered tags. The search you presented above would only work if the topic had exactly the same tags in the same order as entered in the search form.
  • In order to format the search for each individual tag entered, this we need to know how to delineate the individual tags.
  • If we required entering commas between each of the tags, we could use the VarFORMAT macro to format the search query string: %FORMAT{"%URLPARAM{tag}%" type="string" format="Keyword ~ '*$item*'" separator=" OR "}% .
  • Perhaps a more intuitive approach would be to treat each word as separate tag (i.e. use space as delineator). This would require use of FilterPlugin (because VarFORMAT doesn't allow for space-delineated list) but basically follows the same approach to format the query string: %FORMATLIST{"%URLPARAM{tag}%" split=" " format="Keyword ~ '*$1*'" separator=" OR "}% .

I don't think you'd need to encode the URLPARAM unless you anticipate users would insert single or double quotes in the tag field.

Let me know if I'm off base or if you have further questions.

-- LynnwoodBrown - 04 Mar 2015

QuestionForm edit

Subject Topic Markup Language and applications
Status Answered
Related Topics
Topic revision: r3 - 04 Mar 2015, LynnwoodBrown - This page was cached on 21 Feb 2019 - 02:57.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy