How to search by property in custom model

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
tomekszy
Active Member

How to search by property in custom model

Jump to solution

Hi,

I'm looking for a way to search by custom field in my custom aspect. I found some information, like https://www.bluefishgroup.com/insights/ecm/adding-metadata-fields-to-simple-search-and-live-search-w... or How to search metadata of documents ,but it seems very complicated. I can't find XML files, which are mentioned in these documents:

For example in first document from BlueFishGroup, there is information, that files

  • live-search-docs.get.config.xml
  • search.get.config.xml

should be extracted from file tomcat/webapps/alfresco/WEB-INF/lib/alfresco-remote-api-5.0.2.1.jar, from directory alfresco/templates/webscripts/org/alfresco/slingshot/search/, but I don't have that directory in this JAR file (in alfresco/templates/webscripts/org/alfresco/slingshot/ there are only directories called calendar and quadds, there is no search). Also even if I somehow would find this file, it is written, that

These files can now be modified to add additional metadata fields as needed. Once the files have been updated, they should be deployed to the ‘extensions’ directory so that they will override the out of the box configuration. If you are deploying your code as a custom AMP file, the files should target the following directory:

  • tomcat/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search

I don't want to deploy it as a custom AMP, so I assume I should copy them to 'extension' directory. But where is that? Should i put them to those JAR file? Or should it be tomcat/webapps/alfresco/WEB-INF/classes/alfresco/extension directory? Or maybe  /tomcat/shared/classes/alfresco/extension/ ?

I'm looking for help in that matter, because I'm begginer in Alfresco, and I just don't have enough knowledge to do that.

In second document, there is information, that if I want to search by custom metadata, I should write a webscript, and it is way over my knowledge.

Maybe there are some other ways to do that? I just can't believe, that managing so basic procedure, as searching by metadata is so complicated to insert.

1 Solution

Accepted Solutions
kalpesh_c2
Senior Member

Re: How to search by property in custom model

Jump to solution

Hi

I don't know whether you created custom aspect properly. If you want to create custom aspect, you need to create model file and register it through context file.You can place these files in tomcat/shared/classes/alfresco/extension. In extension folder you may find "exampleModel.xml.sample", make a copy of that file in same folder(extension) and remove its .sample extension and make .xml file. After that, edit imports if you want to inherit some aspect defined in other content model this comes under <imports> tag. If you don't want inheritance , keep it as it is. Under <namespaces> tag create your namespace by giving unique URI and prefix. Remove the <types> element. And edit the <aspects> element and define your custom aspect there by giving it's name and add your custom properties in <properties> element. Also in order to make your property indexed add index tag and define its enabled attribute to "true" as code snippet given below:

<index enabled="true">
    <tokenised>TRUE</tokenised>
    <facetable>false</facetable>
</index>

At this stage you created custom model which contains your aspect. In order to make alfresco to know your model register it with spring bean from a context file. You can also get sample context file example-model-context.xml, copy it and change its extension as you did before and in that file edit <beans> element and change bean id. And also change the path of the model file to the model file created by you.

After restart of alfresco service this model will be created and you can apply your aspect to any content in repository and can also search its properties through REST API or CMIS or alfresco share.

Here I am assuming you are using share. In order to make your aspect visible to share, edit share-config-custom.xml file present in tomcat/shared/classes/alfresco/web-extension(create if it is not present). Add aspect created by you to <visible> element. And you can edit or create advanced search forms through by placing this code in the same file.

Refer this code if you want to register your own advanced search form

<config replace='true' 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>
        </forms>
      </advanced-search>
  </config>

And Refer this code to create or edit form

<config evaluator='model-type' condition='cm:folder'>
      <forms>
         <form id='doclib-common'>
            <field-visibility>
               <show id='cm:name' />
               <show id='cm:title' force='true' />
               <show id='cm:description' force='true' />
            </field-visibility>
            <create-form template='../documentlibrary/forms/doclib-common.ftl' />
            <appearance>
               <field id='cm:title'>
                  <control template='/org/alfresco/components/form/controls/textfield.ftl' />
               </field>
            </appearance>
         </form>
         <form id='search'>
            <field-visibility>
               <show id='cm:name' />
               <show id='cm:title' force='true' />
               <show id='cm:description' force='true' />
            </field-visibility>
         </form>
      </forms>
   </config>

For further details you can go through this link

Apart from share, if you are using CMIS then you can search your properties through query. Or you can also search it by REST APIs provided by alfresco.

Thanks,

Kalpesh

ContCentric

13 Replies
Moderator
Moderator

Re: How to search by property in custom model

Jump to solution

Hi,

First could you tell us what version of Alfresco do you use ? It will help to look into the right code base.

For example in the latest version of Alfresco, the files are located in the share-services :

share/live-search-docs.get.config.xml at master · Alfresco/share · GitHub

And

share/search.get.config.xml at master · Alfresco/share · GitHub

If you can't find it in alfresco-remote-api jar look for a jar called share-services.

Regards

kaynezhang
Intermediate

Re: How to search by property in custom model

Jump to solution

Both live-search-docs.get.config.xml and search.get.config.xml are packaged in

alfresco-share-services-***.jar under path alfresco/templates/webscripts/org/alfresco/slingshot/search

Yes you can place it at tomcat/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search

but it is recommeded to place it at /tomcat/shared/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search (make sure /tomcat/shared/classes is configured in your classpah).

cesarista
Advanced

