Full Text Search Portlet: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
(How to add a portlet to your home page to easily perform full-text searches)
 
(Corrected formatting for the new wiki)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==[[File:FTSearch.png|thumb|350px|The portlet]]
Contributed by [[User:Cris70|Cris]]
'''The full-text search portlet'''==
After the release of RT 4.0 we began investigating the migration from out 3.8.x RT installation.


Originally we had a mysql-based installation, and we included a full-text search engine based on Sphinx (see my IntegratingSphinx page on this wiki). We have grown very dependent on this feature.
[[File:FTSearch.png|thumb|350px|The portlet]]
=='''The full-text search portlet'''==
 
After the release of RT 4.0 we began investigating the migration from our 3.8.x RT installation.
 
Originally we had a mysql-based installation, and we included a full-text search engine based on Sphinx (see my [[IntegrateSphinx]] page on this wiki). We have grown very dependent on this feature.


We decided to switch to RT 4 and at the same time switch to Posgresql to take advantage of the built-in full-text search capabilities. Our users were very used to the custom portlet we wrote for Sphinx, so when the first testers began to try the new RT 4 system they were disappointed to have to rely on the confusing "simple search" page, and to have to add "fulltext:" every time.
We decided to switch to RT 4 and at the same time switch to Posgresql to take advantage of the built-in full-text search capabilities. Our users were very used to the custom portlet we wrote for Sphinx, so when the first testers began to try the new RT 4 system they were disappointed to have to rely on the confusing "simple search" page, and to have to add "fulltext:" every time.
Line 15: Line 18:
You have to put it in:
You have to put it in:


<your_rt_root>\local\html\Elements
''<your_rt_root>''\local\html\Elements
 
<pre>
  <&|/Widgets/TitleBox, title => loc('Fulltext Search'), bodyclass => "" &>
  <&|/Widgets/TitleBox, title => loc('Fulltext Search'), bodyclass => "" &>
     <script type="text/javascript">
     <script type="text/javascript">
Line 21: Line 26:
     {
     {
         // qui aggrego tutti i campi della prima form
         // qui aggrego tutti i campi della prima form
         var textstring = '';
         var textstring = <nowiki>''</nowiki>;
          
         var fields=["fulltext:", "queue:", "requestor:", "owner:"];
         for (i=3;i>0;i--) {
             var box = document.forms['input'].elements[i];
         for (i=3;i>=0;i--) {
             var box = document.forms['fulltext-search'].elements[i];
             if (box.value) {
             if (box.value) {
                 textstring += box.value + ' ';
                 textstring += fields[i] + box.value + ' ';
             }
             }
         }
         }
        textstring += 'fulltext:"' + document.forms['input'].elements[0].value + '"'
   
   
         // popolo la seconda form con la stringa ricavata dalla prima
         // popolo la seconda form con la stringa ricavata dalla prima
         document.forms['input2'].elements[0].value = textstring;
         document.forms['simple-search'].elements[0].value = textstring;
       
         // sottometto la seconda form invece della prima
         // sottometto la seconda form invece della prima
         document.forms['input2'].submit();
         document.forms['simple-search'].submit();
     }
     }
     </script>
     </script>
     <form name="input" action="#" method="get" onsubmit="MangleData(); return false">
     <form name="fulltext-search" action="#" method="get" onsubmit="MangleData(); return false">
         <table>
         <nowiki><table></nowiki>
             <tr class="input-row">
             <tr class="input-row">
                 <td class="label"><&|/l&>Text</&>:</td>
                 <td class="label"><&|/l&>Text</&>:</td>
Line 65: Line 71:
             </tr>
             </tr>
         </table>
         </table>
         <div class="submit">
         <nowiki><div class="submit"></nowiki>
             <div class="buttons">
             <nowiki><div class="buttons"></nowiki>
                 <input class="button" type="submit" value="Submit" />
                 <input class="button" type="submit" value="Submit" />
             </div>
             </div>
Line 72: Line 78:
     </form>
     </form>
     <form name="input2" action="/Search/Simple.html" method="get">
     <form name="input2" action="/Search/Simple.html" method="get">
         <table>
         <nowiki><table></nowiki>
             <tr class="input-row">
             <tr class="input-row">
                 <td class="value">
                 <td class="value">
Line 81: Line 87:
     </form>
     </form>
  </&>
  </&>
</pre>
Once the file is ready, you have to edit your RT_SiteConfig.pm file and modify (or add) the line that sets the HomepageComponents variable. If you don't have it, copy it from RT_Config.pm.
Once the file is ready, you have to edit your RT_SiteConfig.pm file and modify (or add) the line that sets the HomepageComponents variable. If you don't have it, copy it from RT_Config.pm.


