talk@lists.collectionspace.org

WE HAVE SUNSET THIS LISTSERV - Join us at collectionspace@lyrasislists.org

View all threads

Tip: enabling both wildcard and range search on a field

RL
Ray Lee
Tue, Dec 4, 2012 8:43 AM

Hi Everyone,
On the advanced search screen, we needed to be able to do both wildcard and
range search on a field. I was happy to find that this is possible with
some app layer configuration. The following example shows how to do this
configuration for the objectNumber field on CollectionObjects.

In base-collectionobject.xml, the objectNumber field is set to have
multi-value wildcard search, with the ui-search="repeatable" attribute:

<field id="objectNumber" ui-search="repeatable"/>

In your tenant overlay, you can add another field, also tied to
objectNumber in the services layer, but configured for range search.
The id doesn't matter, as long as it's unique:

<field id="objectNumberRangeSearch" ui-search="range" exists-in-services="false">
<services-tag>objectNumber</services-tag>

</field>

The services-tag element tells the app layer to map the field to a
different name in the services layer. The exists-in-services attribute
is set to false, which seems contradictory; however, this is necessary
to keep the app layer from actually saving the value of
objectNumberRangeSearch to the services layer when a CollectionObject
is edited. If it did, it would attempt to set objectNumber twice: once
for the objectNumber app layer field, and once for the
objectNumberRangeSearch app layer field. Since you're not going to add
objectNumberRangeSearch to the record editor form, it will always be
empty, which could result in objectNumber being set to empty in the
services layer. Conveniently, when exists-in-services is false, it
does not prevent the field from being used as a search filter.
(There's another attribute that would prevent a field from being used
as a search filter: query-behavior="ignore".)

In the UI layer, you can then add fields for
objectNumberRangeSearchStart and objectNumberRangeSearchEnd, as you
would for any range search field. Our resulting advanced search form
looks like this:

[image: Inline image 1]

The wildcard and range filters are OR'ed or AND'ed together, as with
any other search filters.

The jira issue for this work is at
http://issues.collectionspace.org/browse/UCBG-117. I hope this is
helpful for someone out there!

Thanks,

Ray

Hi Everyone, On the advanced search screen, we needed to be able to do both wildcard and range search on a field. I was happy to find that this is possible with some app layer configuration. The following example shows how to do this configuration for the objectNumber field on CollectionObjects. In base-collectionobject.xml, the objectNumber field is set to have multi-value wildcard search, with the ui-search="repeatable" attribute: <field id="objectNumber" ui-search="repeatable"/> In your tenant overlay, you can add another field, also tied to objectNumber in the services layer, but configured for range search. The id doesn't matter, as long as it's unique: <field id="objectNumberRangeSearch" ui-search="range" exists-in-services="false"> <services-tag>objectNumber</services-tag> </field> The services-tag element tells the app layer to map the field to a different name in the services layer. The exists-in-services attribute is set to false, which seems contradictory; however, this is necessary to keep the app layer from actually saving the value of objectNumberRangeSearch to the services layer when a CollectionObject is edited. If it did, it would attempt to set objectNumber twice: once for the objectNumber app layer field, and once for the objectNumberRangeSearch app layer field. Since you're not going to add objectNumberRangeSearch to the record editor form, it will always be empty, which could result in objectNumber being set to empty in the services layer. Conveniently, when exists-in-services is false, it does not prevent the field from being used as a search filter. (There's another attribute that would prevent a field from being used as a search filter: query-behavior="ignore".) In the UI layer, you can then add fields for objectNumberRangeSearchStart and objectNumberRangeSearchEnd, as you would for any range search field. Our resulting advanced search form looks like this: [image: Inline image 1] The wildcard and range filters are OR'ed or AND'ed together, as with any other search filters. The jira issue for this work is at http://issues.collectionspace.org/browse/UCBG-117. I hope this is helpful for someone out there! Thanks, Ray
JM
Jesse Martinez
Tue, Dec 4, 2012 3:27 PM

This is great, Ray. This technique works in v2.4 and above, I take it?

  • Jesse

On Tue, Dec 4, 2012 at 3:43 AM, Ray Lee rhlee@berkeley.edu wrote:

