This question about Topic Markup Language and applications: Answered

Find sequence over mutliple lines


My Topic has several tables like this:

---++ ThisTable1
| foo |  foo  | foo |  done |
| foo |  foo  | foo | todo |
| foo |  foo  | foo |  done |
---++ ThisTable2
| foo  | foo |  foo |  todo |
| foo | foo  | foo | todo |
| foo |  foo  | foo  | done |
| foo  | foo |  foo |  done |
| foo | foo  | foo | done |
| foo |  foo  | foo  | done |

...(and so on)

I would like to use a query search to find out a certain table (e.g. ThisTable1) has the entry "todo".

I started with
%SEARCH{ "$text ~ ' *SOT=ThisTable1*| todo |*EOT=ThisTable1*  "
topic = "%TOPIC%
Scope = "text"

But there is no result.

Any idea?

I want to use this information to either show choice-yes or choice-no in the headline.

Thank you for you help.

-- MartenLucas - 19 Dec 2016

I tried to solve this question and wasn't successful and it bugs me. There are some things I'll suggest and see if someone else can come up with an answer.

First, I'll point out a few basic issues in your SEARCH macro:
  • In the search string $text should just be text. Also, there needs to be a closing single quote delineating the string to match.
  • The parameters topic and scope shouldn't be capitalized and should not have the spaces before and after equal sign.
  • The topic parameter is lacking a closing double quote.
  • If the search returns no results, nothing is displayed (including no footer). To display an icon for no results, I'd use the zeroresults parameter.

Making these corrections, I was able to get a positive result and was all pleased, but then I realized that this was because I was finding my own search string since it was in the same topic as being searched. To avoid this, I would recommend using a regex search and add square brackets about some letters to avoid the search finding itself.

Putting this all together (plus some code to display the icons you mentioned), this is what I come up with:

...but alas it doesn't work and I don't know why. Perhaps it's because the regex search string has to span multiple lines?

I'd love to hear some more comments on this little puzzle.

-- LynnwoodBrown - 21 Dec 2016

I think you've identified the issue. The SEARCH code internally first splits the topic into lines and applies the pattern to each line. So a multi-line match isn't going to work. At least that's how I read the code in

-- GeorgeClark - 22 Dec 2016

I could not come up with a way to put it into the table title, but you can get a conditional checkbox in the table by using the SpreadSheetPlugin. (Be sure to set the ALLOWHTML switch so that the CALC macro can emit HTML.) I also used a $SET / $GET variable to put the flag below the table. But the SpreadSheetPlugin can't move backwards in the page.

For ex;
| | | | %CALC{"$SET(T1,$IF($COUNTSTR($ABOVE(),todo), %ICON{choice-no}%, %ICON{choice-yes}% ))"}% |

Table 1

foo foo foo done
foo foo foo todo

Status of Table 1 choice-no

foo foo foo done
foo foo foo done

Status of Table 2 choice-yes

-- GeorgeClark - 22 Dec 2016

Goes like this using FilterPlugin:



foo foo foo done
foo foo foo todo
foo foo foo done

-- Main.MichaelDaum - 22 Dec 2016

Curious mixture of search techniques being used above. Simplest is to correct OP's search, thus:
%SEARCH{ "text ~ '*SOT=ThisTable1*| todo |*EOT=ThisTable1*'" type="query" topic="%TOPIC%"}%

which gets you:

Searched: text ~ '*SOT=ThisTable1*| todo |*EOT=ThisTable1*'

Results from Support web retrieved at 21:45 (GMT)

Hi, My Topic has several tables like this: ThisTable1 foo foo foo done foo foo foo todo foo foo foo done ThisTable2 foo ...
Number of topics: 1

-- Main.CrawfordCurrie - 22 Dec 2016 - 09:00

Sorry Crawford - the reason why your search works is that it's finding it's own search string, not the table. To demonstrate, here's the same search but targeting a separate topic containing only the tables:
Searched: text ~ '*SOT=ThisTable1*| todo |*EOT=ThisTable1*'
Number of topics: 0

I like Michaels approach but it doesn't exactly answer Marten's question. He's not asking to extract the table, he's asking to determine whether the table has a row that contains "todo". Here's a variation that achieves what Marten ask for, including displaying the icons:

  • Table 1 (containing 1 todo): choice-yes
  • Table 2 (containing 2 todos): choice-yes
  • Table 3 (containing no todos): choice-no

Thanks George for confirming that searches (either regex or query) can only search over single lines of text at one time. What's odd is that I don't remember it always working like that but perhaps I'm wrong. It's good to know that FilterPlugin 's EXTRACT macro can do this as I would think the need to search over multiple lines would come up with some regularity.

-- Main.LynnwoodBrown - 22 Dec 2016


QuestionForm edit

Subject Topic Markup Language and applications
Version Foswiki 1.0.6
Status Answered
Related Topics
Topic revision: r8 - 22 Dec 2016, LynnwoodBrown - This page was cached on 28 Mar 2017 - 23:45.

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