Add FTSearch to the list of components and save the file. Then clean the mason cache and restart your web server. In our case, the commands are:
Add FTSearch to the list of components and save the file. Then clean the mason cache and restart your web server. In our case, the commands are:
> rm -rf /opt/rt4/var/mason_data/obj/*
<pre>
> svcadm restart apache22
> rm -rf /opt/rt4/var/mason_data/obj/*
> svcadm restart apache22
</pre>
Then, in RT, click on the "EDIT" box in the top right corner and add FTSearch to your home page.
Then, in RT, click on the "EDIT" box in the top right corner and add FTSearch to your home page.


That's all! Hope you enjoy it.
That's all! Hope you enjoy it.


Cris
[[User:Cris70|Cris]]

Latest revision as of 02:49, 20 June 2016

Contributed by Cris

The portlet

The full-text search portlet

After the release of RT 4.0 we began investigating the migration from our 3.8.x RT installation.

Originally we had a mysql-based installation, and we included a full-text search engine based on Sphinx (see my IntegrateSphinx page on this wiki). We have grown very dependent on this feature.

We decided to switch to RT 4 and at the same time switch to Posgresql to take advantage of the built-in full-text search capabilities. Our users were very used to the custom portlet we wrote for Sphinx, so when the first testers began to try the new RT 4 system they were disappointed to have to rely on the confusing "simple search" page, and to have to add "fulltext:" every time.

So I thought "why not write a portlet again", and since I was on the task I decided to add the possibility to search by queue, requestor, owner. This way we will not have to use the "simple search" page again for... simple searches :-)

So here it is, for those who want to have a usable alternative to the "simple search" page and yet don't want to always use the advanced search.

Paste the content of the following box into a file. I called it FTSearch.

You have to put it in:

<your_rt_root>\local\html\Elements

 <&|/Widgets/TitleBox, title => loc('Fulltext Search'), bodyclass => "" &>
     <script type="text/javascript">
     function MangleData()
     {
         // qui aggrego tutti i campi della prima form
         var textstring = '';
         var fields=["fulltext:", "queue:", "requestor:", "owner:"];
 
         for (i=3;i>=0;i--) {
             var box = document.forms['fulltext-search'].elements[i];
             if (box.value) {
                 textstring += fields[i] + box.value + ' ';
             }
         }
 
         // popolo la seconda form con la stringa ricavata dalla prima
         document.forms['simple-search'].elements[0].value = textstring;
 
         // sottometto la seconda form invece della prima
         document.forms['simple-search'].submit();
     }
     </script>
     <form name="fulltext-search" action="#" method="get" onsubmit="MangleData(); return false">
 
         <table>
             <tr class="input-row">
                 <td class="label"><&|/l&>Text</&>:</td>
                 <td class="value">
                     <input type="text" size="40" name="Text" />
                 </td>
             </tr>
             <tr class="input-row">
                 <td class="label"><&|/l&>Queue</&>:</td>
                 <td class="value">
                     <& /Elements/SelectQueue, NamedValues => 1, Name => 'Queue' &>
                 </td>
             </tr>
             <tr class="input-row">
                 <td class="label"><&|/l&>Requestor</&>:</td>
                 <td class="value">
                     <& /Elements/EmailInput, Name => 'Requestor', Size => '40' &>
                 </td>
             </tr>
             <tr class="input-row">
                 <td class="label"><&|/l&>Owner</&>:</td>
                 <td class="value">
                     <& /Elements/SelectOwner, ValueAttribute => "Name", Name => "Owner" &>
                 </td>
             </tr>
         </table>
         <div class="submit">
             <div class="buttons">
                 <input class="button" type="submit" value="Submit" />
             </div>
         </div>
     </form>
     <form name="input2" action="/Search/Simple.html" method="get">
         <table>
             <tr class="input-row">
                 <td class="value">
                     <input style="display:none" type="text" size="40" name="q" />
                 </td>
             </tr>
         </table>
     </form>
 </&>
 

Once the file is ready, you have to edit your RT_SiteConfig.pm file and modify (or add) the line that sets the HomepageComponents variable. If you don't have it, copy it from RT_Config.pm.

Add FTSearch to the list of components and save the file. Then clean the mason cache and restart your web server. In our case, the commands are:

> rm -rf /opt/rt4/var/mason_data/obj/*
> svcadm restart apache22

Then, in RT, click on the "EDIT" box in the top right corner and add FTSearch to your home page.

That's all! Hope you enjoy it.

Cris