com.facetmap.sql
Class ResourceIdFacet

java.lang.Object
  extended by com.facetmap.sql.ResourceIdFacet
All Implemented Interfaces:
Facet, SqlFacet

public class ResourceIdFacet
extends java.lang.Object
implements SqlFacet

This facet lets Facetmap incorporate external searches (searches on other data which is not part of the FacetSpace) in creating a Selection. This makes it possible to integrate any other search/browse functionality you have, as long as it can return a set of integer IDs that correspond to the IDs in the facetmap's ResourceSpace.

For example, a full-document text search may be implemented on your system (let's say, for this example, it isn't feasible to represent that system as a KeywordFacet). You can perform that search yourself, get a result set expressed as integer IDs, and pass those IDs to SqlFacetmap.getSelection in a Heading. The returned Selection will contain only Resources from that set.

Or, if you want Facetmap to control the events, you can wrap your search in a ResourceIdQuery object, and provide that object to the ResourceIdFacet. SqlFacetmap will invoke the ResourceIdQuery with a String (the ID of the heading) and combine its results (expressed, again, as an array of Resource IDs) with those of the other facets. Facetmap will track the query parameters of your search as the user continues browsing.

Here's an example. Let's say you have a search engine that will find images containing a certain person's face, and you submit the face to the engine as an image. Facetmap doesn't support that, but as long as the magic face finder returns the integer keys to its results, Facetmap can combine those keys with its own searches. First we write a ResourceIdQuery:

    public class FaceSearcherIdQuery implements ResourceIdQuery {

        // We need this in order to persist face query data as the user
        // browses. It would probably be unreasonable to serialize the
        // entire byte array into a string ID, so instead we'll use this
        // persistent cache. The cache could also be stored in a HttpSession
        // for the user, if one exists, or some other managed persistence.
        Hashtable faceDataCache;

        // Store a new face image in cache, and return the string key.
        public String storeFace(byte[] faceData) {
            String id = String.valueOf(faceData.hashCode());
            faceDataCache.put(id, faceData);
            return id;
        }

        // Wrap the logic to convert our string ID into a result set of ints.
        // The MagicFaceFinder and the FaceResultSet classes are, of course,
        // invented for this example.
        public int[] getResourceIdHeading(String id) {
            byte[] face = (byte[])this.faceDataCache.get(id);
            FaceResultSet resultSet = MagicFaceFinder.search(face);
            int[] ids = new int[resultSet.size()];
            for (int i=0; i<ids.length; i++) {
                ids[i] = resultSet.get(i).getId();
            }
            return ids;
        }

        // Just return the ID as the title. Add more interesting logic
        // as appropriate.
        public String getDisplayTitle(String headingId) {
            return headingId;
        }
    }
   
... which is used in the following construction code:
    Facetmap source; // from somewhere else
    SqlFacetmapBuilder factory = new SqlFacetmapBuilder(source, new Properties());
    FaceSearcherIdQuery faceQuery = new FaceSearcherIdQuery();
    factory.addResourceIdFacet("face","Face Finder", faceQuery);
    SqlFacetmap facetmap = factory.generateSqlFacetmap();
   
Then: when you find that a user, while doing faceted browsing, has submitted a face image to search for, blend that into the search:
    String ref; // Facetmap's Selection string ref, taken from browsing context
    byte[] face; // read from browsing context by your own code

    ResourceIdFacet facet = facetmap.getResourceIdFacet("face");
    String headingId = faceQuery.storeFace(face);
    List headings = Arrays.asList(facetmap.getRefCodec().decodeRef(ref));
    headings.add(new ResourceIdHeading(
        headingId,
        faceQuery.getDisplayTitle(headingId),
        faceQuery.getResourceIdHeading(headingId),
        facet
    ));
    Selection selection = facetmap.getSelection((Heading[])headings.toArray());
    // work with Selection as usual
   


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.facetmap.Facet
Facet.Util
 
