Plugin CustomSearch | |
This wiki plugin has been available since Tiki8 for the purpose of creating custom user interfaces to search for objects within Tiki. This plugin makes use of the functionality of PluginList to show the results of the search. This plugin is intended for rather advanced customization and you will need to have a good understanding of PluginList as well as Search and List from Unified Index and good knowledge of HTML, CSS, and Smarty in order to make good use of it. See also PluginList with editable filters. What happens when the wheel spins forever?
That is likely the sign of an AJAX failure. If you use the Firefox Firebug plugin in the HTML Response you should be able to see what the AJAX responds with. |
Parameters | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Create a custom search form for searching or listing items on the site Introduced in Tiki 8. Go to the source code Preferences required: wikiplugin_customsearch, wikiplugin_list, feature_search
|
customsearchjs parameter | |
Setting the wikiplugin parameter customsearchjs to 1 (enable) will load a javascript (jquery?) file "lib/jquery_tiki/customsearch.js". This is a Custom search js helper function, mainly keeps the search state on the URL hash, but also adds some helper functions like easier sorting, page size, trackeritem title popover, etc.
|
Basic Usage | |
You need two wiki pages, one for the search interface itself, and the other for the template to be used at the interface. From Tiki 13 onwards, it is possible to specify a |
1.1.1. Create Wiki page 1, entitled: "Custom Search" | |
Copy to clipboard
Copy to clipboard
|
1.1.2. Create Wiki page 2, entitled: "Custom Search Tpl" | |
Note that to have the cleans Bootstrap display you need to remove line feeds and space. Copy to clipboard
Older Version Examples[+]Copy to clipboard
Copy to clipboard
Copy to clipboard
Copy to clipboard
Copy to clipboard
|
1.1.3. Grant permission to the tpl page | |
You need to grant permissions to the tpl page "Custom Search Tpl" to be used as a tracker template (or a template for unified search) by anonymous or registered users (or the group of your choice). Click on permissions for that page, and change permissions accordingly. Remember to restrict edit permissions to only admin users since then to that page. |
1.1.4. Enable unified search | |
Ensure that you have Unified search enabled, under "Control Panels > Search". |
1.1.5. Rebuild search index | |
Rebuild your search index after you have created some content in tracker 1, so that this content can be found by the search engine through the search index. |
1.1.6. Use your custom search interface | |
Go to page 1 to use your new custom search interface. Notes:
|
1.1.7. Download search results | |
Since Tiki18 it is possible to add a download button to export the results of the search query. This option is available if you use the "table" output (see: Download CSV of Table Results . What is interesting in this option is that it will export ALL the results found for the search query and not only the list displayed (pagination may limit the visible list of results). This option has been improved in Tiki25 offering an option to position the download button when using the table.tpl template. Copy to clipboard
|
1.1.8. Multilingual | |
It is fairly easy to create a multilingual interface using the i18n feature and the Tiki translation tools out-in-the-box. Tools like the Plugin Lang (recommended for large sections containing other elements than text), the Plugin Translated (or PluginTr) (recommended for sentences, text) and the tr Smarty tag (recommended for sentences, text in a smarty template) There are cases you cannot use translation tag inside another element in a Smarty template. You can overcome the issue using a condition based on the language preference (the language actually in use) or use the wikiplugin smarty syntax. See the multilingual samples below. |
Working Custom Search Example | |
For a working example showing many of these features see this Custom Search Example page. |
More advanced usage | |
Wiki syntax: Copy to clipboard
Base filters are filters that you want applied regardless of what search parameters the user chooses in the search form. See PluginList for more information about filters and formatting of output. |
Creating your search interface | |
Creating the wiki page | |
You will need to create a template to be placed in the wiki page mentioned above. In this wiki page, you need to surround the contents with smarty literal tags so that the contents don't get parsed as Smarty tags. Copy to clipboard
Copy to clipboard
It is important to make sure that this page has Permissions set so that it cannot be edited by non-admins |
Creating form elements | |
Creating form elements are similar to creating standard HTML form elements, combined with using the filter parameters found in PluginList. Specify each element using plugin syntax. If you want to use a standard HTML supported attribute, simply use it and it will appear in the resulting HTML. All internal attributes that are meant for the LIST plugin to generate the search results should start with an underscore (_), so that they don't end up in the HTML (which would be invalid). For example, if you want to create a text search field that searches for the content entered: Copy to clipboard
Copy to clipboard
Copy to clipboard
Text searchSearch in one or several text tracker fieldIt is possible to filter (search) in one field but you can search in multiple fields using commas and other field permaname. Copy to clipboard
Search in a text tracker field with autocompleteIn a text tracker field have an "Autocomplete" parameter and if set to yes, it is possible to have the autocomplete feature used from within the customSearch interface adding a small JQuery code. Copy to clipboard
(replace "customsearch_0_14" with the id of your form and "fieldId: 11" with your field id) Drop down (with or without multiselect) example:Note how you can specify labels different from the values if you want Copy to clipboard
You can also set a default item to be selected using the Copy to clipboard
From Tiki 14.1 onwards custom search will automatically populate the drop-down menu for ItemLink, UserSelector and Text tracker field inputs. You need to specify the Copy to clipboard
From Tiki 19.0 (and 18.3) you can use the _operator attribute to override the site-wide preference for default boolean operator for multiple select fields. Copy to clipboard
Copy to clipboard
Checkbox example:The most important thing to keep in mind about checkboxes is that they cannot take a normal "value" parameter like in HTML. Instead, use the Copy to clipboard
If you want the checkbox to behave in reverse, i.e. search for Copy to clipboard
If you want the checkbox to mean that you want to search for whatever term you want when checked, set Copy to clipboard
Radio button example:The most important thing to remember about radio buttons is that they need a Copy to clipboard
Categories example:In general, if there are just a few categories to search by, you can use radio buttons or checkboxes (in the following example 24 is the category ID you want to search for when the checkbox is checked): Copy to clipboard
If you want the category search to not only search the specified category but also all of its sub-categories, specify the Copy to clipboard
In addition, to facilitate creating category selection elements for many categories, there is a special way to quickly show multiple checkboxes/radio buttons or a drop-down for multiple categories based on a parent category. Copy to clipboard
Note that if you are specifying a Other parameters include When specifying |
Adding a submit button | |
Copy to clipboard
|
Grouping elements together for the purpose of OR searching instead of AND | |
It has already been mentioned above that Radio buttons as well as categories (those using a However, it is possible to use the Copy to clipboard
|
Object type searches | |
If you want to dynamically filter on object types (e.g. trackeritem, wiki page, calendaritem etc) then you need to use an input with _filter="type" e.g.: Copy to clipboard
Note that it has to be something other than |
Range searches | |
Before you start, please be informed that the Unified search is a string based search. In other words, if you are trying to search between 2 numbers, make sure all your numbers are of the same number of digits. Otherwise 2 will be larger than 12. The only way to get around this for now is to make sure all numbers are entered in a padded form, for example, 0012 for 12.
However, from Tiki14 if you are using Elasticsearch as the unified search engine, then numeric tracker fields are indexed internally as float and therefore will provide for correct range searches for those fields, even without padding.
Copy to clipboard
The following example is an interesting twist, where you automatically set one end of the range through a hidden field. Copy to clipboard
To do a range search on things like modification dates, which are "unix timestamps indexed as dates", use Copy to clipboard
Date Range PickerIn Tiki 9 there is also a date range picker you can use like this: Copy to clipboard
You can also use "now" as a date. It will give you the current time/date. Since Tiki 18.2 you can use English date format based on strtotime PHP function syntax: https://secure.php.net/manual/en/function.strtotime.php. Copy to clipboard
You need to set a default filter in the customsearch as follows so that the user is not confused when first arriving at the page. Copy to clipboard
Copy to clipboard
Single-ended range searchesBefore Tiki14, the user must enter both ends of the filter for the range search for the search to have any effect. Therefore it is important to make sure the user selects a value, or a From Tiki14 it is possible allow for doing range searches with user only specifying one end of the range and the other end left blank but still having default value. For example, the following code will generate 2 form fields for searching the tracker field duration. If the user keeps the first one blank and enters 20 in the second field, it will search for the range 0 to 20. If the user enters 50 in the first field but leaves the second field blank, then the range searched for is 50 to 9999. Note that in each of the fields, Copy to clipboard
|
Distance Searches | |
Since Tiki 16
Copy to clipboard
|
Partial searches | |
Since Tiki 22
Copy to clipboard
One offers the opportunity for users to search by only entering the first characters of a word. |
Multilingual samples | |
You can use them on your Wiki page or your Smarty template
Label translation using Plugin LangUsing the Plugin Lang you can display block of "content" based on the language selection in your results page or you customSearch interface. Copy to clipboard
Copy to clipboard
Multilingual submit button replacementThis is useful to have the "Search" button translated. Using HTML version of the element work for any element. Instead of Copy to clipboard
Using the Tiki language preferencesYou can use the selected language to control what is displayed or used in embedded wikiplugin (like an embedded wikiplugin List) Copy to clipboard
|
Setting default search parameters when first coming to the page | |
As already mentioned above, you can use the Copy to clipboard
The "field" here is the same as what you have in the You can have several search parameters in the url using &.
Copy to clipboard
Copy to clipboard
Setting Date Ranges and Radio Buttons From The URLImprovements in Tiki 23.1 (also 22.2)
The wiki page containing the Custom Search plugin is called "search" and the date range input has the id "timedate": Copy to clipboard
Radio Buttons
Copy to clipboard
Setting Default Search Parameters From A Smarty TemplateSmarty syntax can be used to solve more complex cases in previous versions. In the following we use the Smarty syntax to use a real date to filter results by month following:
Copy to clipboard
Copy to clipboard
|
Advanced adding of jquery/javascript on AJAX loading of results | |
This is relevant only if you are implementing an advanced template for PluginList used in conjunction with Custom Search, and it contains jquery/javascript that affects the search results. Because in IE prior to version 9 it is not possible (due to crappy DOM handling) to deliver jquery/javascript that affect the content of the AJAX response together with the AJAX response, instead of including such scripts in the template for PluginList, you will need to include such scripts as follows: Create a wiki page as follows, enclosing your javascript/jquery, and specify the wiki page name as the Copy to clipboard
It is important to make sure that this page has Permissions set so that it cannot be edited by non-admins
Example excerpt
Wiki page to display results of custom searchCopy to clipboard
Contents of "My Custom Search Tpl"The page "My Custom Search Tpl" has this type of code: Copy to clipboard
Contents of "shortenDescriptions" (callbackscript)The page shortenDescriptions: Copy to clipboard
Advanced Pagination in Smarty TemplateAdvanced pagination not using pagination="y" but instead directly creating the pagination within the Smarty template, by specifying the customsearch ID manually as follows: Copy to clipboard
|
Setting maxRecords, sort_mode, and offset | |
Overriding defaults that apply on arriving at search page | |
The defaults can be overridden by passing into the query string these variables. For example, if you want the number of search results to show to be set to 10, you can do: Copy to clipboard
Copy to clipboard
|
Changing the settings after arriving at the search page | |
You will need a little Jquery/javascript for this. It is possible to set the javascript variables "customsearch_ Copy to clipboard
|
Customizing the interface with CSS | |
The final step is to customize the search interface with CSS. The search results is in a DIV with the ID |
Using Facets | |
Since Tiki23 Chosen has been removed Following this tutorial you will be able to set facets search using JQuery Chosen. Chosen was a "dead" project and from Tiki23 we use Select2: https://doc.tiki.org/Tiki23#Select2
A new documentation is required and will be published soon Facets are dynamic search filters provided by the search engines. They allow to refine the user's search. Not all search engines support this feature. At this time, it is only supported by the Elasticsearch implementation. Global parameters for Facets can be set on the Admin, Search control panel under Search Results (/tiki-admin.php?page=search&cookietab=2) Using facets with CustomSearch requires that hidden fields be added to the search form. These fields will be filled as the user selects filters. To simplify binding, make sure you set the ID explicitly. Copy to clipboard
Copy to clipboard
|
Facets from Categories | |
To use categories as facet generators, go to the search control panel, and on the "search results" tab add the top category or categories you will need to the "Generate custom facets from categories" preference, apply that and rebuild the search index. Add the hidden fields to your search form as above, but using this special format for the id: Copy to clipboard
and then add the facet commands to your custom search page like this: Copy to clipboard
|
Facet Parameters | |
OperatorSets the input above to use "AND" or "OR" (default is "OR") CountSince 12.4
Copy to clipboard
OrderSince 20.1
Useful for charts where you need to set the colours according to the order the facets/aggregations are returned. Copy to clipboard
MinSince 20.1
Copy to clipboard
Date Based FacetsSince 20.1 RangesUsed for Copy to clipboard
IntervalFor
Copy to clipboard
|
Facets selector tools in your results template | |
Finally, you need to modify the results template. The Copy to clipboard
Copy to clipboard
|
Generating Charts from Facets | |
Since Tiki 19 (r68500) example templates can be found in |
Related profiles | |
Shopping Cart profile
|
Test | |
Feel free to apply it to your tiki site and learn how it work, adapt it to your own needs, etc. |
Aliases | |