cancel
Showing results for 
Search instead for 
Did you mean: 

Custom search in folder?

theoryoflinkin
Champ on-the-rise
Champ on-the-rise
Hi everyone,

I'm trying to extend the default search in Alfresco Share for the "cm:content" type.

What I need is, for example, when I select the "Test folder" folder, it returns me all the files inside the "Test folder".

I was wondering how could I implemente this.

Here is the code of my custom search:


         <!– Search form –>
         <form id="search">
      
            <field-visibility>
               <show id="cm:name" />
               <show id="cm:title" force="true" />
               <show id="cm:description" force="true" />
               <show id="mimetype" />
               <show id="cm:modified" />
               <show id="cm:modifier" />                           
         
               <!– new search parameters –>
               <show id="cm:created" />
          <show id="cm:creator" />
          <show id="cm:categories" force="true" />

          <!– Should insert here the parameters for the location search –>   
           
            </field-visibility>

            <appearance>
               <field id="mimetype">
                  <control template="/org/alfresco/components/form/controls/mimetype.ftl" />
               </field>
               <field id="cm:modifier">
                  <control>
                     <control-param name="forceEditable">true</control-param>
                  </control>
               </field>
               <field id="cm:modified">
                  <control template="/org/alfresco/components/form/controls/daterange.ftl" />
               </field>        
          <field id="cm:created">
                  <control template="/org/alfresco/components/form/controls/daterange.ftl" />
               </field>
          <field id="cm:creator">
                  <control>
                     <control-param name="forceEditable">true</control-param>
                  </control>
               </field>
           
          <field id="cm:categories">
        <control>
           <control-param name="compactMode">true</control-param>
           <control-param name="showSubCategoriesOption">true</control-param>
        </control>
          </field>
            </appearance>
         </form>



Please, could you tell me which parameter should I insert in order to search by file location?

Hope this is clear

Thanks in advance


PS: I already define a ftl template that allows me to select a folder. Here is the code of this if you want:


<#include "common/picker.inc.ftl" />

<#assign controlId = fieldHtmlId + "-cntrl">

<script type="text/javascript">//<![CDATA[
(function()
{
   <@renderPickerJS field "picker" />
   picker.setOptions(
   {
   <#if field.control.params.showTargetLink??>
      showLinkToTarget: ${field.control.params.showTargetLink},
      <#if page?? && page.url.templateArgs.site??>
         targetLinkTemplate: "${url.context}/page/site/${page.url.templateArgs.site!""}/document-details?nodeRef={nodeRef}",
      <#else>
         targetLinkTemplate: "${url.context}/page/document-details?nodeRef={nodeRef}",
      </#if>
   </#if>
   <#if field.control.params.allowNavigationToContentChildren??>
      allowNavigationToContentChildren: ${field.control.params.allowNavigationToContentChildren},
   </#if>
      itemType: "cm:folder",
      multipleSelectMode: true,
      parentNodeRef: "alfresco://company/home",
   <#if field.control.params.rootNode??>
      rootNode: "${field.control.params.rootNode}",
   </#if>
      itemFamily: "node",
      displayMode: "${field.control.params.displayMode!"items"}"
   });
})();
//]]></script>

<div class="form-field">
   <#if form.mode == "view">
      <div id="${controlId}" class="viewmode-field">
         <#if (field.endpointMandatory!false || field.mandatory!false) && field.value == "">
            <span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
         </#if>
         <span class="viewmode-label">${field.label?html}:</span>
         <span id="${controlId}-currentValueDisplay" class="viewmode-value current-values"></span>
      </div>
   <#else>
      <label for="${controlId}">${field.label?html}:<#if field.endpointMandatory!false || field.mandatory!false><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
     
      <div id="${controlId}" class="object-finder">
        
         <div id="${controlId}-currentValueDisplay" class="current-values"></div>
        
         <#if field.disabled == false>
            <input type="hidden" id="${fieldHtmlId}" name="-" value="${field.value?html}" />
            <input type="hidden" id="${controlId}-added" name="${field.name}_added" />
            <input type="hidden" id="${controlId}-removed" name="${field.name}_removed" />
            <div id="${controlId}-itemGroupActions" class="show-picker"></div>
        
            <@renderPickerHTML controlId />
         </#if>
      </div>
   </#if>
