|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.facetmap.sql.ResourceIdFacet
public class ResourceIdFacet
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 |
|---|
public ResourceIdFacet(java.lang.String id,
java.lang.String title,
ResourceIdQuery resourceIdQuery)
| Method Detail |
|---|
public ResourceIdHeading getResourceIdHeading(java.lang.String headingId)
public ResourceIdHeading getResourceIdHeading(int[] ids)
public SqlFacetSpace getSqlFacetSpace()
getSqlFacetSpace in interface SqlFacetpublic void setSqlFacetSpace(SqlFacetSpace sqlFacetSpace)
setSqlFacetSpace in interface SqlFacet
public void sqlCreate(java.sql.Connection connection,
java.lang.String vendor)
throws java.sql.SQLException
sqlCreate in interface SqlFacetjava.sql.SQLException
public Heading getHeading(java.lang.String id)
throws UnknownReferenceException
getResourceIdHeading(String).
getHeading in interface FacetUnknownReferenceException
public Heading getSqlHeading(Heading sourceHeading)
throws UnknownReferenceException
getSqlHeading in interface SqlFacetUnknownReferenceExceptionpublic Heading getRootHeading()
FacetIn 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.
getRootHeading in interface FacetSelection.getForwardSelections(com.facetmap.Facet)public java.lang.String getId()
Facet
getId in interface Facetpublic void setId(java.lang.String id)
public java.lang.String getTitle()
Facet
getTitle in interface Facetpublic void setTitle(java.lang.String title)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||