public class ContextSearchSpecification extends AttributeSearchSpecification
The user must also specify the Class on which the ContextQualifications are to be applied.
The Text Query of each ContextQualification is applied on each Media. The result will contain entries from all the Media. The Media rows will be joined with the ContextClass, so that only the Content of objects in the ContextClass is considered. Otherwise, there is nothing special about what is returned by a Context Search. For every result row, the conditions defined by the SearchTree must hold.
// Usage Examples // How to build a Context Search specification // Process is very similar to that of building an AttributeSearchSpecification. // Construct the ContextSearchSpecification. ContextSearchSpecification csp = new ContextSearchSpecification(); // Let's assume we have the 3 parts needed. // They are SearchClassSpecification - SELECT list and FROM list // SearchQualification - WHERE condition // SearchSortSpecification - ORDER BY clause SearchClassSpecification someSearchSpec = ...; SearchSortSpecification someSortSpec = ... ; SearchQualification someSearchQual = ...; LibrarySession sess = ...; // Set the search class spec. Make sure the class // spec includes the class that stores the content, CONTENTOBJECT // in most cases. csp.setSearchClassSpecification(someSearchSpec); // Set the search qualification. Make sure there is // at least one ContextQualification in this. csp.setSearchQualification(someSearchQual); // Set the sort specification. Specify context // score based ordering in the sort spec if necessary. csp.setSearchSortSpecification(someSortSpec); // One extra step in ContextSearchSpecification is to // setup the context search class. csp.setContextClassname(ContentObject.CLASS_NAME); // Now we are ready to build a Search or create a View. // Building a search Search someSearch = new Search(sess, asp); // Or creating a view. Note that View itself will not have // content in it. ViewSpecification viewSpec = new ViewSpecification("TestView", asp); // --------------------------------------------------------------- // Complete example of a Search using ContextSearchSpecification // --------------------------------------------------------------- // Let's build a search that looks for all DOCUMENTS with a given // word "FOOBAR" and are named FOO. // Let's build the WHERE condition first. // It will be - DOC.Contains(FOOBAR) and DOC.NAME='FOO' // DOC.Contains = FOO String contextClauseName = "CQ1"; String queryTerm = "FOOBAR"; ContextQualification cq1 = new ContextQualification(); cq1.setQuery(queryTerm); cq1.setName(contextClauseName); // Since content in stored in CONTENTOBJECT, the above // ContextQualification is actually doing a contains on CONTENETOBJECT. // Therefore, we need to join the CONTENTOBJECT with DOCUMENT. // Create a JoinQualification. This sort of join is a must // for all context searches. // SQL generated - DOC.CO = CO.ID JoinQualification jq1 = new JoinQualification(); jq1.setLeftAttribute(Document.CLASS_NAME, Document.CONETNTOBJECT_ATTRIBUTE); jq1.setRightAttribute(ContentObject.CLASS_NAME, null); // DOC.NAME= 'FOO' AttributeQualification aq1 = new AttributeQualification(); aq1.setAttribute(PublicObject.NAME_ATTRIBUTE); aq1.setOperatorType(AttributeQualification.EQUAL); aq1.setValue("FOO"); // Put them together with an AND. With that our // SearchQualification is ready. // The search tree looks like - cq1 AND aq1 and jq1 SearchClause sc = new SearchClause(cq1, aq1, SearchClause.AND); sc = new SearchClause(sc, jq1, SearchClause.AND); // Let's build the SearchClassSpecification SearchClassSpecification classSpec = new SearchClassSpecification(); classSpec.addSearchClass(Document.CLASS_NAME); classSpec.addSearchClass(ContentObject.CLASS_NAME); // Let's build the SearchSortSpecification // Let' sort by context score. Note the use of contextClauseName SearchSortSpecification sortSpec = new SearchSortSpecification(); sortSpec.add(Document.CLASS_NAME, ContextQualification.ORDER_PREFIX + "." + contextClauseName); // Now that all 3 components are built, it is time to build // AttributeSearchSpecification,nd attache the 3 components. ContextSearchSpecification csp = new ContextSearchSpecification(); csp.setSearchClassSpecification(classSpec); csp.setSearchQualification(sc); csp.setSearchSortSpecification(sortSpec) // Remember to set the context class name csp.setContextClassname(ContentObject.CLASS_NAME); // Now we are ready to construct the search object. // You can even build a view at this point using ViewSpecification. Search s = new Search(m_Session, csp); // Open the search. This runs the query. s.open(); // At this point you can do next() on the Search and get the SearchResultObject // for each row in searcn result. After processing the results, remember to close // the search. // close s.close();
Modifier and Type | Field and Description |
---|---|
protected Hashtable |
m_ContentClasses
In a future release, there will be support for ContextQualifications on
multiple classes.
|
protected Long |
m_ContextClassId
ClassId of Context Search Class
|
protected String |
m_ContextClassName
Name of Class on which Context Qualifications will be appllied.
|
protected boolean |
m_ContextConditionUnderOrOperator
Indicates that the context condition is under a a 'OR' operator.
|
protected boolean |
m_HasContextQualifier
True if Specification contains, a COntextQualification.
|
m_ClassSpecification, m_Qual, m_SortSpec
CLEAR_PLAN_TABLE_PARAMETER, m_SecurityBindingInPlace, PLAN_NAME_PARAMETER, PLAN_TABLE_PARAMETER, SEARCH_ID_PARAMETER, SEARCH_SPEC_PARAMETER
Constructor and Description |
---|
ContextSearchSpecification()
Constructs a ContextSearchSpecification.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addContentClass(String clss)
Adds the specified class to the list of classes for which the readContent
check must be performed.
|
Object |
clone()
Returns a clone of this ContextSearchSpecification.
|
String[] |
contentClasses()
Returns list of classes for read content check must be performed.
|
protected void |
copy(ContextSearchSpecification src)
Copies the elements from the src ContextSearchSpecification into this
object.
|
Long |
getContextClassId()
Returns id of Context Search Class
|
String |
getContextClassname()
Returns the name of the class used for Text queries.
|
Hashtable |
getContextScoreMap()
Returns a mapping from SCORE expression numbers to ContextQualifier names.
|
boolean |
getFastResponseType()
Returns true if the search qualifies for rewrite as fast response
context search.
|
protected boolean |
getHasContextQualifier()
Returns whether SearchTree contains any ContextQualifications.
|
protected String |
getQueryTerm()
Returns the query term used by the fast response search.
|
protected Enumeration |
getSQL(String prefix,
S_Search srchObj,
S_LibrarySession sess,
Vector avs,
boolean searchCountOnly)
Returns an Enumeration of PreparedStatements.
|
String |
getSQLString(String prefix,
S_LibrarySession session,
boolean searchCountOnly)
Returns the SQL string for this SearchSpecification.
|
protected String |
getViewStatement(ViewSpecification vsp,
S_LibrarySession sess)
Generates a View creation statement, based on the ViewSpecification.
|
protected boolean |
isContextConditionUnderOrOperator()
Returns true if the context serach condition is under an OR operator
in the search tree; False otherwise.
|
void |
setContextClassname(String cn)
Set the Class to be used for Text Queries.
|
void |
setContextConditionUnderOrOperatorFlag(boolean value)
Used to indicate that the context condition is under an 'OR' operator
in the search tree.
|
protected void |
setFastResponseType(boolean type)
Sets the search to a fast response search.
|
protected void |
setHasContextQualifier(boolean hasQual)
Sets whether SearchTree has ContextQualifications.
|
protected void |
setQueryTerm(String term)
Sets the query term that is speficied in the search tree.
|
void |
validate(LibrarySession sess)
Constructs or finds a SearchValidator for the specified session.
|
addOptimizerHint, bindValuesInPlace, copy, getEffectiveOptimizerHint, getMaxItemCount, getOptimizerHints, getResultClasses, getSearchClassSpecification, getSearchQualification, getSearchSortSpecification, replaceFirstOptimizerHint, setMaxItemCount, setResultClass, setSearchClassSpecification, setSearchQualification, setSearchSortSpecification, setSecurityParameters
createView, explainPlan, getBoundSpecification, getSQL, getSQL
protected Long m_ContextClassId
protected String m_ContextClassName
protected boolean m_HasContextQualifier
protected Hashtable m_ContentClasses
protected boolean m_ContextConditionUnderOrOperator
public ContextSearchSpecification()
protected void setHasContextQualifier(boolean hasQual)
hasQual
- specify whether this has a ContextQualification.protected boolean getHasContextQualifier()
protected void setQueryTerm(String term) throws IfsException
IfsException
protected String getQueryTerm() throws IfsException
IfsException
public void setContextClassname(String cn) throws IfsException
cn
- Text Queries in ContextQualifications are applied on the content
of objects of this class.IfsException
- if the operation failspublic String getContextClassname() throws IfsException
IfsException
- if the operation failspublic Long getContextClassId()
public void validate(LibrarySession sess) throws IfsException
validate
in class AttributeSearchSpecification
sess
- LibrarySession in which validation is performed.IfsException
- if validation failsSearchValidator
protected void setFastResponseType(boolean type) throws IfsException
IfsException
public boolean getFastResponseType() throws IfsException
IfsException
- if the operation failsprotected String getViewStatement(ViewSpecification vsp, S_LibrarySession sess) throws IfsException
getViewStatement
in class AttributeSearchSpecification
vsp
- details about the View for which the creation statement is to be
generated.sess
- server-side session.IfsException
- if operation fails.protected Enumeration getSQL(String prefix, S_Search srchObj, S_LibrarySession sess, Vector avs, boolean searchCountOnly) throws IfsException
There are one or more Media table over which the Search is performed. THe ContextBridge returns the list of Media Tables based on the list of Searched Media. The generated SQL is a union of selects, with each select apllied on a media table. The number of Media Tables is not dependent on the number of Searched Media, but depends on how the Media are implemented. Each Media Table can contain multiple Content columns.
For each MediaTable (select within the union) the security parameters are bound by calling setSecurityParameters. The BindValuesVisitor traverse the searchTree, binding any late bound Qualification values.
getSQL
in class AttributeSearchSpecification
prefix
- the generated SQL is prefixed with this String, this is used for
explain plan.srchObj
- server side Search object in which Search is being executed.sess
- server side session in which Search is being executed.avs
- list of bind valuesIfsException
- if sql generation failsSearchSpecification.getSQL(String, S_Search, S_LibrarySession, Vector, boolean)
public String getSQLString(String prefix, S_LibrarySession session, boolean searchCountOnly) throws IfsException
getSQLString
in class AttributeSearchSpecification
prefix
- sql generated is prefixed with this String. Used during explain plan.session
- server-side sessionsearchCountOnly
- if true, it generates a count(*) in select.IfsException
- if the operation fails.public Hashtable getContextScoreMap() throws IfsException
getContextScoreMap
in class SearchSpecification
IfsException
- if operation fails.public Object clone()
clone
in class AttributeSearchSpecification
protected void copy(ContextSearchSpecification src) throws IfsException
src
- Source ContextSearchSpecificationIfsException
protected void addContentClass(String clss) throws IfsException
clss
- Class for which readContent Check must be performed.IfsException
public String[] contentClasses() throws IfsException
contentClasses
in class SearchSpecification
IfsException
- if operation fails.public void setContextConditionUnderOrOperatorFlag(boolean value)
value
- true or falseprotected boolean isContextConditionUnderOrOperator()
Copyright © 2023. All rights reserved.