|
|||
Lines: 1-8 | Lines: 1-10 | ||
- | This |
+ | See also ((Front-ends to Tracker data)) |
- | { If you use the Firefox Firebug plugin in the HTML Response you should be able to see what the AJAX responds with. {maketoc} |
+ | ! {icon name=search} 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 __ forever?__That is likely the sign of 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 | !! Parameters | ||
{pluginmanager plugin="customsearch"} | {pluginmanager plugin="customsearch"} | ||
Lines: 14-36 | Lines: 16-54 | ||
{CODE(colors="tiki")} | {CODE(colors="tiki")} | ||
{CUSTOMSEARCH(wiki="Custom Search Tpl")} | {CUSTOMSEARCH(wiki="Custom Search Tpl")} | ||
- | } "} {OUTPUT} |
+ | {list max="10"} {filter field="tracker_id" content="1" {OUTPUT( } {display name="title" format=" "} {OUTPUT} {CUSTOMSEARCH} |
{CODE} | {CODE} | ||
{CODE(caption="Tiki 12.2 onwards, .tpl version" colors="tiki")} | {CODE(caption="Tiki 12.2 onwards, .tpl version" colors="tiki")} | ||
{CUSTOMSEARCH(tpl="CustomSearchTpl.tpl")} | {CUSTOMSEARCH(tpl="CustomSearchTpl.tpl")} | ||
- | } "} {OUTPUT} |
+ | {list max="10"} {filter field="tracker_id" content="1" {OUTPUT( } {display name="title" format=" "} {OUTPUT} {CUSTOMSEARCH} |
{CODE} | {CODE} | ||
!!!# Create Wiki page 2, entitled: "__Custom Search Tpl__" | !!!# Create Wiki page 2, entitled: "__Custom Search Tpl__" | ||
+ | Note that to have the cleans Bootstrap display you need to remove line feeds and space. | ||
+ | {CODE(caption="In Tiki 21+" colors="tiki")} | ||
+ | {literal}<div class="input-group mb-3">{input _filter="content" type="text" class="form-control" placeholder="search..." id="customSearch"}<div class="input-group-append">{input type="Submit" value="Search" class="btn btn-primary"}</div></div>{/literal} | ||
+ | {CODE} | ||
+ | !!!!- Older Version Examples | ||
+ | {CODE(caption="In Tiki 19 and 20" colors="tiki")} | ||
+ | {literal} | ||
+ | <div class="input-group mb-3"> | ||
+ | {input _filter="content" type="text" class="form-control" placeholder="Any text..." id="q"} | ||
+ | <div class="input-group-append"> | ||
+ | {input type="Submit" value="Search" class="btn btn-outline-secondary"} | ||
+ | </div> | ||
+ | </div> | ||
+ | {/literal} | ||
+ | {CODE} | ||
{CODE(caption="In Tiki 12" colors="tiki")} | {CODE(caption="In Tiki 12" colors="tiki")} | ||
{literal} | {literal} | ||
Lines: 43-47 | Lines: 61-65 | ||
{literal} | {literal} | ||
<div class="col-sm-2">Any text:</div><div class="col-sm-10">{input _filter="content" type="text" class="form-control"}</div> | <div class="col-sm-2">Any text:</div><div class="col-sm-10">{input _filter="content" type="text" class="form-control"}</div> | ||
- | <div class="col-sm-10 col-sm-push-2">{input type="Submit" value="Search" class="btn btn-primary"} | + | <div class="col-sm-10 col-sm-push-2">{input type="Submit" value="Search" class="btn btn-primary"}</div> |
{/literal} | {/literal} | ||
{CODE} | {CODE} | ||
Lines: 77-88 | Lines: 95-131 | ||
{filter field="tracker_id" content="1"} | {filter field="tracker_id" content="1"} | ||
{CODE} | {CODE} | ||
- | * it will work as a search over all your content. In fact just |
+ | * it will work as a search over all your content. In fact just this line on it's own in a page will work! |
+ {CODE(colors="tiki")} | + {CODE(colors="tiki")} | ||
{customsearch wiki="Custom Search Tpl"} | {customsearch wiki="Custom Search Tpl"} | ||
{CODE} | {CODE} | ||
- | + | !!!# Download results resultsSince ((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: [https://doc.tiki.org/PluginList-output-control-block#Download_CSV_of_Table_Results|Download CSV of Table Results] ~tc~or if you have developers skills, reusing the code from the table template (templates/search/list/table.tpl) into your own template but as of Tiki24 it requires hardcoding the name of the template at lib/core/Search/Formatter/Builder.ph~/tc~. 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. {CODE(caption="CustomSearch with download option" wrap="1" colors "tiki")} {CUSTOMSEARCH(tpl= CustomSearchTpl.tpl")} {filter content="22 field="tracker_id"} {OUTPUT(template="table" downloadable="Sample file.csv" -position="top")} {column label= Firstname" field="firstname"} {column label "Lastname field="lastname"} {OUTPUT} {FORMAT(name="firstname" }{display name="tracker_field_contactsFirstName"}{FORMAT} {FORMAT(name="lastname")}{display name "tracker_field_contactsLastName format "trackerrender"}Multilingual FORMAT} {CUSTOMSEARCH} {CODE} !!!# MultilingualIt is fairly easy to create a multilingual interface using the ((i18n|i18n feature)) and the Tiki translation tools out-in-the-box. Tools like the ((PluginLang|Plugin Lang)) (recommended for large sections containing other elements than text), the ((PluginTranslated |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|Smarty template)). You can overcome the issue using a condition on the language preference (the language actually in use) or use wikiplugin smarty syntax. Example the ((PluginCustomSearch|#Multilingual_samples|multilingual samples below)). !!! Working Custom Search ExampleFor a working example showing many of these features see this ((Custom Search Example)) page. | |
!! More advanced usage | !! More advanced usage | ||
Wiki syntax: | Wiki syntax: | ||
- | {CODE(caption=" |
+ | {CODE(caption="CustomSearch" wrap="1" colors="tiki")} |
{CUSTOMSEARCH(wiki="Search-tpl" id="mysearch")} | {CUSTOMSEARCH(wiki="Search-tpl" id="mysearch")} | ||
{output template="/var/www/html/templates/my-custom-searchresults.tpl" pagination="y"} | {output template="/var/www/html/templates/my-custom-searchresults.tpl" pagination="y"} | ||
Lines: 134-137 | Lines: 177-196 | ||
{input _filter="content" _field="tracker_field_28,tracker_field_22" type="text"} | {input _filter="content" _field="tracker_field_28,tracker_field_22" type="text"} | ||
{CODE} | {CODE} | ||
+ | !!!! Text search | ||
+ | !!!!! Search in one or several ((Text Tracker Field|text tracker field)) | ||
+ | It is possible to filter (search) in one field but you can search in multiple fields using commas and other field permaname. | ||
+ | {CODE(colors="tiki")} | ||
+ | {input _filter="content" _field="tracker_field_20,tracker_field_28,tracker_field_22" type="text" class="mysearchbox"} | ||
+ | {CODE} | ||
+ | !!!!! Search in a ((Text Tracker Field|text tracker field)) with autocomplete | ||
+ | In a ((Text Tracker Field|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. | ||
+ | {CODE()} | ||
+ | $("#customsearch_0_14").tiki("autocomplete", "trackervalue", { fieldId: 11}); | ||
+ | {CODE} | ||
+ | (replace "customsearch_0_14" with the id of your form and "fieldId: 11" with your field id) | ||
!!!! Drop down (with or without multiselect) example: | !!!! Drop down (with or without multiselect) example: | ||
Lines: 146-152 | Lines: 205-221 | ||
{select _filter="content" _options="1980,1981,1982" _field="tracker_field_104" multiple="multiple" _mandatory="y" _default="1980"} | {select _filter="content" _options="1980,1981,1982" _field="tracker_field_104" multiple="multiple" _mandatory="y" _default="1980"} | ||
{CODE} | {CODE} | ||
- | 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 -+_field+- and -+_trackerId+- params only (to |
+ | 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 -+_field+- and -+_trackerId+- params only. You can force a blank or labelled item (has no value) by using the attribute -+_firstlabel+- like, kind of a placeholder HTML attribute {CODE(wrap="1" colors="tiki" } {select _field="tracker_field_myFieldPermName" _trackerId="42" _firstlabel="default "} {CODE} From Tiki 19. ''(and 18.3)'' you can use the _operator attribute to override the site-wide preference for default boolean operator multiple select fields. {CODE(wrap="1" colors "tiki")} {select _filter="content" _options="o,p,c" _labels="Open,Pending,Closed" _field="tracker_status" _operator="or" class="form-control" multiple="multiple" id= status"} {CODE} From Tiki 21+ you can use the parameter -+_unquoted+- to not create quotes around strings with spaces in. This is useful for doing boolean filters, such as: |
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
- | {select _field=" |
+ | {select _filter="content" _options="o OR p,c" _labels="Open or Pending,Closed" _field="tracker_status" class="form-control" id="status" _unquoted="y"} |
{CODE} | {CODE} | ||
Lines: 156-160 | Lines: 225-229 | ||
{input _filter="content" _default="y" _field="tracker_field_58" type="checkbox"} | {input _filter="content" _default="y" _field="tracker_field_58" type="checkbox"} | ||
{CODE} | {CODE} | ||
- | If you want the checkbox to behave in reverse, i.e. search for -+NOT y+- when it is checked and y when it is not checked, specify |
+ | If you want the checkbox to behave in reverse, i.e. search for -+NOT y+- when it is checked and y when it is not checked, specify -+value="n"+- . |
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
{input _filter="content" _field="tracker_field_58" _value="n" type="checkbox"} | {input _filter="content" _field="tracker_field_58" _value="n" type="checkbox"} | ||
Lines: 206-209 | Lines: 275-283 | ||
{input _filter="content" type="checkbox" _value="oranges" _group="15"} Oranges | {input _filter="content" type="checkbox" _value="oranges" _group="15"} Oranges | ||
{CODE} | {CODE} | ||
+ | !!! 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.: | ||
+ | {CODE()}{input _filter="type" type="hidden" id="my_object_type"}{CODE} | ||
+ | Note that it has to be something other than -+type="text"+- (so -+hidden+- if using javascript, or -+select+- to use a dropdown). | ||
!!! Range searches | !!! Range searches | ||
Lines: 231-234 | Lines: 305-316 | ||
{CODE} | {CODE} | ||
You can also use "now" as a date. It will give you the current time/date. | 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. | ||
+ | {CODE(wrap="1" colors="tiki")} | ||
+ | {daterange _field="modification_date" _gap="2 weeks" _to="next week" } | ||
+ | {daterange _field="modification_date" _gap="1 month" _to="now" } | ||
+ | {CODE} | ||
+ | To test your "humanly readable" date strings you can use [https://strtotime.co.uk|this tool] so see what the server interprets them as, for example this for the [https://strtotime.co.uk/?str=first+friday+of+next+month|first friday of next month] | ||
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. | 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. | ||
Lines: 237-240 | Lines: 319-328 | ||
{filter range="modification_date" from="now" gap="31536000"} | {filter range="modification_date" from="now" gap="31536000"} | ||
{CODE} | {CODE} | ||
+ | Since Tiki 18.3 the end date uses the end of the day, as opposed to midnight at the beginning of that day. This is generally agreed to be more intuitive, but if you need to revert to the previous behaviour add a parameter -+_toendofday="n"+-. For instance this will find nothing: | ||
+ | {CODE(wrap="1" colors="tiki")} | ||
+ | {daterange _field="modification_date" _from="today" _to="today" _toendofday="n"} | ||
+ | {CODE} | ||
!!!!Single-ended range searches | !!!!Single-ended range searches | ||
Before ((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 -+_default+- is set. | Before ((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 -+_default+- is set. | ||
Lines: 244-263 | Lines: 332-461 | ||
{input class="form-control" type="number" placeholder="Min" _filter="content" _field="tracker_field_duration" _emptyfrom="0" _emptyother="9999" _textrange="1"} - {input class="form-control" type="number" placeholder="Max" _filter="content" _field="tracker_field_duration" _emptyto="9999" _emptyother="0" _textrange="1"} | {input class="form-control" type="number" placeholder="Min" _filter="content" _field="tracker_field_duration" _emptyfrom="0" _emptyother="9999" _textrange="1"} - {input class="form-control" type="number" placeholder="Max" _filter="content" _field="tracker_field_duration" _emptyto="9999" _emptyother="0" _textrange="1"} | ||
{CODE} | {CODE} | ||
+ | !!! Distance Searches | ||
+ | ''Since Tiki 16'' | ||
+ | This should be considered unfinished and somewhat experimental but basically works with some customisation. The three inputs are: | ||
+ | * distance: Use a number and a unit, e.g. 1000m for one thousand metres | ||
+ | * latitude: A floating point number up between -90 and +90 | ||
+ | * longitude: A floating point number up between -180 and +180 | ||
+ | {CODE(wrap="1" colors="tiki")} | ||
+ | {DIV(class="row")}{distance class="form-control col-sm-4"}{DIV} | ||
+ | {CODE} | ||
+ | !!! Partial searches | ||
+ | ''Since Tiki 22'' | ||
+ | It was possible to perform a partial search -+foo*+- in a text field in order to match -+foo+-, -+foobar+-, -+foostuff+- but it is not user-friendly and users need to know or figure it out. | ||
+ | A parameter -+_partial+- has been added to the plugin CustomSearch in ((Tiki22)) to allow partial search. | ||
+ | {CODE(caption="Text field filter using partial parameter" wrap="1" colors="tiki")} | ||
+ | {input _field="tracker_field_peopleLastname,tracker_field_peopleFirstname" _trackerId="1" class="form-control" placeholder="Look for names in directory" _partial="y" } | ||
+ | {CODE} | ||
+ | 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 | ||
+ | ''literal tags depends of the context and the way you set your template while needed in most case, you may need to remove them for your usage'' | ||
+ | !!!! Label translation using Plugin Lang | ||
+ | Using the ((PluginLang|Plugin Lang)) you can display block of "content" based on the language selection in your results page or you customSearch interface. | ||
+ | {CODE(wrap="1" caption="Plugin Lang in a smarty template" colors="tiki")} | ||
+ | {wikiplugin _name=lang lang=fr} | ||
+ | {literal} | ||
+ | {select _filter="content" _options="September,October,November,December,January,February,March,April,May,June,July,August" _labels="Septembre,Octobre,Novembre,Decembre,Janvier,Février,Mars,Avril,Mai,Juin,Juillet,Aout" _field="tracker_field_timeworkWorkerMonth" class="custom-select"} | ||
+ | {/literal} | ||
+ | {/wikiplugin} | ||
+ | {CODE} | ||
+ | {CODE(wrap="1" caption="Translation of tracker status" colors="tiki")} | ||
+ | {wikiplugin _name=lang lang=fr} | ||
+ | {literal} | ||
+ | {select _filter="content" _options="o,p,c" _labels="Ouverte,En attente,Fermée" _field="tracker_status" _operator="or" class="form-control custom-select" multiple="multiple" id="statusSelector_field"} | ||
+ | {/literal} | ||
+ | {/wikiplugin} | ||
+ | {CODE} | ||
+ | !!!! Multilingual submit button replacement | ||
+ | This is useful to have the "Search" button translated. Using HTML version of the element work for any element. | ||
+ | Instead of -+{input type="Submit" value="Search" class="btn btn-primary"}+- | ||
+ | |||
+ | {CODE(wrap="1" caption="Multilingual submit button" colors="tiki")} | ||
+ | <button type="submit" class="btn btn-primary">{tr}Search{/tr}</button> | ||
+ | {CODE} | ||
+ | !!!! Using the Tiki language preferences | ||
+ | You can use the selected language to control what is displayed or used in embedded wikiplugin (like an embedded wikiplugin List) | ||
+ | {CODE(wrap="1" caption="Using the language preferences" colors="tiki")} | ||
+ | {if $prefs.language eq fr} Montre ca {else} Show this {/if} | ||
+ | {CODE} | ||
!!! Setting default search parameters when first coming to the page | !!! Setting default search parameters when first coming to the page | ||
As already mentioned above, you can use the -+_default+- parameter on specific fields. However, in some cases you are coming from another page where you want to pass some input from there via the query string. To do this you can pass in the query string, for example: | As already mentioned above, you can use the -+_default+- parameter on specific fields. However, in some cases you are coming from another page where you want to pass some input from there via the query string. To do this you can pass in the query string, for example: | ||
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
- | tiki-index.php?page=Search&default[field]=value | + | [tiki-index.php?page=Search&default[field]=value] ''Or with SEFURL enabled' [Search?default~field=value] |
{CODE} | {CODE} | ||
The "field" here is the same as what you have in the -+_field+- attribute in your search template. | The "field" here is the same as what you have in the -+_field+- attribute in your search template. | ||
+ | You can have several search parameters in the url using &. | ||
+ | You may also use an item link/list value (in the example below tracker_field_kind is item link) in some case. | ||
+ | {CODE(wrap="1" colors="tiki")} | ||
+ | tiki-index.php?page=Search&default[field]=value&default[field]=value | ||
+ | e.g. [tiki-index.php?page=Search&default[tracker_field_month]=October&default[tracker_field_kind]=644] | ||
+ | ''Or with SEFURL enabled'' | ||
+ | [Search?default~tracker_field_month=October&default~tracker_field_kind=644] | ||
+ | {CODE} | ||
If you have categories filters defined, you can set the defaults as follows: | If you have categories filters defined, you can set the defaults as follows: | ||
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
tiki-index.php?page=Search&defaultcat[parent]=value | tiki-index.php?page=Search&defaultcat[parent]=value | ||
- | e.g. tiki-index.php?page=Search&defaultcat[5]=2,7 | + | e.g. [tiki-index.php?page=Search&defaultcat[5]=2,7] ''Or with SEFURL enabled' [Search?defaultcat~5=2,7] |
{CODE} | {CODE} | ||
+ | !!!! Setting Date Ranges and Radio Buttons From The URL | ||
+ | ''Improvements in Tiki 23.1 (also 22.2)'' | ||
+ | __Date Ranges__ | ||
+ | PHP -+strtotime+- values can be used to set date range field defaults. You can test your values here [https://strtotime.co.uk] | ||
+ | The wiki page containing the Custom Search plugin is called "search" and the date range input has the id "timedate": | ||
+ | {CODE(wrap="1" colors="tiki" caption="Date Range Examples")} | ||
+ | * From one year ago to the end of the current month | ||
+ | [search?default~timedate_from=-1+year&default~timedate_to=first+day+of+next+month] | ||
+ | * Everything in the past year | ||
+ | [search?default~timedate_gap=1+year&default~timedate_to=now] | ||
+ | * Everything in 2015 | ||
+ | [search?default~timedate_gap=1+year&default~timedate_from=2015-1-1] | ||
+ | {CODE} | ||
+ | __Radio Buttons__ | ||
+ | You can use the -+_field+- or the -+_group+- value to set Radio Buttons by their value | ||
+ | {CODE(wrap="1" colors="tiki" caption="Radio Button Examples")} | ||
+ | [Search?default~tracker_field_radioButton=1] | ||
+ | or | ||
+ | [Search?default~myGroup=3] | ||
+ | {CODE} | ||
+ | !!!! Setting Default Search Parameters From A Smarty Template | ||
+ | Smarty 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: | ||
+ | https://www.smarty.net/docs/en/language.modifier.date.format.tpl | ||
+ | {CODE(wrap="1" colors="tiki" theme="default")}tiki-index.php?page=Search&default[field]={smarty} | ||
+ | e.g. tiki-index.php?page=Serch&default[tracker_field_month]={'this month'|date_format:"%B"} | ||
+ | ''Or with SEFURL enabled'' | ||
+ | <a href="Search?default~tracker_field_month={'this month'|date_format:"%B"}">Search this month</a> | ||
+ | {CODE} | ||
Note that if you are having problems using square brackets within link syntax in a wiki page, you may want to urlencode the square brackets, for example: | Note that if you are having problems using square brackets within link syntax in a wiki page, you may want to urlencode the square brackets, for example: | ||
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
[tiki-index.php?page=Search&defaultcat%5b7%5d=3] | [tiki-index.php?page=Search&defaultcat%5b7%5d=3] | ||
+ | ''Or use ~ instead of square brackets completely (also with SEFURL enabled)'' | ||
+ | [Search?defaultcat~5=3] | ||
{CODE} | {CODE} | ||
Lines: 268-277 | Lines: 466-522 | ||
Create a wiki page as follows, enclosing your javascript/jquery, and specify the wiki page name as the -+callbackscript+- parameter to the CUSTOMSEARCH plugin. | Create a wiki page as follows, enclosing your javascript/jquery, and specify the wiki page name as the -+callbackscript+- parameter to the CUSTOMSEARCH plugin. | ||
- | {CODE(wrap="1" colors="tiki")} { |
+ | {CODE(wrap="1" colors="tiki" theme="default")}{JQ()} $(document).on("pageSearchReady", function() doYourStuff ); return true; }); {JQ} |
{CODE} | {CODE} | ||
^It is important to make sure that this page has ((Permissions)) set so that it cannot be edited by non-admins^ | ^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 search | ||
+ | {CODE(colors="tiki")} | ||
+ | {CUSTOMSEARCH(wiki="My Custom Search Tpl" recalllastsearch="0" searchonload="1" requireinput="0" searchable_only="1" customsearchjs="1" callbackscript="shortenDescriptions")} | ||
+ | (the filters and output of the custom search as usual) | ||
+ | {CUSTOMSEARCH} | ||
+ | {CODE} | ||
+ | !!!!! Contents of "My Custom Search Tpl" | ||
+ | The page "My Custom Search Tpl" has this type of code: | ||
+ | {CODE(colors="htmlmixed")} | ||
+ | <div id="courseOverview">{$row.courseDescription|truncate:30:"...":false}</div> <a class="readMore" >Read more</a> | ||
+ | <div id="courseOverviewFull" style="display: none">{$row.courseDescription}</div> <a class="readLess" style="display: none">Read less</a> | ||
+ | {CODE} | ||
+ | !!!!! Contents of "shortenDescriptions" (callbackscript) | ||
+ | The page shortenDescriptions: | ||
+ | {CODE(colors="javascript" theme="default")}{JQ()} | ||
+ | $(document).on("pageSearchReady", function() { | ||
+ | //using the .readMore class as a selector for the click event over it. | ||
+ | $('.readMore').click(function(){ | ||
+ | $('#courseOverview').toggle(); | ||
+ | $('#courseOverviewFull').show(); | ||
+ | $('.readLess').show(); | ||
+ | $('.readMore').hide(); | ||
+ | }); | ||
+ | $('.readLess').click(function(){ | ||
+ | $('#courseOverview').toggle(); | ||
+ | $('#courseOverviewFull').hide(); | ||
+ | $('.readLess').hide(); | ||
+ | $('.readMore').show(); | ||
+ | }); | ||
+ | return true; | ||
+ | }); | ||
+ | {JQ} | ||
+ | {CODE} | ||
!!!!Advanced Pagination in Smarty Template | !!!!Advanced Pagination in Smarty Template | ||
Lines: 279-283 | Lines: 524-528 | ||
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
{assign var='customsearchid' value="xyz"} | {assign var='customsearchid' value="xyz"} | ||
- | {pagination_links offset_jsvar=" |
+ | {pagination_links offset_jsvar="customsearch_`$customsearchid`.offset" _onclick="$('#customsearch_`$customsearchid`').submit();return false;" resultset=$results}{/pagination_links} |
{CODE} | {CODE} | ||
Lines: 309-313 | Lines: 554-563 | ||
!!Using Facets | !!Using Facets | ||
+ | {REMARKSBOX(type="warning" title="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{REMARKSBOX} | ||
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. | 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. | 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. | ||
Lines: 329-344 | Lines: 579-665 | ||
{CODE} | {CODE} | ||
- | Since Tiki 14 (and backported |
+ | Then, you need to modify the results template to display the facets selector tools (see the sample below) |
+ | !!! 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: -+deep_categories_under_XXX+- replacing the XXX with the top category id | ||
+ | {CODE(wrap="1" colors="tiki")} | ||
+ | {input _filter="content" type="hidden" _field="tracker_field_types" id="deep_categories_under_28"} | ||
+ | {input _filter="content" type="hidden" _field="tracker_field_styles" id="deep_categories_under_42"} | ||
+ | {CODE} | ||
+ | and then add the facet commands to your custom search page like this: | ||
{CODE(wrap="1" colors="tiki")} | {CODE(wrap="1" colors="tiki")} | ||
{CUSTOMSEARCH()} | {CUSTOMSEARCH()} | ||
... | ... | ||
- | {facet name= |
+ | {facet name="deep_categories_under_28"} {facet name="deep_categories_under_42"} |
... | ... | ||
{CUSTOMSEARCH} | {CUSTOMSEARCH} | ||
{CODE} | {CODE} | ||
+ | Then, you need to modify the results template to display the facets selector tools (see the sample below) | ||
+ | !!! Facet Parameters | ||
+ | !!!! Operator | ||
+ | Sets the input above to use "AND" or "OR" (default is "OR") | ||
+ | !!!! Count | ||
+ | ''Since 12.4'' | ||
+ | You can specify the maximum number of facets returned. This defaults to 10, but can be changed globally using the "Facet result count" preference on the search results control panel, or per facet in the plugin like this: | ||
+ | {CODE(wrap="1" colors="tiki")}{CUSTOMSEARCH()} | ||
+ | ... | ||
+ | {facet name=deep_categories operator=or count=50} | ||
+ | ... | ||
+ | {CUSTOMSEARCH}{CODE} | ||
+ | !!!! Order | ||
+ | ''Since 20.1'' | ||
+ | Sets the order the facets are returned in the results, use either -+_count+- (default) or -+_term+- for ES5 (or -+_key+- for ES6+). Append -+_asc+- or -+_desc+- for ascending and descending. | ||
+ | Useful for charts where you need to set the colours according to the order the facets/aggregations are returned. | ||
+ | {CODE(wrap="1" colors="tiki")}{CUSTOMSEARCH()} | ||
+ | ... | ||
+ | {facet name="tracker_status" order="_term_asc"} | ||
+ | ... | ||
+ | {CUSTOMSEARCH}{CODE} | ||
+ | !!!! Min | ||
+ | ''Since 20.1'' | ||
+ | Set the min_doc_count - useful for displaying empty aggregations | ||
+ | {CODE(wrap="1" colors="tiki")}{CUSTOMSEARCH()} | ||
+ | ... | ||
+ | {facet name=deep_categories min="0"} | ||
+ | ... | ||
+ | {CUSTOMSEARCH}{CODE} | ||
+ | !!!! Date Based Facets | ||
+ | ''Since 20.1'' | ||
+ | !!!!! Ranges | ||
+ | Used for -+type=date_range+- each range is separated by a pipe | character, and within that use commas to separate -+from+-,-+to+-,-+label+- | ||
+ | More info on date formats accepted [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern|here on elastic.co] | ||
+ | {CODE(wrap="1" colors="tiki")}{CUSTOMSEARCH()} | ||
+ | ... | ||
+ | {facet name="date" type="date_range" id="date_range" ranges="2018-01-01,2018-04-01,2018 Q1|2018-04-01,2018-07-01,2018 Q2|2018-07-01,2018-10-01,2018 Q3|2018-10-01,2019-01-01,2018 Q4"} | ||
+ | ... | ||
+ | {CUSTOMSEARCH}{CODE} | ||
+ | !!!! Interval | ||
+ | For -+type=date_histogram+- (more info [https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-aggregations-bucket-datehistogram-aggregation.html|here]) | ||
+ | {CODE(wrap="1" colors="tiki")}{CUSTOMSEARCH()} | ||
+ | ... | ||
+ | {facet name="date" type="date_histogram" id="date_histogram" interval="year"} | ||
+ | ... | ||
+ | {CUSTOMSEARCH}{CODE} | ||
+ | !!! Facets selector tools in your results template | ||
Finally, you need to modify the results template. The -+$facets+- variable is available and contains all the facets returned by the search engine. It is important to verify that the results have been provided. | Finally, you need to modify the results template. The -+$facets+- variable is available and contains all the facets returned by the search engine. It is important to verify that the results have been provided. | ||
+ | {CODE(caption="Test the facets array is populated properly")} | ||
+ | {$facets|var_dump} | ||
+ | {CODE} | ||
In this example, Chosen is used to render the facet elements nicely and each change to a facet causes the results to reload. The registerFacet() jQuery function binds the select element to the hidden field annotated by -+data-for+-. | In this example, Chosen is used to render the facet elements nicely and each change to a facet causes the results to reload. The registerFacet() jQuery function binds the select element to the hidden field annotated by -+data-for+-. | ||
Lines: 380-388 | Lines: 701-714 | ||
{/jq} | {/jq} | ||
{CODE} | {CODE} | ||
+ | !!! Generating Charts from Facets | ||
+ | Since Tiki 19 (r68500) example templates can be found in -+templates/examples/search/+-. | ||
+ | Some examples of this can be found on ((PluginCustomSearch Chart Examples)) | ||
!! Related profiles | !! Related profiles | ||
__Shopping Cart profile__ | __Shopping Cart profile__ | ||
The https://profiles.tiki.org/Shopping_Cart profile sets up a more complicated custom search using smarty templates etc. | The https://profiles.tiki.org/Shopping_Cart profile sets up a more complicated custom search using smarty templates etc. | ||
- | + | ! Test | |
Feel free to apply it to your tiki site and learn how it work, adapt it to your own needs, etc. | Feel free to apply it to your tiki site and learn how it work, adapt it to your own needs, etc. | ||
!!Aliases | !!Aliases | ||
(alias(Custom search)) | (alias(Plugin Custom Search)) | (alias(CustomSearch)) | (alias(Custom search)) | (alias(Plugin Custom Search)) | (alias(CustomSearch)) |