I would like the ability to sort search results by meta field. Currently this can only be done using the table plugin, however this requires results are displayed as a twiki table (opposed to a bulleted list etc)
The reason for this requirement is I would like to thread child documents. I currently have a threaded bulletin board running on
EvEm but it requires the threading information be extracted from the topicname. On very long threads, the maximum filename length limits the thread depth to about 16 postings.
If you could specify to sort the results by the contents of a META field, all thread information can be stored in the field and the topic name can be simplified for readability.
You can see an example of the threaded message board (each message is a normal twiki topic, and the list of topics threaded is created using
FormattedSearch and extensions written as a plugin).
http://www2.evem.org.au/bin/view/Home/EvEmDevTaskList
--
AdrianLynch - 28 Jan 2002
No takers?
--
AdrianLynch - 13 Feb 2002
This sounds like a useful feature, but I'm not volunteering to code it if that's what you mean
--
RichardDonkin - 13 Feb 2002
To search just by field, don't you just have to compose your search string more or less like this?
META:FIELD\{name\=.key[^}]*value\=.val1
If you want field searching and regular text searches combined...
I enabled searching by field & text (and even by more than one field!) on my Twiki. I changed a core function (searchWeb) to accomplish this but I've recently realized that this could be done as a Plugin as well though with a performance hit.
If you don't know how multiple field searches are allowed, all I got to say is I've gone native (
NativePerlSearch), which is quite fast in my implementation. (Gotta write that up.)
--
SlavaKozlov - 13 Feb 2002
Thanks for the replys. By
no takers I was wondering whether anyone else would find this usefull. Slava, I am actually needing the
sorting of the results to be changed. At the moment you can sort results using topic name (alphabetical), modified date or modified by. I need to sort results by the contents of a
META field. There are also facilities to sort results using the table plugin - but I am not displaying the results in a table.
--
AdrianLynch - 13 Feb 2002
Oh, yeah. oops. Got to read the title. A plugin won't work.
If you really need it - you could always hack the Search.pm file (Dec01 release), by adding a sorting if block, like this:
376a377,402
>
> } elsif( $theOrder =~ m/^field:(.*)$/ ) {
> # sort by field
> my $sortfield = $1;
> my %fieldVals= ();
> # first we need to build the hashes for fields
> foreach( @topicList ) {
> $tempVal = $_;
> my( $meta, $text ) = &TWiki::Store::readTopic( $thisWebName, $tempVal );
> my %field = $meta->findOne( "FIELD", $sortfield );
> my $value = $field{"value"} || "";
> $fieldVals{ $tempVal } = $value ;
> }
>
> # sort by field, Schwartzian Transform
> if( $revSort ) {
> @topicList = map { $_->[1] }
> sort {$b->[0] cmp $a->[0] }
> map { [ $fieldVals{$_}, $_ ] }
> @topicList;
> } else {
> @topicList = map { $_->[1] }
> sort {$a->[0] cmp $b->[0] }
> map { [ $fieldVals{$_}, $_ ] }
> @topicList;
> }
The syntax here is: use the order attribute of %SEARCH%, a colon and the name of the field. Like this: %SEARCH{order="field:shoe_size"...
(Use the field's name not title.)
--
SlavaKozlov - 13 Feb 2002
Excellent... works beautifully. This now means I can finish off and modify the form plugin and complete a proper threading bulleting board using 100% standard twiki topics...
Excellent!!
--
AdrianLynch - 13 Feb 2002
This is now in
TWikiAlphaRelease and at TWiki.org. The syntax is
order="formfield(name)", this is to make it consistent with the
FormattedSearch syntax.
Code:
} elsif( $theOrder =~ m/^formfield\((.*)\)$/ ) {
# sort by TWikiForm field
my $sortfield = $1;
my %fieldVals= ();
# first we need to build the hashes for fields
foreach( @topicList ) {
$tempVal = $_;
my( $meta, $text ) = &TWiki::Store::readTopic(
$thisWebName, $tempVal );
my( $revdate, $revuser, $revnum ) = &TWiki::Store::getRevisionInfoFromMeta( $thisWebName,
$tempVal, $meta, 1 );
$topicRevUser{ $tempVal } = &TWiki::userToWikiName(
$revuser );
$topicRevDate{ $tempVal } = $revdate;
$topicRevNum{ $tempVal } = $revnum;
$topicAllowView{ $tempVal } =
&TWiki::Access::checkAccessPermission( "view",
$TWiki::wikiUserName, $text, $tempVal, $thisWebName );
$fieldVals{ $tempVal } = getMetaFormField( $meta,
$sortfield );
}
# sort by field, Schwartzian Transform
if( $revSort ) {
@topicList = map { $_->[1] }
sort {$b->[0] cmp $a->[0] }
map { [ $fieldVals{$_}, $_ ] }
@topicList;
} else {
@topicList = map { $_->[1] }
sort {$a->[0] cmp $b->[0] }
map { [ $fieldVals{$_}, $_ ] }
@topicList;
}
--
PeterThoeny - 16 Feb 2002
I haven't quite yet figured a way to handle this, but if your formfield values are all numbers and you want to sort them, you will probably want to use
<=> rather than
cmp in the code that
SlavaKozlov has provided. This way you get results in straight numerical order instead of something like 1, 11, 19, 114, 2, 28, 253, 3, 53, 503, 6, etc... is there a good way to do this? Perhaps check to see if the members are numerical, something like
m/[0-9]*/ ...? Or maybe rather than having it decide this on it's own there could be a way for the user to specify? How do you people feel about this matter?
--
DavidSachitano - 25 Jul 2002
Maybe kill 2 birds with one stone and provide a sprintf facility in the search format and search sort order (ie format the result before the ordering so that you could get numeric sort order using something like
order="sprintf( "%08d", formfield(mynumericfield))"?
--
DarrylGreen - 26 Jul 2002