Help with ModifyQuery callback

I would appreciate some assistance in forcing FTS in simple searches…so I have written the following, which completely broke the simple search, but you get the idea of what I am trying to do (value of: /opt/rt4/local/html/Callbacks/hibbett/Search/Simple.html/ModifyQuery):
<%init>
my $val = $$query;
$val = “fulltext:$val”;
$$query = $val;
</%init>

<%args>
$query => undef
</%args>

I imagine I could skip a step and have a one-liner: $$query = “fulltext:$$query”; but nonetheless, it doesn’t like me modifying the query like this. Is the query, at this point, sql, or is it still the text inserted into the search box?

I have changed owner on the tree structure to www-data:www-data, and I have cleared the mason cache. (clearly since the simple search will not return any results now) :slight_smile:

I will continue to work on this, but would appreciate any assistance.

Thanks in advance,
Izz

Anyone? The below code breaks the simple query altogether. I haven’t seen anything from google.From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Izz Abdullah
Sent: Friday, October 07, 2011 8:36 AM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] help with ModifyQuery callback

I would appreciate some assistance in forcing FTS in simple searches…so I have written the following, which completely broke the simple search, but you get the idea of what I am trying to do (value of: /opt/rt4/local/html/Callbacks/hibbett/Search/Simple.html/ModifyQuery):
<%init>
my $val = $$query;
$val = “fulltext:$val”;
$$query = $val;
</%init>

<%args>
$query => undef
</%args>

I imagine I could skip a step and have a one-liner: $$query = “fulltext:$$query”; but nonetheless, it doesn’t like me modifying the query like this. Is the query, at this point, sql, or is it still the text inserted into the search box?

I have changed owner on the tree structure to www-data:www-data, and I have cleared the mason cache. (clearly since the simple search will not return any results now) :slight_smile:

I will continue to work on this, but would appreciate any assistance.

Thanks in advance,
Izz

I have gone as far to add the logger, and it never shows up in the rt.log. Here is what I have now.

  1.   ModifyQuery breaks ALL simple search (meaning, no matter what I put into the box to search for, I get 0 results)
    
  2.   There is no noise in the logs from the RT Logger
    
  3.   I have cleared the mason cache
    
  4.   I have restarted apache
    
  5.   Here is my ModifyQuery code - I have tried multiple variations:
    

a. <%init>

$RT::Logger->debug(“The initial value is $$query”); #I have also tried this with the $$query outside of the quotes

$$query = “fulltext:$$query”; #I have also tried $$query = “fulltext:” . $$query;

$RT::Logger->debug(“The value is now $$query”);

</%init>

<%args>

$query => undef

</%args>

b. <%init>

my $val = $$query;

$RT::Logger->debug(“The initial value is $val”); #I have also tried this with the $val outside of the quotes

$val = “fulltext:$val”; #I have also tried $val = “fulltext:” . $val; ##and I have also tried: $$query = “fulltext:$val”; #and $$query = “fulltext:” . $val;

$RT::Logger->debug(“The value is now $val”); #changed to $$query if assigned to $$query on the line above

$$query = $val; #this gets commented out if I change two lines up to be assigned directly to $$query

</%init>

<%args>

$query => undef

</%args>

I know someone can give me some pointers. I am so confused why it’s not working, and if the syntax is bad, why am I not at least getting something in the logs???From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Izz Abdullah
Sent: Friday, October 07, 2011 3:08 PM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] help with ModifyQuery callback

Anyone? The below code breaks the simple query altogether. I haven’t seen anything from google.

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Izz Abdullah
Sent: Friday, October 07, 2011 8:36 AM
To: rt-users@lists.bestpractical.com
Subject: [rt-users] help with ModifyQuery callback

I would appreciate some assistance in forcing FTS in simple searches…so I have written the following, which completely broke the simple search, but you get the idea of what I am trying to do (value of: /opt/rt4/local/html/Callbacks/hibbett/Search/Simple.html/ModifyQuery):
<%init>
my $val = $$query;
$val = “fulltext:$val”;
$$query = $val;
</%init>

<%args>
$query => undef
</%args>

I imagine I could skip a step and have a one-liner: $$query = “fulltext:$$query”; but nonetheless, it doesn’t like me modifying the query like this. Is the query, at this point, sql, or is it still the text inserted into the search box?

I have changed owner on the tree structure to www-data:www-data, and I have cleared the mason cache. (clearly since the simple search will not return any results now) :slight_smile:

I will continue to work on this, but would appreciate any assistance.

Thanks in advance,
Izz

If you really want to search full text most of the time, using the
Tickets section with all the dropdowns and page submits can be
cumbersome. I can see why you want to modify the simple search page. I
don;t know how to do that, but attached is a PHP script that searches
the database directly.

