[Rt-commit] rt branch 5.0/pg-fts-websearch created. rt-5.0.5-37-g7a3874a54e

BPS Git Server git at git.bestpractical.com
Tue Oct 31 17:13:47 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/pg-fts-websearch has been created
        at  7a3874a54e225fa4dabf73549e134c6883c96aed (commit)

- Log -----------------------------------------------------------------
commit 7a3874a54e225fa4dabf73549e134c6883c96aed
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Oct 31 11:51:30 2023 -0400

    Add search tips for MySQL and MariaDB

diff --git a/share/html/Search/Simple.html b/share/html/Search/Simple.html
index 8d61d66827..c6043a0bd4 100644
--- a/share/html/Search/Simple.html
+++ b/share/html/Search/Simple.html
@@ -81,6 +81,16 @@
   <li>Note that common words like 'the', 'is', 'this', etc. are excluded from searches since they are so common they find excessive results.</li>
 </ul>
 %    }
+%    if ( RT->Config->Get('DatabaseType') eq 'mysql' ) {
+<p>Text searches accept some extra syntax, to help refine searches:</p><ul>
+  <li>Multiple words in quotes will be searched with an OR, so "first second" will find tickets with "first" OR "second" somewhere in the history.</li>
+  <li>Multiple words with single quotes outside double quotes like '"first second"' will find results only where 'second' immediately follows 'first'.</li>
+  <li>Add a plus to search terms to require all of them like an AND, like "+first +second". This will find tickets with history entries that contain "first" and "second".</li>
+  <li>Exclude results with a minus sign before a word like "first -second", which will exclude results containing 'second'.</li>
+  <li>Include "*" as a wildcard at the end of a term to search for multiple words that start with the same letters, like "request*". This will find tickets with the words "request", "requestor", and "requested".</li>
+  <li>Note that common words like 'the', 'is', 'this', etc. are excluded from searches since they are so common they find excessive results. Also, words less than 3 characters are not indexed, so search for words longer than this limit.</li>
+</ul>
+%    }
 % } else {
 <p><&|/l, $fulltext_keyword &>Searching the full text of every ticket can take a long time, but if you need to do it, you can search for any word in full ticket history by typing <b>[_1]<i>word</i></b>.</&></p>
 % }

commit 518d1f71cfd650ff051da0290df6758a227926b9
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Oct 31 10:59:19 2023 -0400

    Add tips for using the new PostgreSQL web search features
    
    Also provide some additional guidance for all searches.

diff --git a/share/html/Search/Simple.html b/share/html/Search/Simple.html
index cd889e9388..8d61d66827 100644
--- a/share/html/Search/Simple.html
+++ b/share/html/Search/Simple.html
@@ -62,24 +62,33 @@
     <input type="submit" class="button btn btn-primary form-control" value="<&|/l&>Search</&>" />
   </div>
 </div>
-
+<p> </p>
 % my @strong = qw(<strong> </strong>);
 
-<p><&|/l_unsafe, @strong &>Search for tickets by entering [_1]id[_2] numbers, subject words [_1]"in quotes"[_2], [_1]queues[_2] by name, Owners by [_1]username[_2], Requestors by [_1]email address[_2], and ticket [_1]statuses[_2].  Searching for [_1]@domainname.com[_2] will return tickets with requestors from that domain.</&></p>
-
-<p><&|/l&>Any word not recognized by RT is searched for in ticket subjects.</&></p>
+<p><&|/l_unsafe, @strong &>The search box above is the same as the search box at the top of the page. You can use it to search for tickets by entering [_1]id[_2] numbers, [_1]queues[_2] by name, Owners by [_1]username[_2], Requestors by [_1]email address[_2], and ticket [_1]statuses[_2].  Searching for [_1]@domainname.com[_2] will return tickets with requestors from that domain.</&></p>
 
 % my $config = RT->Config->Get('FullTextSearch') || {};
 % my $fulltext_keyword = 'fulltext:';
 % if ( $config->{'Enable'} ) {
 % if ( $config->{'Indexed'} ) {
-<p><&|/l, $fulltext_keyword &>You can search for any word in full ticket history by typing <b>[_1]<i>word</i></b>.</&></p>
+<p><&|/l, $fulltext_keyword &>Any word, or multiple words in quotes, do a text search in the full ticket history. You can also type the keyword <b>[_1]<i>word</i></b>.</&></p>
+%    if ( RT->Config->Get('DatabaseType') eq 'Pg' && $RT::Handle->PgFTSQueryFunction eq 'websearch_to_tsquery' ) {
+<p>Text searches accept some extra syntax, similar to web searches:</p><ul>
+  <li>Multiple words in quotes will be searched with an AND, so "first second" will find tickets with "first" and "second" somewhere in the history.</li>
+  <li>Multiple words with single quotes outside double quotes like '"first second"' will find results only where 'second' immediately follows 'first'.</li>
+  <li>Add OR to search for the first or second term, like "first OR second".</li>
+  <li>Exclude results with a minus sign before a word like "first -second", which will exclude results containing 'second'.</li>
+  <li>Note that common words like 'the', 'is', 'this', etc. are excluded from searches since they are so common they find excessive results.</li>
+</ul>
+%    }
 % } else {
 <p><&|/l, $fulltext_keyword &>Searching the full text of every ticket can take a long time, but if you need to do it, you can search for any word in full ticket history by typing <b>[_1]<i>word</i></b>.</&></p>
 % }
+% } else {
+<p><&|/l&>Any word, or multiple words in quotes, are searched for in ticket subjects. Multiple words are searched with an 'AND'.</&></p>
 % }
 