Re: How to search by property in custom model

Jump to solution

Hi:

A direct way of searching for a custom metadata of your content model (without developing) is just to put in Alfresco search something like:

ASPECT:"mycustom:somethingable"  

@mycustomSmiley Tongueroperty:"whatever"

http://docs.alfresco.com/4.2/concepts/rm-searchsyntax-intro.html

Regards.

--C.

tomekszy
Active Member

Re: How to search by property in custom model

Jump to solution

I don't have neither of this directories....

instead of

tomcat/webapps/alfresco/WEB-INF/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search

I have

/home/alfresco/alfresco-community/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts/org/alfresco/slingshot/rmsearch

- this one is most similar

and instead of

/tomcat/shared/classes/alfresco/extension/templates/webscripts/org/alfresco/slingshot/search

I have

/home/alfresco/alfresco-community/tomcat/shared/classes/alfresco/extension

- and thats it, no templates directory.

Maybe I should made them? But I assume, that if they not exist, Alfresco would not reach to them. Where can I find place to put files?

kaynezhang
Intermediate

Re: How to search by property in custom model

Jump to solution

If the folder dose not exist ,please just create it ,it will work. Alfresco will search the folder.

tomekszy
Active Member

Re: How to search by property in custom model

Jump to solution

Thank you, I 'll try that.

But where should I copy files :

  • exampleModel.xml.sample
  • example-model-context.xml.sample

after editing them, and removing .sample suffix ? To the same directory as search XMLs? Or leave it with other samle files in /home/alfresco/alfresco-community/tomcat/shared/classes/alfresco/extension directory?

kaynezhang
Intermediate

Re: How to search by property in custom model

Jump to solution

exampleModel.xml.sample/example-model-context.xml.sample are located in  /home/alfresco/alfresco-community/tomcat//webapps/alfresco/WEB-INF/lib/alfresco-repository-**.jar under path /alfrescoextension

Copy them in to /home/alfresco/alfresco-community/tomcat/shared/classes/alfresco/extension and rename them to exampleModel.xml//example-model-context.xml.

kalpesh_c2
Senior Member

Re: How to search by property in custom model

Jump to solution

Hi

I don't know whether you created custom aspect properly. If you want to create custom aspect, you need to create model file and register it through context file.You can place these files in tomcat/shared/classes/alfresco/extension. In extension folder you may find "exampleModel.xml.sample", make a copy of that file in same folder(extension) and remove its .sample extension and make .xml file. After that, edit imports if you want to inherit some aspect defined in other content model this comes under <imports> tag. If you don't want inheritance , keep it as it is. Under <namespaces> tag create your namespace by giving unique URI and prefix. Remove the <types> element. And edit the <aspects> element and define your custom aspect there by giving it's name and add your custom properties in <properties> element. Also in order to make your property indexed add index tag and define its enabled attribute to "true" as code snippet given below:

<index enabled="true">
    <tokenised>TRUE</tokenised>
    <facetable>false</facetable>
</index>

At this stage you created custom model which contains your aspect. In order to make alfresco to know your model register it with spring bean from a context file. You can also get sample context file example-model-context.xml, copy it and change its extension as you did before and in that file edit <beans> element and change bean id. And also change the path of the model file to the model file created by you.

After restart of alfresco service this model will be created and you can apply your aspect to any content in repository and can also search its properties through REST API or CMIS or alfresco share.

Here I am assuming you are using share. In order to make your aspect visible to share, edit share-config-custom.xml file present in tomcat/shared/classes/alfresco/web-extension(create if it is not present). Add aspect created by you to <visible> element. And you can edit or create advanced search forms through by placing this code in the same file.

Refer this code if you want to register your own advanced search form

<config replace='true' 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>
        </forms>
      </advanced-search>
  </config>

And Refer this code to create or edit form

<config evaluator='model-type' condition='cm:folder'>
      <forms>
         <form id='doclib-common'>
            <field-visibility>
               <show id='cm:name' />
               <show id='cm:title' force='true' />
               <show id='cm:description' force='true' />
            </field-visibility>
            <create-form template='../documentlibrary/forms/doclib-common.ftl' />
            <appearance>
               <field id='cm:title'>
                  <control template='/org/alfresco/components/form/controls/textfield.ftl' />
               </field>
            </appearance>
         </form>
         <form id='search'>
            <field-visibility>
               <show id='cm:name' />
               <show id='cm:title' force='true' />
               <show id='cm:description' force='true' />
            </field-visibility>
         </form>
      </forms>
   </config>

For further details you can go through this link

Apart from share, if you are using CMIS then you can search your properties through query. Or you can also search it by REST APIs provided by alfresco.

Thanks,

Kalpesh

ContCentric

tomekszy
Active Member

Re: How to search by property in custom model

Jump to solution

Hey

I did it thanks to Kalpesh Patel's description (by the way Dobra robota). Thank you very much. But I have one small problem. Properties from my aspects are often lists of predefinied vavues, when one option is already selected, like here:

so if i'm searching anything I have to chose one value from list (in this example, in 'Rodzaj' or 'Projekt Rok' property, there are selected 'Publikacje' and '2000'), but I want be able to search something, that hasn't got my aspect's properties filled, or just search something by only one property.

So I assume, I need to have some "universal" value, which will be some kind of widcard for all other values, but of course if I just add one extra value (named for example "undefinied"), it won't do the trick.

So my question is, how to do that?