New forum search for 1.5 in CVS

New forum search for 1.5 in CVS

by Tony Hursh -
Number of replies: 11
This version is for 1.5 dev (I posted a version for 1.4.x earlier).

It's in contrib/awhsearch/1.5dev/mod/forum/

All files go in mod/forum.

New files:

mod/forum/moodlesearchparser.php
mod/forum/lexer.php

Modified files:

mod/forum/lib.php


The following search constructs are supported:

some random phrase --> searches for posts containing all of the words "some", "random" and "phrase" (anywhere in the post).

"some random phrase" --> searches for posts containing "some random phrase" with the words in that exact order.

+word --> searches for posts containing the exact word (i.e., +foo will only match posts with the word "foo", not ones with "food").

-word --> searches for posts that do NOT contain the word.

user:John --> searches for posts where the user's name contains John. Matches both first and last name, so user:John would match both John Smith and Jim Johnson.

subject:foo --> searches for posts where foo is in the subject

You may want to update the string searchhelp in lang/en/moodle.php to reflect the new options.

All of this code should probably be examined for security implications. I'm a long way from being Petr Skoda. smile


Potential bugs: Though some effort was made to support PostgreSQL, the code needs testing under that platform.

Please let me know if you find any errors.

Enjoy!


Average of ratings: -
In reply to Tony Hursh

Re: New forum search for 1.5 in CVS

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Thanks, Tony! approve I did a few quick tests and it worked perfectly! big grin

I've merged it into HEAD for testing!

When I upgrade this site to 1.5 these forums will be SO much more useful.

One small bug: when searching for user:martin, say, the word "user" is highlighted in the results.
In reply to Martin Dougiamas

Re: New forum search for 1.5 in CVS

by Timothy Takemoto -

I just had go at test.moodle.org. The new search function is really great.

I guess it might be nice to be able to combine the string functions ("", +, and -), with the field specification commands, such as "-user:takemoto." But is is brilliant as it is.

In reply to Martin Dougiamas

Re: New forum search for 1.5 in CVS

by Tony Hursh -
One small bug: when searching for user:martin, say, the word "user" is highlighted in the results.

Ah, hadn't run into that one, but I can see why it would occur. I expect the same will probably be true if you use subject: This should be fairly easy to fix. Thanks!
In reply to Martin Dougiamas

Re: New forum search for 1.5 in CVS

by Tony Hursh -
One small bug: when searching for user:martin, say, the word "user" is highlighted in the results.

This should be fixed in the mod/forum/search.php file I just checked in to contrib/awhsearch/1.5dev/mod/forum/search.php.

In reply to Tony Hursh

Re: New forum search for 1.5 in CVS

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Thanks, checked in!  BTW, you can edit your work directly in HEAD now.  Just read the coding guide on spacing.  wink

Also, you may have noticed I renamed the moodlesearchparser.php as lib/searchlib.php and moved lexer.php to lib/lexer.php, because I think they would make a fine generic base to extend searching to other modules.
In reply to Martin Dougiamas

Re: New forum search for 1.5 in CVS

by Zbigniew Fiedorowicz -
The forum search code (both the old and new improved version) searches within html tags. Usually this is not what one wants. See the following discussion:
http://moodle.org/mod/forum/discuss.php?d=18198
for an example of this, where the search is picking up "autolink"  from class="autolink", returning entirely irrelevant results.
One can imagine however situations where searches within html tags might be desirable.  So the optimal solution might be some kind of checkbox in the search setup which might control this.
In reply to Zbigniew Fiedorowicz

Re: New forum search for 1.5 in CVS

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I've replied on bug 2507 about this.. also, I want to extend the search page as a proper form that teaches people about all the new options, so a new html field could go there

   html:table
In reply to Martin Dougiamas

Re: New forum search for 1.5 in CVS

by Zbigniew Fiedorowicz -
Hi Martin,

I've replied to you there.  The point is that the main problem is to find a way to limit searches to text which is outside html tags. I don't see a simple regexp solution for this problem.  [It's not a problem to search inside html tags with regexps.]

Zig

In reply to Tony Hursh

Re: New forum search for 1.5 in CVS

by Gustav W Delius -
This is wonderful. Unfortunately, unless there is some help icon in the search box noone will know that these possibilities now exist.