Constructor Summary
ResourceIdFacet(java.lang.String id, java.lang.String title, ResourceIdQuery resourceIdQuery)
           
 
Method Summary
 Heading getHeading(java.lang.String id)
          Implementation of Facet's getHeading; functionally identical to getResourceIdHeading(String).
 java.lang.String getId()
          Unique identifier.
 ResourceIdHeading getResourceIdHeading(int[] ids)
          This creates a valid ResourceIdHeading that can be passed into a getSelection() method.
 ResourceIdHeading getResourceIdHeading(java.lang.String headingId)
          Passes the specified heading ID to this object's ResourceIdQuery if there is a ResourceIdQuery; otherwise returns null.
 Heading getRootHeading()
          A facet structure is rooted at the heading returned by this method.
 SqlFacetSpace getSqlFacetSpace()
           
 Heading getSqlHeading(Heading sourceHeading)
          This type of facet has no equivalent outside the com.facetmap.sql package, so this method always throws UnsupportedOperationException.
 java.lang.String getTitle()
          The descriptive name of this structure, for display to users.
 void setId(java.lang.String id)
           
 void setSqlFacetSpace(SqlFacetSpace sqlFacetSpace)
           
 void setTitle(java.lang.String title)
           
 void sqlCreate(java.sql.Connection connection, java.lang.String vendor)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceIdFacet

public ResourceIdFacet(java.lang.String id,
                       java.lang.String title,
                       ResourceIdQuery resourceIdQuery)
Method Detail

getResourceIdHeading

public ResourceIdHeading getResourceIdHeading(java.lang.String headingId)
Passes the specified heading ID to this object's ResourceIdQuery if there is a ResourceIdQuery; otherwise returns null.


getResourceIdHeading

public ResourceIdHeading getResourceIdHeading(int[] ids)
This creates a valid ResourceIdHeading that can be passed into a getSelection() method. However, it will be an anonymous Heading, with no ID (so it can't be remembered by Facetmap during browsing) and no title (so it can't be rendered in the UI).


getSqlFacetSpace

public SqlFacetSpace getSqlFacetSpace()
Specified by:
getSqlFacetSpace in interface SqlFacet

setSqlFacetSpace

public void setSqlFacetSpace(SqlFacetSpace sqlFacetSpace)
Specified by:
setSqlFacetSpace in interface SqlFacet

sqlCreate

public void sqlCreate(java.sql.Connection connection,
                      java.lang.String vendor)
               throws java.sql.SQLException
Specified by:
sqlCreate in interface SqlFacet
Throws:
java.sql.SQLException

getHeading

public Heading getHeading(java.lang.String id)
                   throws UnknownReferenceException
Implementation of Facet's getHeading; functionally identical to getResourceIdHeading(String).

Specified by:
getHeading in interface Facet
Throws:
UnknownReferenceException

getSqlHeading

public Heading getSqlHeading(Heading sourceHeading)
                      throws UnknownReferenceException
This type of facet has no equivalent outside the com.facetmap.sql package, so this method always throws UnsupportedOperationException.

Specified by:
getSqlHeading in interface SqlFacet
Throws:
UnknownReferenceException

getRootHeading

public Heading getRootHeading()
Description copied from interface: Facet
A facet structure is rooted at the heading returned by this method. The root provides a starting point for navigation through this facet structure; the root will be one of the headings in the Selection that contains all Resources. The root Heading should have no backward Heading.

In most cases, Resources that are not mapped to any Heading in this Facet are implicitly mapped to this function's return value. Selection.getBackwardSelections(). In some subinterfaces, the root takes on a more familiar role, e.g. the root node of a Taxonomy.

Specified by:
getRootHeading in interface Facet
See Also:
Selection.getForwardSelections(com.facetmap.Facet)

getId

public java.lang.String getId()
Description copied from interface: Facet
Unique identifier.

Specified by:
getId in interface Facet

setId

public void setId(java.lang.String id)

getTitle

public java.lang.String getTitle()
Description copied from interface: Facet
The descriptive name of this structure, for display to users.

Specified by:
getTitle in interface Facet

setTitle

public void setTitle(java.lang.String title)