cancel
Showing results for 
Search instead for 
Did you mean: 

How to set/get multiple-value property programmatically?

llin
Champ in-the-making
Champ in-the-making
Hello,

My data model has a property with multiple values:

<property name="tal:software">
   <type>d:text</type>
   <multiple>true</multiple>
   <constraints>
      <constraint ref="tal:softwareList" />
   </constraints>
</property>

How can I save those property values into Alfresco using my application? I also have problem with getting those values in Alfresco to my application? The following code from Alfresco SDK examples, works with normal properties, but not for property with multiple values.

Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString );
QueryResult queryResult = getRepositoryService().query(LilacConstants.STORE, query, false);
ResultSet resultSet = queryResult.getResultSet();
ResultSetRow[] rows = resultSet.getRows();

for(ResultSetRow row : rows) {
for (NamedValue namedValue : row.getColumns()) {
         if (namedValue.getName().endsWith(Constants.PROP_NAME) == true) {
                 contentResult.setName(namedValue.getValue());
         }
…..


The above "tal:software" property is not inside "NamedValue", so I can't get them into my application.

Any idea or suggestion? Thanks a lot.


Ally
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
To set properties with the "multiple=true" attribute, you set the value to a List of the type - so a List of size 1 for a single value. In your case, since it's a d:text, you will create a List<String>. Remember that you will also get a List back - even if there is only a single value in it.

Thanks,

Kevin

rulo
Champ in-the-making
Champ in-the-making
When I search from the Alfresco Advanced Search and I write a value of this property it doesnt work. I mean, lets say that there is a property "P" with multiple values (<multiple>true</multiple> ), and I upload a file setting this property value with two values:  "a"  and "b".
When I write "a" or " b" in the text box of this property in the advance search section, no file  is founded.
Is there a solution to this?
Thanks in advance

andy
Champ on-the-rise
Champ on-the-rise
Hi

Multi-valued properties are indexed correctly.

If you search for "a" it may vanish as a stop word in the tokenisation - perhaps you need identifiers or to try something else.

If this does not work try running the query direct in the node browser or post the debug form the UI query generation. Post the query you are using in the SDK sample.

Andy

rulo
Champ in-the-making
Champ in-the-making
Hi Andy, thanks for answer.
The solution is to set the index tag with the value true and the tokenised tag to the same value. Something like this:

<property>
  <type>d:text</type>
  <multiple>true</multiple>
  <index enabled="true">
      <tokenised>true</tokenised>
  </index>
</property>

Doing this, the search engine will search by the value of this kind of property.