Can I apply a template for each word on a phrase?

cancel
Showing results for 
Search instead for 
Did you mean: 
DI_SI_GO
Member II

Can I apply a template for each word on a phrase?

Jump to solution
I am using Alfresco Rest API (/alfresco/api/-default-/public/search/versions/1/search)
I perform the following search:  
{
    "query": {
        "query": "WOOF:((H) (A minor) (Anor))"
    },
    "defaults": {
        "defaultFTSOperator": "AND",
        "defaultFTSFieldOperator": "OR"
    },
    "templates": [
        {
            "name": "WOOF",
            "template": "(%content OR %cm:title) AND TYPE:content"
        }
    ]
}
And I get like 200 results, but if I search the same:  (H) (A minor) (Anor) in Alfresco Share ,I get about 500 results. I found that it does something like this: 
{
    "query": {
        "query": "((WOOF:(H)) (WOOF:(A minor)) (WOOF:(Anor)))"
    },
    "defaults": {
        "defaultFTSOperator": "AND",
        "defaultFTSFieldOperator": "OR"
    },
    "templates": [
        {
            "name": "WOOF",
            "template": "(%cm:content OR %cm:title) AND TYPE:content"
        }
    ]
}
(Note: I know that Alfresco Shares uses an internal API/slingshot and that's why there are variations, so I am trying to kind of duplicate its behavior).
 
So, the previous query gives me the results that I am looking for, but to accomplish that, I had to add the WOOF template as prefix of each term.
 
Is there a way to achieve this without adding the template per term? because the user its just going to type: (H) (A minor) (Anor)  and what I expect, is the outcome of this last query.
1 Solution

Accepted Solutions
afaust
Master

Re: Can I apply a template for each word on a phrase?

Jump to solution

Before going into the question of the template: The use of parantheses to group query inputs is extremely weird. I don't know if the search would really be executed in a way that a user would expect.

WOOF:((H) (A minor) (Anor))

=> Given your default FTS operator + field operator config, this would effectively search for

WOOF:H OR WOOF:A OR WOOF:minor OR WOOF:Anor

=> where I would expect the user that rather intends to find what the following query would return

WOOF:H OR WOOF:"A minor" OR WOOF:Anor

 

As for the template: The thing is that templates are applied before field term groupings are expanded. So

WOOF:(A B)

becomes

(cm:content:(A B) OR cm:title:(A B)) AND TYPE:content

What is happening in Share is that - I assume - someone has customised it to apply WOOF as the default field name when no field name is explicitly set, and as a result, the input (A B) would be turned into

(WOOF:A WOOF:B)

You should be able to achieve the same with ReST API by specifying the defaultFieldName property with the value of WOOF in the search request JSON.

View solution in original post

2 Replies
afaust
Master

Re: Can I apply a template for each word on a phrase?

Jump to solution

Before going into the question of the template: The use of parantheses to group query inputs is extremely weird. I don't know if the search would really be executed in a way that a user would expect.

WOOF:((H) (A minor) (Anor))

=> Given your default FTS operator + field operator config, this would effectively search for

WOOF:H OR WOOF:A OR WOOF:minor OR WOOF:Anor

=> where I would expect the user that rather intends to find what the following query would return

WOOF:H OR WOOF:"A minor" OR WOOF:Anor

 

As for the template: The thing is that templates are applied before field term groupings are expanded. So

WOOF:(A B)

becomes

(cm:content:(A B) OR cm:title:(A B)) AND TYPE:content

What is happening in Share is that - I assume - someone has customised it to apply WOOF as the default field name when no field name is explicitly set, and as a result, the input (A B) would be turned into

(WOOF:A WOOF:B)

You should be able to achieve the same with ReST API by specifying the defaultFieldName property with the value of WOOF in the search request JSON.

DI_SI_GO
Member II

Re: Can I apply a template for each word on a phrase?

Jump to solution

Thanks, yes that was what I was looking for.

 

Regards.