You’ll need to put in code for your mysql connection to the RT
database at the top of the file. You will also need to recode all the
php function shortcuts for making HTML form elements
(show_open_form(), make_radio(), etc) using your favorite form making
widget or just writing out the html manually. Then search the file for
"YOURDOMAIN" and substitute your appropriate domain name.

Using Callbacks, I added menu items inside RT so that links to this
"Easier Search" page show up when you hover over the global "Tickets"
navigation menu and when inside that section, adds a link next to the
other page nav items like “Edit Search”, “Show results”, etc. How to
do that was discussed on this list a couple of weeks ago. Search for:
RT4 Callback changes Elements/Tabs/Default

Doing it this way is not ideal since it accesses the database directly
instead of through RT API, which means if schema or anything changes,
this script will be broken. But it works ok for now.

Allen

rtsearch.zip (4.98 KB)

$$query = “fulltext:$$query”; #I have also tried $$query = “fulltext:” . $$query;

I don’t think this does what you think it does.

Try writing a trivial perl program.

use strict; use warnings;
my $query = “search term”;
print $$query;

-kevin

I appreciate the code, but yes, I have been asked to hard code the fts for simple search. The thing is, simple search is now displayed on privileged users top-bar in RT4.0.2 and it is very easy to just punch something in and search. Of course, management doesn’t want to type ‘fulltext:’ before the term, so I’ve been on a hunt for a solution. I don’t think your code will do what I need since I need to change the functionality of the search box in the topsection that is now rt4.0.2.

Thank you though…by the way an addition to my fiasco:

I edited the ModifyQuery callback to contain only one line:
$$query = $$query . " new open resolved stalled rejected deleted";
AND the search functionality still returns 0 results. Something else is not quite right…any ideas?