-<p><&|/l_unsafe, map { "<strong>$_</strong>" } qw(initial active inactive any) &>Entering [_1], [_2], [_3], or [_4] limits results to tickets with one of the respective types of statuses.  Any individual status name limits results to just the statuses named.</&>
+<p><&|/l_unsafe, map { "<strong>$_</strong>" } qw(initial active inactive any) &>Adding [_1], [_2], [_3], or [_4] at the end of a search limits results to tickets with one of the respective types of statuses.  Any individual status name limits results to just the statuses named. For example, "subject:maintenance any" will find tickets of all statuses with "maintenance" in the subject.</&>
 
 % if (RT->Config->Get('OnlySearchActiveTicketsInSimpleSearch', $session{'CurrentUser'})) {
 % my $status_str  = join ', ', map { loc($_) } RT::Queue->ActiveStatusArray;
@@ -93,7 +102,7 @@
 
 % my $link_start  = '<a href="' . RT->Config->Get('WebPath') . '/Search/Build.html">';
 % my $link_end    = '</a>';
-<p><&|/l_unsafe, $link_start, $link_end &>For the full power of RT's searches, please visit the [_1]search builder interface[_2].</&></p>
+<p>After performing a search, click Advanced on the search results page to see the actual search performed. <&|/l_unsafe, $link_start, $link_end &>For the full power of RT's searches, please visit the [_1]search builder interface[_2].</&></p>
 
 </form>
 

commit b452629db3d3b21f0934160fcdd79aeac43c37e8
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Mon Oct 30 16:58:00 2023 -0400

    Switch to websearch for FTS on newer PostgreSQL
    
    PostgreSQL starting with version 11 provide a
    websearch_to_tsquery for full text search that handles
    incoming text in a more "web" style, which should help
    users get better results from searches.
    
    https://www.postgresql.org/docs/11/textsearch-controls.html

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 02e4667d7f..c43b243476 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -3272,6 +3272,32 @@ sub SimpleQuery {
     return $ret;
 }
 
+=head2 PgFTSQueryFunction
+
+The full text search engine in PostgreSQL offers several functions to convert
+input queries to the tsquery data type. This method returns the function to
+use. It is provided to handle older versions that didn't have all functions
+and also as an easy hook to override to select a different function.
+
+For PostgreSQL 11 and newer, it returns C<websearch_to_tsquery>.
+
+For older than version 11, it returns C<plainto_tsquery>.
+
+=cut
+
+sub PgFTSQueryFunction {
+    my $self = shift;
+    my $version = $self->DatabaseVersion;
+    ($version) = $version =~ /^(\d+\.\d+)/;
+
+    if ( $version >= 11.0 ) {
+        return 'websearch_to_tsquery';
+    }
+    else {
+        return 'plainto_tsquery';
+    }
+}
+
 __PACKAGE__->FinalizeDatabaseType;
 
 RT::Base->_ImportOverlays();
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index b9d0fbae04..64bdb6991c 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -1019,7 +1019,7 @@ sub _TransContentLimit {
                 ALIAS       => $alias,
                 FIELD       => $index,
                 OPERATOR    => '@@',
-                VALUE       => 'plainto_tsquery('. $dbh->quote($value) .')',
+                VALUE       => $RT::Handle->PgFTSQueryFunction . '('. $dbh->quote($value) .')',
                 QUOTEVALUE  => 0,
             );
         }
diff --git a/lib/RT/Transactions.pm b/lib/RT/Transactions.pm
index e03d2995a8..f6bde4fa06 100644
--- a/lib/RT/Transactions.pm
+++ b/lib/RT/Transactions.pm
@@ -763,7 +763,7 @@ sub _AttachContentLimit {
                 ALIAS       => $alias,
                 FIELD       => $index,
                 OPERATOR    => '@@',
-                VALUE       => 'plainto_tsquery('. $dbh->quote($value) .')',
+                VALUE       => $RT::Handle->PgFTSQueryFunction . '('. $dbh->quote($value) .')',
                 QUOTEVALUE  => 0,
             );
         }

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list