cancel
Showing results for 
Search instead for 
Did you mean: 

No results with share search and custom model

lotharmärkle
Champ in-the-making
Champ in-the-making
Looking at search.lib.js I found, that there is a function escapeString(value) {…} which takes care to escape the property qname of the searched property for building up the solr query.
This function does not escape all namespace prefixes as expected by solr:

The prefix qname ecm4uUtils:testproperty makes it finally to solr as the query ecm\4uUtils:testproperty:"searchvalue" and yields no results. Issuing ecm4uUtils\:testproperty:"searchvalue" returns the expected results.

There are two issues I think:
The digit is escaped with backslash but should not
The colon between the namespace prefix and the local name of the property is not escaped with a backslash, but should.

Anybody discovered the same issue, that is no results searching a custom property?

Regards,
  lothar
6 REPLIES 6

chrisokelly
Champ on-the-rise
Champ on-the-rise
I am having the exact same problem - https://forums.alfresco.com/en/viewtopic.php?f=48&t=44475, I was under the impression I must have misconfgured something to cause it so I hadn't submitted anything to JIRA. do you know of a workaround?

lotharmärkle
Champ in-the-making
Champ in-the-making
We patched two functions in search.lib.js of the community 4.0dCE version in use.

In file alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js of the repository side.

1. added backslash in colon-separator ( I don't understand why SOLR accepts a query like >>cm:title:"some text")
function escapeQName(qname)
{
   var separator = qname.indexOf(':'),
       namespace = qname.substring(0, separator),
       localname = qname.substring(separator + 1);

   return escapeString(namespace) + '\\:' + escapeString(localname);
}

2. added digits to the accepted set of chars in the identifier (not at the beginning)
function escapeString(value)
{
   var result = "";

   for (var i=0,c; i<value.length; i++)
   {
      c = value.charAt(i);
      if (i == 0)
      {
         if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'))
         {
            result += '\\';
         }
      }
      else
      {
         if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '#' || (c >= '0' && c <= '9')))
         {
            result += '\\';
         }
      }
      result += c;
   }
   return result;
}


But also to say, that the forn service returns a non expected field name for properties that do not belong to the requested type directly. That is for properties that are defined on an aspect.
We created a custom form control that adds the required prop_ prefix to the html field name, so that it gets actually considered in the search query.

chrisokelly
Champ on-the-rise
Champ on-the-rise
We patched two functions in search.lib.js of the community 4.0dCE version in use.

In file alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js of the repository side.

1. added backslash in colon-separator ( I don't understand why SOLR accepts a query like >>cm:title:"some text")

2. added digits to the accepted set of chars in the identifier (not at the beginning)

But also to say, that the forn service returns a non expected field name for properties that do not belong to the requested type directly. That is for properties that are defined on an aspect.
We created a custom form control that adds the required prop_ prefix to the html field name, so that it gets actually considered in the search query.

Hi Lothar,

I can grok the first two things there, however have never defined a custom form control. Are you able to show how you did this please? It would be invaluable in resolving this issue.

lotharmärkle
Champ in-the-making
Champ in-the-making
The reading of the valuable documentation here
http://wiki.alfresco.com/wiki/Forms

will explain how to create a custom form control and where to place the files. This documentation is great and will show you how to configure any share form (the search form is also just a form).
I'm sure there are already dicussions on the forum on how to create a custom control for reference.

But to share code:

  <config evaluator="model-type" condition="cm:content">
      <forms>
         <form id="ecm4uTool">
            <field-visibility>
               <show id="ecm4uTool:personName" />
            </field-visibility>
            <appearance>
               <field id="ecm4uTool:personName">
                  <control template="/ecm4u/searchTextfield.ftl" />
               </field>
            </appearance>
         </form>
      </forms>
   </config>

and the control template, a stripped down version of the alfresco textfield including a "prop_" prefix on the html fieldname:


<div class="form-field">
      <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
      <input id="${fieldHtmlId}" name="prop_${field.name}" tabindex="0"
             <#if field.value?is_number>value="${field.value?c}"<#else>value="${field.value?html}"</#if> />
      <@formLib.renderFieldHelp field=field />
</div>

hth,
  lothar

chrisokelly
Champ on-the-rise
Champ on-the-rise
Hi Lothar,

A million times thank you for your help, not only in solving this issue but introducing me to control templates and how they can be modified. This worked perfectly. For the record, I did not have to make the changes to the search.lib.js (I tried only making these changes originally, but reverted once it did not solve the problem, I have not had to make the changes again). I also did not have to make changes to the accepted characters (probably because there are no digits in our custom types/aspects/properties/namespace, as there appears to be in yours). It was all in the changed control templates.

For any future-people landing here with this problem, just thought I might clarify Lothar's steps a little -

  • To find the location to put the custom control .ftl file I actually had to dig a little deeper than http://wiki.alfresco.com/wiki/Forms. I found the answer here - http://wiki.alfresco.com/wiki/Forms_Examples#Providing_A_Custom_Form_Control which is that they can be put in $TOMCAT_HOME/shared/classes/alfresco/web-extension/site-webscripts

  • I also needed a replacement for the selectone.ftl control (combo box by any other name). For this (and, I assume, any other controls needed) I just had to copy the original .ftl from $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/form/controls to the above directory, find name="${field.name}" and replace with name="prop_${field.name}" (you could probably also cut a lot of the rest of the file out for efficiency)

  • the share-config-custom.xml file needs to be modified to point at these template files. This is the template property of the control tag and appears to start at the site-webscripts directory (either the one in WEB-INF or the one in shared).
Thanks again Lothar, I wish this were my post so I could mark you useful. BTW please take no offense at me clarifying the steps there, obviously the way you put it worked fine and resolved my issue, just wanted to make it clear to other people as silly/inexperienced as myself!

Regards,
Chris

lutz_horn
Champ in-the-making
Champ in-the-making
I've just noticed that the prefix <tt>prop_<tt> is <strong>not</strong> to be added in edit mode. Since Share is unable to decide if a template is used for edit or search, you will have to use different Freemarker templates for edit and search. The search template will have to prefix <ttprop_</tt> while the edit template must not do this.

<strong>Edit:</strong>


<input id="${fieldHtmlId}" type="hidden" name="${field.name}" value="${fieldValue?string}" />


<strong>Search:</strong>


<input id="${fieldHtmlId}" type="hidden" name="prop_${field.name}" value="${fieldValue?string}" />


This is annoying Smiley Sad