Sun Java System Portal Server 7 Developer's Guide

Multi-valued Attribute Routines

A SOIF attribute can have multiple values. SOIF supports the convention of using -NNN to indicate a multivalued attribute. For example, Title-1, Title-2, Title-3, and so on. The -NNN do not need to be sequential positive integers.

The Search Engine supports searching on multi-valued attributes such as the classification attribute. In SOIF representation, it is represented using classification-1, classification-2, and so on. For example:

classification-1{5}: robot
classification-2{5}: siroe
classification-3{10}: web crawler
SOIF_AttributeCompareMV
NSAPI_PUBLIC int SOIF_AttributeCompareMV(const char *a1, const char *a2);

Compares two attribute names. Returns 0 (zero) if they are equal, or non-zero if they are different. If neither of the attributes is multi-valued then use above routine SOIF_AttributeCompare(). If one or both of the attributes are multi-value, use the base name of the multi-valued attribute for comparison. The base name of a multi-valued attribute is the name portion before -. For example, the base name of classification-3 is classification.

SOIF_MVAttributeParse
NSAPI_PUBLIC int SOIF_MVAttributeParse(char *a)

Returns the multi-valued number of the given attribute, and strips the attribute string of its -NNN indicator; otherwise, returns zero in the case of a normal attribute name. For example, classification-3 returns the number 3.

SOIF_IsMVAttribute
NSAPI_PUBLIC char *SOIF_IsMVAttribute(const char *a);

Returns NULL if the given attribute is not a multi-valued attribute; otherwise returns a pointer to where the multi-valued number occurs in the attribute string. For example, for the multi-valued attribute classification-3, it will return the pointer to 3.

SOIF_InsertMV
NSAPI_PUBLIC int SOIF_InsertMV(SOIF *s, char *a, int slot, char *v, int vsz, int useval)

Inserts a new value v at index slot for the given attribute a (in non-multivalue form). If set, the useval flag tells the function to use the given value buffer rather than creating its own copy.

For example:

SOIF_InsertMV(s, "classification", 3, "web crawler", strlen("web crawler");

Inserts

classification-3{10}: web crawler
SOIF_ReplaceMV
NSAPI_PUBLIC int SOIF_ReplaceMV(SOIF *s, char *a, int slot, char *v, int vsz, int useval);
SOIF_DeleteMV
NSAPI_PUBLIC int SOIF_DeleteMV(SOIF *s, char *a, int slot)

Deletes the value at the index slot in the attribute a. For example:

SOIF_DeleteMV(s, "classification", 3)

Deletes classification-3.

SOIF_FindvalMV
NSAPI_PUBLIC const char *SOIF_FindvalMV(SOIF *s, const char *a, int slot)

Finds the value at the index slot in the attribute a. For example:

SOIF_FindvalMV(s, "classification", 3)

Returns web crawler (using the previous example).

SOIF_SqueezeMV
NSAPI_PUBLIC void SOIF_SqueezeMV(SOIF *s)

Forces a renumbering to ensure that the multi-value indexes are sequentially increasing (for example, 1, 2, 3,...). This function can be used to fill in any holes that might have occurred during SOIF_InsertMV() invocations. For example, to insert values explicitly for the multivalue attribute author-*:


SOIF_InsertMV(s, "author", 1, "John", 4, 0);
SOIF_InsertMV(s, "author", 2, "Kevin", 5, 0);
SOIF_InsertMV(s, "author", 6, "Darren", 6, 0);
SOIF_InsertMV(s, "author", 9, "Tommy", 5, 0);
SOIF_FindvalMV(s, "author", 9); /* == "Tommy" */
SOIF_SqueezeMV(s);
SOIF_FindvalMV(s, "author", 9); /* == NULL */
SOIF_FindvalMV(s, "author", 4); /* == "Tommy" */
SOIFAVPair_IsMV
#define SOIFAVPair_IsMV(avp)

Use this to determine if the AVPair has multiple values or not.

SOIFAVPair_NthValid
#define SOIFAVPair_NthValid(avp,n)

Use this to determine if the Nth value is valid or not.

SOIFAVPair_NthValue
#define SOIFAVPair_NthValue(avp,n)   ((avp)->values[n])

Use this to access the Nth value. For example:


for (i = 0; i <= avp->last_slot; i++)
  if (SOIFAVPair_NthValid(avp, i))
    printf("%s = %s\\n", avp->attribute,
      SOIFAVPair_NthValue(avp, i));
SOIFAVPair_NthVsize
#define SOIFAVPair_NthVsize(avp,n)   ((avp)->vsizes[n])

Use this to get the size of the Nth value.

SOIF_Contains
NSAPI_PUBLIC boolean_t SOIF_Contains(SOIF *s, char *a, char *v, int vsz);

Indicates if the given attribute contains the given value. It returns B_TRUE if the value matches one or more of the values of the attribute a in the given SOIF s.