</div>

6 REPLIES 6

afaust
Legendary Innovator
Legendary Innovator
Hello,

unless your seriously modify the Repository backend web script for the search, you can not specify a parameter to restrict searches to specific locations / contexts other than the Repository/Sites/Site X option that Alfresco offers you out of the box.
You would need to modify the search.lib.js file and evaluate your "parameter-to-be" to add a PATH clause to the FTS query.

Regards
Axel

shazada
Star Contributor
Star Contributor
We've got a Folder Search addon which does exactly that: http://addons.alfresco.com/addons/alfresco-share-folder-search

I've written it, just pop us an email and we'll send you it. In a while I'm going to blog about it so it will make clear.
Like Axel told you need to change more files.
You'll need to change atleast the share advsearch.js and search.js.
Define a new variable which reads your custom folder field and sends the value to search.js. A snippet of the advsearch.js:
<javascript>
onSearchClick: function ADVSearch_onSearchClick(e, obj) {
            // retrieve form data structure directly from the runtime
            var formData = this.currentForm.runtime.getFormData();

            // add DD type to form data structure
            formData.datatype = this.currentForm.type;
            this.options.searchSpace = formData.targetPath;
            if (this.options.searchSpace == null) this.options.searchSpace = "";
            // build and execute url for search page
            var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + "{site}search?t={terms}&q={query}&r={repo}&rootNode={container}", {
                site: (this.options.siteId.length !== 0 ? ("site/" + this.options.siteId + "/") : ""),
                terms: encodeURIComponent(Dom.get(this.id + "-search-text").value),
                query: encodeURIComponent(YAHOO.lang.JSON.stringify(formData)),
                repo: this.options.searchRepo.toString(),
                container: encodeURIComponent(this.options.searchSpace)
            });
</javascript>
In my case this is the most valuable line<javascript> container: encodeURIComponent(this.options.searchSpace)</javascript>
So define another variable in search.js (this file has more snippets) and send it to the repo webscript, like the param rootNode:
<javascript>
_buildSearchParams: function Search__buildSearchParams(searchRepository, searchAllSites, searchTerm, searchTag, searchSort, rootNode, page) {
            var site = searchAllSites ? "" : this.options.siteId;
            var params = YAHOO.lang.substitute("site={site}&term={term}&tag={tag}&maxResults={maxResults}&sort={sort}&query={query}&repo={repo}&pageSize={pageSize}&startIndex={startIndex}&rootNode={rootNode}", {
                site: encodeURIComponent(site),
                repo: searchRepository.toString(),
                term: encodeURIComponent(searchTerm),
                tag: encodeURIComponent(searchTag),
                sort: encodeURIComponent(searchSort),
                rootNode: encodeURIComponent(rootNode),
                query: encodeURIComponent(this.options.searchQuery),
                maxResults: this.options.maxSearchResults + 1,
                // to calculate whether more results were available
                pageSize: this.options.pageSize,
                startIndex: (page - 1) * this.options.pageSize
            });
</javascript>

will this addon be compatible with alfresco 4.2x communiy and all future releases?

sir this is not showing up the UI in alfresco 5.1. either i can run the UI or logic for folder search. main problem is in advancesearch.js  when i call this logic works but lack the proper UI

 var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + "{site}search?t={terms}&q={query}&r={repo}&rootNode={container}",

and when i run the out or the box funtion that is

        var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + this.options.searchPath,

it show the UI but the logic for searching in folder is compromised

theoryoflinkin
Champ on-the-rise
Champ on-the-rise
Thank you for the answers.

Unfortunatly, I'm very busy on an other project at the moment and I have to leave aside my Alfresco project.

But when I will get some more free time, I will have a look on this.

shazada, could you post the link to your blog here after it's done?

Thanks in advance

sharifu
Confirmed Champ
Confirmed Champ
I have found a bug on this. after a search is performed, where it says "in folder" it does not list the full path, so when it is clicked on the url take me to `http://alfrescotest:8080/share/page/repository#filter=path|%2F%2F%2FApproved`. when it shoud be `http://alfrescotest:8080/share/page/repository#filter=path|%2FSites%2FSpectrumASA%2FdocumentLibrary%...`