Cleared mason cache = sudo rm -rf /opt/rt4/var/mason_data/obj/*
Changed ownership of directory tree is sudo chown -R root:www-data /Callbacks
(I have another callback in Ticket that works perfectly)
And of course restarting apache in Ubuntu…

What am I missing?-----Original Message-----
From: Allen [mailto:allen+rtlist@crystalfontz.com]
Sent: Wednesday, October 12, 2011 3:07 PM
To: rt-users@lists.bestpractical.com
Cc: Izz Abdullah
Subject: Re: help with ModifyQuery callback

If you really want to search full text most of the time, using the Tickets section with all the dropdowns and page submits can be cumbersome. I can see why you want to modify the simple search page. I don;t know how to do that, but attached is a PHP script that searches the database directly.

You’ll need to put in code for your mysql connection to the RT database at the top of the file. You will also need to recode all the php function shortcuts for making HTML form elements (show_open_form(), make_radio(), etc) using your favorite form making widget or just writing out the html manually. Then search the file for “YOURDOMAIN” and substitute your appropriate domain name.

Using Callbacks, I added menu items inside RT so that links to this “Easier Search” page show up when you hover over the global “Tickets”
navigation menu and when inside that section, adds a link next to the other page nav items like “Edit Search”, “Show results”, etc. How to do that was discussed on this list a couple of weeks ago. Search for:
RT4 Callback changes Elements/Tabs/Default

Doing it this way is not ideal since it accesses the database directly instead of through RT API, which means if schema or anything changes, this script will be broken. But it works ok for now.

Allen

I see where you are going with this. I have also tried $query.
Google showed up previous results of people changing the search criteria to include all ticket statuses and $$query was used.-----Original Message-----
From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Kevin Falcone
Sent: Wednesday, October 12, 2011 3:10 PM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] help with ModifyQuery callback

On Wed, Oct 12, 2011 at 02:45:08PM -0500, Izz Abdullah wrote:

$$query = “fulltext:$$query”; #I have also tried $$query = “fulltext:” . $$query;

I don’t think this does what you think it does.

Try writing a trivial perl program.

use strict; use warnings;
my $query = “search term”;
print $$query;

-kevin

And I have tried with just $query…I wrote the silly program though and received what I expected, an error for an undefined variable. If I change the print line to
print $query;
I get also what I would expect, an echo to stdout of “search term”

I have been using the double $ because that is all I could find on the net…no one here has given me any other guidance on this issue.
http://requesttracker.wikia.com/wiki/SimpleSearchIncludeResolved
http://wiki-archive.bestpractical.com/edit/ModifyQuery/1768
and there are a few others
Another reason is the code I have used from what I saw here on skipping ticket history transactions for unprivileged users (SkipTransaction):
<%init>
return if $session{‘CurrentUser’}->Privileged;
my($myskip)=1;
if ($Transaction->Type =~ /^(Correspond|Create)$/) {
$myskip=0;
}

$$skip=$myskip;
</%init>

<%args>
$Transaction => undef
$skip
</%args>

Which works beautifully! (Thanks to Lars on for the code)-----Original Message-----
From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Kevin Falcone
Sent: Wednesday, October 12, 2011 3:10 PM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] help with ModifyQuery callback

On Wed, Oct 12, 2011 at 02:45:08PM -0500, Izz Abdullah wrote:

$$query = “fulltext:$$query”; #I have also tried $$query = “fulltext:” . $$query;

I don’t think this does what you think it does.

Try writing a trivial perl program.

use strict; use warnings;
my $query = “search term”;
print $$query;

-kevin

And I have tried with just $query…I wrote the silly program though and received what I expected, an error for an undefined variable. If I change the print line to
print $query;

If print $query works, why are you using $$query on the right of an
assignment? go print $$query and see what you get.

I have been using the double $ because that is all I could find on the net…no one here has given me any other guidance on this issue.

The correct way to do this is to avoid hacking things onto the string
(what happens when I use the syntax available to do queue:General, are
you going to transform that to fulltext:queue:General?)

lib/RT/Search/Googleish.pm has been massively refactored and contains
a number of small subroutines available for overriding that affect the
way that the default parsing is done. You could do this with in a
much less fragile manner by looking at that code and overriding the
default parsing one.

-kevin

  1. This was within a ‘simple perl program’ outside of RT. I already answered what happens: print $$query results in undefined variable error (because using strict). print $query prints “search term”. This is completely independent from ModifyQuery, and as I said, I have tried using BOTH $query and $$query in ModifyQuery and it is not working, in fact SimpleSearch quits working altogether. I got the code from places in the wiki which automagically double scalars. I have done the same thing with the SkipTransaction Callback and it works.
    http://requesttracker.wikia.com/wiki/SimpleSearchExcludeResolved
    and you didn’t have anything to say in this user’s request on why it doesn’t do anything either:
    Carbon60: Managed Cloud Services
    which also touches on the $RT::Logger not working in his callback, if I could get that to work, I wouldn’t be bothering everyone here.
  2. Management wants it this way…they are not going to be searching for queue:General or using any other nice utilities you have put into RT, if they were, they wouldn’t mind type fulltext: before the search term.
  3. I’ll look at the Googleish.pm, but I bet I will have just as many questions…hopefully not. I was putting this in a callback to avoid any conflicts in patching the RT app in the future.From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Kevin Falcone
    Sent: Wednesday, October 12, 2011 5:38 PM
    To: rt-users@lists.bestpractical.com
    Subject: Re: [rt-users] help with ModifyQuery callback

And I have tried with just $query…I wrote the silly program though
and received what I expected, an error for an undefined variable. If
I change the print line to print $query;

If print $query works, why are you using $$query on the right of an assignment? go print $$query and see what you get.

I have been using the double $ because that is all I could find on the net…no one here has given me any other guidance on this issue.

The correct way to do this is to avoid hacking things onto the string (what happens when I use the syntax available to do queue:General, are you going to transform that to fulltext:queue:General?)

lib/RT/Search/Googleish.pm has been massively refactored and contains a number of small subroutines available for overriding that affect the way that the default parsing is done. You could do this with in a much less fragile manner by looking at that code and overriding the default parsing one.

-kevin

and you didn’t have anything to say in this user’s request on why it doesn’t do anything either:
Carbon60: Managed Cloud Services

I can’t answer every question on the mailing list.
That question is also from a year ago and a different version of RT.

which also touches on the $RT::Logger not working in his callback, if I could get that to work, I wouldn’t be bothering everyone here.

A trivial Logger call in that callback works fine:

transom:rt4.0.2 root# mkdir -p local/html/Callbacks/Hi/Search/Simple.html/
transom:rt4.0.2 root# vim local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
transom:rt4.0.2 root# cat local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
% RT->Logger->error(“Hi”)
transom:rt4.0.2 root# ./sbin/standalone_httpd
HTTP::Server::PSGI: Accepting connections at http://0:8992/
[Thu Oct 13 14:24:19 2011] [info]: Successful login for root from 127.0.0.1 (/opt/rt4.0.2/sbin/…/lib/RT/Interface/Web.pm:660)
[Thu Oct 13 14:24:19 2011] [error]: Hi (/opt/rt4.0.2/local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery:1)

-kevin

Well it doesn’t work for me in this callback. And you did put your 2 cents worth in at the end of that particular thread. Yes, it was over a year ago, but there isn’t much literature, except for help from colleagues here, on the ModifyQuery syntax. Which I am not really getting a lot of help…just ‘why did you do this’. I have tried multiple ways. And am still working on multiple ways, and emailing the list in the midst of trying different approaches.

I have even tried the noted:
$$query = $$query . " new open resolved stalled rejected deleted";
(which seemed to work for other users)

Direction is appreciated.From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Kevin Falcone
Sent: Thursday, October 13, 2011 9:25 AM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] help with ModifyQuery callback

and you didn’t have anything to say in this user’s request on why it doesn’t do anything either:
Carbon60: Managed Cloud Services

I can’t answer every question on the mailing list.
That question is also from a year ago and a different version of RT.

which also touches on the $RT::Logger not working in his callback, if I could get that to work, I wouldn’t be bothering everyone here.

A trivial Logger call in that callback works fine:

transom:rt4.0.2 root# mkdir -p local/html/Callbacks/Hi/Search/Simple.html/
transom:rt4.0.2 root# vim local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
transom:rt4.0.2 root# cat local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
% RT->Logger->error(“Hi”)
transom:rt4.0.2 root# ./sbin/standalone_httpd
HTTP::Server::PSGI: Accepting connections at http://0:8992/ [Thu Oct 13 14:24:19 2011] [info]: Successful login for root from 127.0.0.1 (/opt/rt4.0.2/sbin/…/lib/RT/Interface/Web.pm:660)
[Thu Oct 13 14:24:19 2011] [error]: Hi (/opt/rt4.0.2/local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery:1)

-kevin

Well it doesn’t work for me in this callback.

If my trivial example does not work for you, then something is
fundamentally broken with your RT install.

Stop trying to make your changes to the query until you can get
my example to run.

-kevin

That’s another thing. Your logger looks different from what I have seen.
Yours:
RT->Logger->error("Hi)

What I have seen:
$RT::Logger->error(“Hi”);

Yours doesn’t have a semicolon and is called differently, or is it essentially called the same?From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Kevin Falcone
Sent: Thursday, October 13, 2011 10:03 AM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] help with ModifyQuery callback

Well it doesn’t work for me in this callback.

If my trivial example does not work for you, then something is fundamentally broken with your RT install.

Stop trying to make your changes to the query until you can get my example to run.

-kevin

A trivial Logger call in that callback works fine:

transom:rt4.0.2 root# mkdir -p
local/html/Callbacks/Hi/Search/Simple.html/
transom:rt4.0.2 root# vim
local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
transom:rt4.0.2 root# cat
local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
% RT->Logger->error(“Hi”)
transom:rt4.0.2 root# ./sbin/standalone_httpd
HTTP::Server::PSGI: Accepting connections at http://0:8992/ [Thu Oct
13 14:24:19 2011] [info]: Successful login for root from 127.0.0.1
(/opt/rt4.0.2/sbin/…/lib/RT/Interface/Web.pm:660)
[Thu Oct 13 14:24:19 2011] [error]: Hi
(/opt/rt4.0.2/local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery:1
)

And you haven’t set any permissions on the file…does that matter?From: Izz Abdullah
Sent: Thursday, October 13, 2011 10:13 AM
To: ‘rt-users@lists.bestpractical.com’
Subject: RE: [rt-users] help with ModifyQuery callback

That’s another thing. Your logger looks different from what I have seen.
Yours:
RT->Logger->error("Hi)

What I have seen:
$RT::Logger->error(“Hi”);

Yours doesn’t have a semicolon and is called differently, or is it essentially called the same?

From: rt-users-bounces@lists.bestpractical.com [mailto:rt-users-bounces@lists.bestpractical.com] On Behalf Of Kevin Falcone
Sent: Thursday, October 13, 2011 10:03 AM
To: rt-users@lists.bestpractical.com
Subject: Re: [rt-users] help with ModifyQuery callback

Well it doesn’t work for me in this callback.

If my trivial example does not work for you, then something is fundamentally broken with your RT install.

Stop trying to make your changes to the query until you can get my example to run.

-kevin

A trivial Logger call in that callback works fine:

transom:rt4.0.2 root# mkdir -p
local/html/Callbacks/Hi/Search/Simple.html/
transom:rt4.0.2 root# vim
local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
transom:rt4.0.2 root# cat
local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery
% RT->Logger->error(“Hi”)
transom:rt4.0.2 root# ./sbin/standalone_httpd
HTTP::Server::PSGI: Accepting connections at http://0:8992/ [Thu Oct
13 14:24:19 2011] [info]: Successful login for root from 127.0.0.1
(/opt/rt4.0.2/sbin/…/lib/RT/Interface/Web.pm:660)
[Thu Oct 13 14:24:19 2011] [error]: Hi
(/opt/rt4.0.2/local/html/Callbacks/Hi/Search/Simple.html/ModifyQuery:1
)