How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

cancel
Showing results for 
Search instead for 
Did you mean: 
anon26949
Established Member

How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

For example, I have a type "Contract":

<type name="some-prefix:contract">
    <title>Contract</title>
    <parent>cm:content</parent>
    <mandatory-aspects>
        ...
        <aspect>some-prefix:resolution</aspect>
    </mandatory-aspects>
</type>

This type contains an aspect:

<aspect name="some-prefix:resolution">
    <title>Resolution</title>
    <properties>
        ...
        <property name="some-prefix:isCoordinated">
            <type>d:boolean</type>
            <default>false</default>
        </property>
    </properties>
</aspect>

By using this aspect, I set the state of the contract and trying to retrieve approptiate node:

...
getParameters : function Contract_getParameters() {
     var param = "term=";
     var query = "+TYPE:some-prefix\\:contract";
     if (this.widgets.filter.value == "inactive")
          query += " +@some-prefix\\:isCoordinated:false";
     else
          query += " +@some-prefix\\:isCoordinated:true";
     param += encodeURIComponent(query);
     return param;
},

getWebscriptUrl : function Contract_getWebscriptUrl() {
     return Alfresco.constants.PROXY_URI + "slingshot/search";
},
...

If I use only this part, then I get the whole list of contracts:

var query = "+TYPE:some-prefix\\:contract";

But if I add an additional condition, for example:

query += " +@some-prefix\\:isCoordinated:true";

Then in this case I get an empty list.

By using the Node Browser I found, that my query works:

+TYPE:some-prefix\:contract +@some-prefix\:isCoordinated:true

But when I call Alfresco Search WebScript from JavaScript controller I get the following:

{
     "totalRecords": 0,
     "totalRecordsUpper": 0,
     "startIndex": 0,
     "numberFound": 0,
     "facets":
     {
     },
   "highlighting":
   {
   },
     "items":
     [
     ],
     "spellcheck":
     {
     }
}

What could be the reason?..

I would be very grateful for the information. Thanks to all.

1 Solution

Accepted Solutions
mehe
Senior Member II

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

I think you did everything right. Maybe the slingshot search is just not working for booleans. Could you try to use a non boolean for your filter instead - just for testing?

Just besides: I use the slingshot-url ..../alfresco/slingshot (without the proxy) and a ticket parameter for authentication but cannot remember if I ever used a boolean in the query... 

You can see the parameters and the url that is formed by share for the slingshot query, if you use chrome or firefox developer tools and emit an advanced search - but I think you already know that.

Just another thought:   What happens if you just search for your boolean field, without a value?   some-prefix:isCoordinated    Or some-prefix:isCoordinated:"true"...

View solution in original post

8 Replies
mehe
Senior Member II

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

Hi,

for slingshot search, you don't need the "+" sign, because "AND" is the default operator. Nor you use "@"

Try

query='TYPE:"some-prefix:contract"';
...
query += ' some-prefix:isCoordinated:true';
‍‍‍

you can test your query on the slingshot search page (Alfresco advanced search). You can use the fieldnames there too.

If you use Alfresco 5.2 there is also a new search rest api (see api-explorer)

anon26949
Established Member

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

Hi, Martin!

Thank you very much for your answer, I'll try to do it now.

anon26949
Established Member

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

Am I making the request correctly?..

For example:

...
var param = 'term=';
var query = 'TYPE:\"some-prefix:contract\"';
query += ' some-prefix:isCoordinated:false';
param += encodeURIComponent(query);
...‍‍‍‍‍‍

Then I add the 'param' here:

http://...:8080/share/proxy/alfresco/slingshot/search?‍‍

The resulting query looks like the following:

http://...:8080/share/proxy/alfresco/slingshot/search?term=TYPE%3A%22some-prefix%3Acontract%22%20some-prefix%3AisCoordinated%3Afalse‍

But I get empty list:

{
     "totalRecords": 0,
     "totalRecordsUpper": 0,
     "startIndex": 0,
     "numberFound": 0,
     "facets":
     {
     },
   "highlighting":
   {
   },
     "items":
     [
     ],
     "spellcheck":
     {
     }
}

If I remove an additional condition, the query returns the entire list of contracts:

http://...:8080/share/proxy/alfresco/slingshot/search?term=TYPE%3A%22some-prefix%3Acontract%22‍

Where am I wrong?..

mehe
Senior Member II

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

I think you did everything right. Maybe the slingshot search is just not working for booleans. Could you try to use a non boolean for your filter instead - just for testing?

Just besides: I use the slingshot-url ..../alfresco/slingshot (without the proxy) and a ticket parameter for authentication but cannot remember if I ever used a boolean in the query... 

You can see the parameters and the url that is formed by share for the slingshot query, if you use chrome or firefox developer tools and emit an advanced search - but I think you already know that.

Just another thought:   What happens if you just search for your boolean field, without a value?   some-prefix:isCoordinated    Or some-prefix:isCoordinated:"true"...

anon26949
Established Member

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

Great idea! Thank you very much, will try it now...

anon26949
Established Member

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

Excellent! You are right - I used the advanced search and in the network console I found all needed parameters.

The right query looks like this:

http://localhost:8080/share/proxy/alfresco/slingshot/search/?query=%7B%22prop_some-prefix_isCoordinated%22%3A%22true%22%2C%22datatype%22%3A%22some-prefix%3Acontract%22%7D

In decode view:

{"prop_some-prefix_isCoordinated":"true","datatype":"some-prefix:contract"}

Thank you very much again!..

mehe
Senior Member II

Re: How to filtering types by properties in JavaScript controller using the Alfresco Search WebScript?

Jump to solution

Hi Aleksey,

Thank you very much for sharing your results - not everybody does this, and I think this is very helpful to understand and solve the problem for others who face the same issues. 

PS: have you examined the new search REST-API in Alfresco 5.2? I will try to get rid of my "slingshot" searches and use the new api, because the slingshot thing ist not a real API.

anon26949
Established Member

Deleted.

Jump to solution

Deleted.