Kross
Kross

Reputation: 305

How to enable advanced search by d:date properties in Alfresco?

I have a custom content model I created for Alfresco that has type with a d:date property. I am able to build the repository and share projects with seemingly no errors. However, I am unable to search by the properties using the data type d:date or d:int. I resolved the d:int problem by changing the data type to d:text and adding a regex constraint, but I'm not sure if that would be prudent for the d:date property.

Is there some additional configuration that I need to supply or create in order to search by properties that are not d:text?

Here is a snippet showing the type declaration:

<types>
    <!-- Enterprise-wide generic document type -->
    <type name="gl:x">
        <title>Document</title>
        <parent>cm:content</parent>
        <properties>
            <property name="gl:period">
                <type>d:text</type>
            </property>
            <property name="gl:year">
                <type>d:text</type>
                <constraints>
                    <constraint ref="gl:documentYears" />
                </constraints>
            </property>
            <property name="gl:docType">
                <type>d:text</type>
                <constraints>
                    <constraint ref="gl:documentTypeList" />
                </constraints>
            </property>
            <property name="gl:date">
                <type>d:date</type>
            </property>
        </properties>
    </type>
</types>

The share search forms and properties forms seem to be rendering correctly, so I don't think that there is any problem within those.

Upvotes: 0

Views: 1724

Answers (1)

softwareloop
softwareloop

Reputation: 383

The advanced search page accepts two types of parameters.

One is simply the "keywords" field. This performs a full text search, i.e. it looks for the provided keywords in ANY text property. There is no need to configure the full text search for custom types (e.g. your gl:x) - it automatically picks up any text property in any model in the system.

The other is the group of single parameters: name, title, description, mime-type, modified-date, modifier. These properties can be of any type. A d:date property would be perfectly acceptable here, as the modified-date parameter testifies. But here custom properties are not picked-up automatically. They need to be configured explicitly.

Notice that in the upper part of the advanced search page is a drop-down called "Look for" with two options: content and folders. The best approach would be to add an option for your content type gl:x and to configure a search form for it.

You can find the definition of the two standard search forms in tomcat/webapps/share/WEB-INF/classes/alfresco/share-form-config.xml. The file is rather long so here are the two sections to look for:

<config evaluator="model-type" condition="cm:content">
  <forms>
     <!-- Default Create Content form -->
     <form>
     </form>
     <!-- Document Library Create Google Doc form -->
     <form id="doclib-create-googledoc">
     </form>
     <!-- Search form -->
     <form id="search">
     </form>
  </forms>
</config>

<!-- cm:folder type (creating nodes) -->
<config evaluator="model-type" condition="cm:folder">
  <forms>
     <!-- Document Library Common form -->
     <form id="doclib-common">
     </form>
     <!-- Search form -->
     <form id="search">
     </form>
  </forms>
</config>

I've skipped the details, but what is important is that "cm:content" and "cm:folder" each defines a <form id="search"> with the desired search properties/parameters.

As an experiment you could modify share-form-config.xml directly and add your own definition:

<config evaluator="model-type" condition="gl:x">
  <forms>
     <!-- Search form -->
     <form id="search">
        <field-visibility>
           <show id="gl:date" />
        </field-visibility>
        <appearance>
           <field id="gl:date">
              <control template="/org/alfresco/components/form/controls/daterange.ftl" />
           </field>
        </appearance>
     </form>
  </forms>
</config>

Also you have to add the new search form to the AdvancedSearch configuration found in tomcat/webapps/share/WEB-INF/classes/alfresco/share-config.xml:

<config evaluator="string-compare" condition="AdvancedSearch">
  <advanced-search>
     <forms>
        <form labelId="search.form.label.cm_content" descriptionId="search.form.desc.cm_content">cm:content</form>
        <form labelId="search.form.label.cm_folder" descriptionId="search.form.desc.cm_folder">cm:folder</form>
        <form labelId="search.form.label.gl_x" descriptionId="search.form.desc.gl_x">gl:x</form>
     </forms>
  </advanced-search>
</config>

Remember to restart alfresco after every change. When you're satisfied with the results, it would be better to move your custom definitions to a separate share-config-custom.xml in your project (share-config.xml and share-form-config.xml should never be modified directly).

For more details: https://wiki.alfresco.com/wiki/Share_Advanced_Search

Upvotes: 1

Related Questions