Tags:
create new tag
, view all tags

Question

I know you can shorten the topic names in the search result table eg. $topic(4, ...) from topic "ThisIstheTopicName0005" gives This... as result

But what if you want the last 4 characters of topicName? Is there a possibility to get ...0005 as result?

Environment

TWiki version: TWikiRelease04x01x02
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS:  
Web server:  
Perl version:  
Client OS:  
Web Browser:  
Categories: Search

-- FrederikBeun - 05 Sep 2008

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

From SpreadSheetPlugin:

Can I use CALC in a formatted search?

You need to escape the CALC so that it executes once per search hit. This can be done by escaping the % signs of %CALC{...}% with $percnt.

For example, the last four characters of the current topic are: sult

The search string is:

%SEARCH{
  "%TOPIC%"
  scope="topic"
  nonoise="on"
  format="$percntCALC{$REPLACE($topic,1,$EVAL($LENGTH($topic)-4))}$percnt"
}%

-- SeanCMorgan - 05 Sep 2008

beautifull, thanks

-- FrederikBeun - 05 Sep 2008

OK, this works:

sult

But now, try it with another use of

%CALC{}%

in the same search; here I'll add an excludetopic for 'Fred2018'.
%SEARCH{
  "%TOPIC%" 
  scope="topic" 
  nonoise="on" 
  format="$percntCALC{$REPLACE($topic,1,$EVAL($LENGTH($topic)-4))}$percnt" 
  excludetopic="Fred%CALC{$EVAL(%DISPLAYTIME{"$YEAR"}%+1)}%"
}%

This produces:

%CALC{$REPLACE(HowToShortenTopicNamesInSearchResult,1,$EVAL($LENGTH(HowToShortenTopicNamesInSearchResult)-4))}%

How do I fix this? (I'm not sure understand how quotes nest in these nested substitutions, but I've tried backslashes in various places to no effect.) I get the same failure with an expression in the search string...

-- TimotheLitt - 28 Sep 2008

Please "don't add your question to an existing page" (as per the section of that name in SupportGuidelines):

  • You haven't provided any information about your installation. That's often vital.
  • The original question was definitively answered, but your additional (and different question) could make the casual reader think it wasn't, and so they would keep looking for a different answer. I am setting the status of this question back to "Answered".
  • The original problem was solved with a "Deferred Calc". Yours requires a "Search with conditional output" (see that section in FormattedSearch), so continuing discussion here would be needlessly confusing to hypothetical future readers.

-- SeanCMorgan - 29 Sep 2008

Er, you referred me to this topic for an answer from the one I started - HowToSEARCH, which indeed had installation details.

Since you said my problem was the same, it seemed to me that associated issues with the solution belong here. Sorry that you think this is confusing. So did I - but I tried to follow your guidance...

I did read the documentation quite carefully and experimented before posting, and didn't arrive at a solution. I seem to need both defered calc (to format the output) and conditional output (to select the topics.) I'll try again to work it out from the clues provided.

Thanks for the help.

-- TimotheLitt - 29 Sep 2008

> Er, you referred me to this topic for an answer from the one I started

Yes, but I didn't say to re-open it smile

-- SeanCMorgan - 29 Sep 2008

Change status to:
Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2008-09-29 - SeanCMorgan
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.