cancel
Showing results for 
Search instead for 
Did you mean: 

Query syntax error with Share advanced search and list constraint

ludo2000
Champ in-the-making
Champ in-the-making
Hello,
I'm using Alfresco community edition 4.2.c.

I created a custom content type with a LIST constraint:


<type name="abc:personaleDocumentazioneVaria">
  <title>Personale - Documentazione Varia</title>
  <parent>cm:content</parent>
  <properties>
    <property name="abc:personaleDVCodiceFiscale">
      <title>Codice fiscale</title>
      <type>d:text</type>
      <mandatory>true</mandatory>
      <constraints>
        <constraint ref="abc:codicefiscale16_constraint" />
      </constraints>
    </property>
    …
    <property name="abc:personaleDVMatricola">
      <title>Matricola</title>
      <type>d:text</type>
      <mandatory>true</mandatory>
    </property>
    <property name="abc:personaleDVCognome">
      <title>Cognome</title>
      <type>d:text</type>
      <mandatory>true</mandatory>
    </property>
    <property name="abc:personaleDVNome">
      <title>Nome</title>
      <type>d:text</type>
      <mandatory>true</mandatory>
    </property>
    <property name="abc:personaleDVDataDocumento">
      <title>Data documento</title>
      <type>d:date</type>
      <mandatory>true</mandatory>
    </property>
    <property name="abc:personaleDVTiopDocumento">
      <title>Tipo documento</title>
      <type>d:text</type>
      <mandatory>true</mandatory>
      <constraints>
        <constraint type="LIST">
          <parameter name="allowedValues">
            <list>
              <value>Contratti ed incarichi</value>
              <value>Disposizioni di servizio</value>
              <value>Documentazione assunzione</value>
              <value>Documentazione contabile</value>
         <value>Documentazione personale riservata</value>
         <value>Documentazione previdenziale</value>
              <value>Titoli e formazione</value>
              <value>Varie</value>                    
            </list>
          </parameter>
          <parameter name="caseSensitive">
            <value>true</value>
          </parameter>
        </constraint>
      </constraints>
    </property>
  </properties>
</type> 



then, I configured Share advanced search with a "selectmany" control on the property with the LIST constraint (share-config-custom.xml):


<config evaluator="model-type" condition="abc:personaleDocumentazioneVaria">
      <forms>
         <form id="search">
            <field-visibility>
               <show id="abc:personaleDVCodiceFiscale" />
               <show id="abc:personaleDVMatricola" />
               <show id="abc:personaleDVCognome" />
               <show id="abc:personaleDVNome" />
               <show id="abc:personaleDVDataDocumento" />
               <show id="abc:personaleDVTiopDocumento" />
            </field-visibility>
            <appearance>
               <field id="abc:personaleDVDataDocumento">
                  <control template="/org/alfresco/components/form/controls/daterange.ftl" />
               </field>
                <field id="abc:personaleDVTiopDocumento">
                  <control template="/org/alfresco/components/form/controls/selectmany.ftl" >
                     <control-param name="size">8</control-param>
                     <control-param name="mode">OR</control-param>
                  </control>
               </field>             
            </appearance>
         </form>
      </forms>
   </config>


When I search without selecting list elements but only by other properties (for example abcSmiley TongueersonaleDVNome="Giuliano"), the query is correct, here an example of the query from the log:

((TYPE:"abc:personaleDocumentazioneVaria" AND (abc:personaleDVNome:"Giuliano")) AND -TYPE:"cm:thumbnail" AND -TYPE:"cm:failedThumbnail" AND -TYPE:"cm:rating") AND NOT ASPECT:"sys:hidden"


When I search selecting only one element from the list (for example abcSmiley TongueersonaleDVNome="Giuliano", abcSmiley TongueersonaleDVTiopDocumento:"Varie"), the query is correct, here an example of the query from the log:

((TYPE:"abc:personaleDocumentazioneVaria" AND (abc:personaleDVTiopDocumento:"Varie" AND abc:personaleDVNome:"Giuliano")) AND -TYPE:"cm:thumbnail" AND -TYPE:"cm:failedThumbnail" AND -TYPE:"cm:rating") AND NOT ASPECT:"sys:hidden"


But when I search selecting two or more items from the list (for example abcSmiley TongueersonaleDVNome="Giuliano", abcSmiley TongueersonaleDVTiopDocumento:"Varie", abcSmiley TongueersonaleDVTiopDocumento:"Titoli e formazione"), there is a syntax error in the query and the result is wrong, here an example of the query from the log:

((TYPE:"abc:personaleDocumentazioneVaria" AND (((abc:personaleDVTiopDocumento:"Titoli e formazione") OR (abc:personaleDVTiopDocumento:"Varie"))abc:personaleDVNome:"Giuliano")) AND -TYPE:"cm:thumbnail" AND -TYPE:"cm:failedThumbnail" AND -TYPE:"cm:rating") AND NOT ASPECT:"sys:hidden"


The correct query would be:

((TYPE:"abc:personaleDocumentazioneVaria" AND (((abc:personaleDVTiopDocumento:"Titoli e formazione") OR (abc:personaleDVTiopDocumento:"Varie")) AND abc:personaleDVNome:"Giuliano")) AND -TYPE:"cm:thumbnail" AND -TYPE:"cm:failedThumbnail" AND -TYPE:"cm:rating") AND NOT ASPECT:"sys:hidden"


Is this a bug? Is there a workaround?

Thank you very much in advance.

4 REPLIES 4

douglascrp
World-Class Innovator
World-Class Innovator
Yes, it seems to be a bug.
If you already know how it's creating the query, I think you already know where to make changes.

I've done some advanced search fixes, but I'm unable to find where I posted them.

douglascrp
World-Class Innovator
World-Class Innovator

ludo2000
Champ in-the-making
Champ in-the-making
Thank you very much for the link, the problem was similar.

I modified this file:
alfresco-4.2.c/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js

To fix the problem I added this line:

first = false;

after line number 882.

Old code was:

else if (isMultiValueProperty(propValue, modePropValue))
                  {
                     formQuery += (first ? '(' : ' AND (');
                     formQuery += processMultiValue(propName, propValue, modePropValue, false);
                     formQuery += ')';
                  }

New code is:

else if (isMultiValueProperty(propValue, modePropValue))
                  {
                     formQuery += (first ? '(' : ' AND (');
                     formQuery += processMultiValue(propName, propValue, modePropValue, false);
                     formQuery += ')';
                     first = false; // Added by Ludo
                  }
<code>
first = false;


Now the query is correct.

douglascrp
World-Class Innovator
World-Class Innovator
It seems it is another bug, right?

Having the variable and not changing its value seems to be a unfinished code.

Thank you for sharing your solution.