Custom search question

All,

I’m trying to create a search to search a certain field in a number of tiddlers that is formated like this yyyy-mm-dd. It’s a date field. The sticky point for me is that I don’t want any search results to appear until some minimum number of characters are typed in the edit text widget. Using the minlength[] operator like this:

[tag[Railroads]search:charterfiled{$:/state/rrfind}minlength[]]

doesn’t work.

I’d like to not have any results show until at least the first three characters of the year are typed. I think it could be done with a regular expression, but I don’t know that well enough.

Any ideas? Thanks in advance!

You are using minlength[] that is equivalent to minlength[0] then you have a result with only 1 character you will have a result.

Generally, you will probably have to check for a minimum length in an outside list widget. You also need to specify what your minimum length is.

<$list filter="[{$:/state/rrfind}minlength[3]]" variable="null" emptyMessage="//Needs at least 3 input characters.//">
<$list filter="[tag[Railroads]search:charterfiled{$:/state/rrfind}]" emptyMessage="//No results//"/>
</$list>
1 Like

I actually have it set as 3. I just forgot to type that in the message.

Thanks. I realized that solution after I sent the message. I’m still interested in knowing if there’s a regexp solution.

I’m trying to understand, why do you need regexp in particular?

There are 3 possible outputs:

  1. Message: Need more characters
  2. Message: No results
  3. The actual results

If you don’t need #1, then it could be done with just one list widget.

Edit: You could use regexp to enforce a 3 digits rule like this:

<$vars regx="\d{3,}">
<$list filter="[{$:/state/rrfind}regexp<regx>]" variable="null" emptyMessage="//Needs at least 3 input digitts.//">
<$list filter="[tag[Railroads]search:charterfiled{$:/state/rrfind}]" emptyMessage="//No results//"/>
</$list>
</$vars>

It’s not that I need regexp. It’s more that I’m curious if it could be done with regexp. If it doesn’t make any sense, then that’s good to know to.

I basically did what Mark suggested and it worked great. Thanks, Mark!

1 Like

Perhaps its useful to think of regexp as searching or testing for strings or patterns but if you are simply testing integers or regular maths there are more direct methods.

For example you may use maths for a test for 5 stars but regex for ***** stars.

Makes perfect sense. Regex is pretty foreign to me so I’m still learning. Thanks.

1 Like

Regex in TW is very useful. There has been a lot of work trying to explain implementing (1) Regex in general (that TW can do well); and (2) the one special rule needed (you can’t use the regex [character class] directly as it is reserved for filter syntax) for the TW regexp operator.

Learning comment :slight_smile:
TT

1 Like

Thanks very much for the links. I need all the help I can get.