Hi Everyone,
On the advanced search screen, we needed to be able to do both wildcard
and range search on a field. I was happy to find that this is possible with
some app layer configuration. The following example shows how to do this
configuration for the objectNumber field on CollectionObjects.

In base-collectionobject.xml, the objectNumber field is set to have
multi-value wildcard search, with the ui-search="repeatable" attribute:

<field id="objectNumber" ui-search="repeatable"/>

In your tenant overlay, you can add another field, also tied to objectNumber in the services layer, but configured for range search. The id doesn't matter, as long as it's unique:

<field id="objectNumberRangeSearch" ui-search="range" exists-in-services="false"> <services-tag>objectNumber</services-tag> </field>

The services-tag element tells the app layer to map the field to a different name in the services layer. The exists-in-services attribute is set to false, which seems contradictory; however, this is necessary to keep the app layer from actually saving the value of objectNumberRangeSearch to the services layer when a CollectionObject is edited. If it did, it would attempt to set objectNumber twice: once for the objectNumber app layer field, and once for the objectNumberRangeSearch app layer field. Since you're not going to add objectNumberRangeSearch to the record editor form, it will always be empty, which could result in objectNumber being set to empty in the services layer. Conveniently, when exists-in-services is false, it does not prevent the field from being used as a search filter. (There's another attribute that would prevent a field from being used as a search filter: query-behavior="ignore".)

In the UI layer, you can then add fields for objectNumberRangeSearchStart and objectNumberRangeSearchEnd, as you would for any range search field. Our resulting advanced search form looks like this:

[image: Inline image 1]

The wildcard and range filters are OR'ed or AND'ed together, as with any other search filters.

The jira issue for this work is at http://issues.collectionspace.org/browse/UCBG-117. I hope this is helpful for someone out there!

Thanks,

Ray


Talk mailing list
Talk@lists.collectionspace.org

http://lists.collectionspace.org/mailman/listinfo/talk_lists.collectionspace.org

This is great, Ray. This technique works in v2.4 and above, I take it? - Jesse On Tue, Dec 4, 2012 at 3:43 AM, Ray Lee <rhlee@berkeley.edu> wrote: > Hi Everyone, > On the advanced search screen, we needed to be able to do both wildcard > and range search on a field. I was happy to find that this is possible with > some app layer configuration. The following example shows how to do this > configuration for the objectNumber field on CollectionObjects. > > In base-collectionobject.xml, the objectNumber field is set to have > multi-value wildcard search, with the ui-search="repeatable" attribute: > > <field id="objectNumber" ui-search="repeatable"/> > > > In your tenant overlay, you can add another field, also tied to objectNumber in the services layer, but configured for range search. The id doesn't matter, as long as it's unique: > > > <field id="objectNumberRangeSearch" ui-search="range" exists-in-services="false"> > <services-tag>objectNumber</services-tag> > > </field> > > > The services-tag element tells the app layer to map the field to a different name in the services layer. The exists-in-services attribute is set to false, which seems contradictory; however, this is necessary to keep the app layer from actually saving the value of objectNumberRangeSearch to the services layer when a CollectionObject is edited. If it did, it would attempt to set objectNumber twice: once for the objectNumber app layer field, and once for the objectNumberRangeSearch app layer field. Since you're not going to add objectNumberRangeSearch to the record editor form, it will always be empty, which could result in objectNumber being set to empty in the services layer. Conveniently, when exists-in-services is false, it does not prevent the field from being used as a search filter. (There's another attribute that would prevent a field from being used as a search filter: query-behavior="ignore".) > > > In the UI layer, you can then add fields for objectNumberRangeSearchStart and objectNumberRangeSearchEnd, as you would for any range search field. Our resulting advanced search form looks like this: > > > [image: Inline image 1] > > > The wildcard and range filters are OR'ed or AND'ed together, as with any other search filters. > > > The jira issue for this work is at http://issues.collectionspace.org/browse/UCBG-117. I hope this is helpful for someone out there! > > > Thanks, > > Ray > > > > _______________________________________________ > Talk mailing list > Talk@lists.collectionspace.org > > http://lists.collectionspace.org/mailman/listinfo/talk_lists.collectionspace.org > >