mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
SHA-1771: Update Search script object to support search term highlighting
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@131523 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -49,6 +49,8 @@ import org.alfresco.service.cmr.repository.ContentReader;
|
|||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.alfresco.service.cmr.search.FieldHighlightParameters;
|
||||||
|
import org.alfresco.service.cmr.search.GeneralHighlightParameters;
|
||||||
import org.alfresco.service.cmr.search.LimitBy;
|
import org.alfresco.service.cmr.search.LimitBy;
|
||||||
import org.alfresco.service.cmr.search.ResultSet;
|
import org.alfresco.service.cmr.search.ResultSet;
|
||||||
import org.alfresco.service.cmr.search.ResultSetRow;
|
import org.alfresco.service.cmr.search.ResultSetRow;
|
||||||
@@ -558,6 +560,7 @@ public class Search extends BaseScopableProcessorExtension implements Initializi
|
|||||||
return (Scriptable)queryResultSet(search).get("nodes", getScope());
|
return (Scriptable)queryResultSet(search).get("nodes", getScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public Scriptable queryResultSet(Object search)
|
public Scriptable queryResultSet(Object search)
|
||||||
{
|
{
|
||||||
Object[] results = null;
|
Object[] results = null;
|
||||||
@@ -755,6 +758,42 @@ public class Search extends BaseScopableProcessorExtension implements Initializi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Map<Serializable, Serializable> highlighting = (Map<Serializable, Serializable>)def.get("highlighting");
|
||||||
|
if (highlighting != null)
|
||||||
|
{
|
||||||
|
int snippetCount = this.getIntegerValue("snippetCount", 20, highlighting);
|
||||||
|
int fragmentSize = this.getIntegerValue("fragmentSize", 50, highlighting);
|
||||||
|
int maxAnalyzedChars = this.getIntegerValue("maxAnalyzedChars", 500, highlighting);
|
||||||
|
boolean usePhraseHighlighter = this.getBooleanValue("usePhraseHighlighter", true, highlighting);
|
||||||
|
boolean mergeContiguous = this.getBooleanValue("mergeContiguous", false, highlighting);
|
||||||
|
|
||||||
|
String prefix = (String) highlighting.get("prefix");
|
||||||
|
if (prefix == null)
|
||||||
|
{
|
||||||
|
prefix = "<mark>";
|
||||||
|
}
|
||||||
|
String postfix = (String) highlighting.get("postfix");
|
||||||
|
if (postfix == null)
|
||||||
|
{
|
||||||
|
postfix = "</mark>";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<FieldHighlightParameters> fieldHighlightParameters = new ArrayList<FieldHighlightParameters>();
|
||||||
|
List<Map<Serializable, Serializable>> fields = (List<Map<Serializable, Serializable>>)def.get("fields");
|
||||||
|
for (Map<Serializable, Serializable> field: fields)
|
||||||
|
{
|
||||||
|
String propertyName = (String) field.get("field");
|
||||||
|
if (propertyName != null)
|
||||||
|
{
|
||||||
|
fieldHighlightParameters.add(new FieldHighlightParameters(propertyName, snippetCount, fragmentSize, mergeContiguous, prefix, postfix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GeneralHighlightParameters ghp = new GeneralHighlightParameters(snippetCount, fragmentSize, mergeContiguous, prefix, postfix, maxAnalyzedChars, usePhraseHighlighter, fieldHighlightParameters);
|
||||||
|
sp.setHighlight(ghp);
|
||||||
|
}
|
||||||
|
|
||||||
// error handling opions
|
// error handling opions
|
||||||
boolean exceptionOnError = true;
|
boolean exceptionOnError = true;
|
||||||
if (onerror != null)
|
if (onerror != null)
|
||||||
@@ -806,6 +845,54 @@ public class Search extends BaseScopableProcessorExtension implements Initializi
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to retrieve and parse an attribute in the supplied object to an integer. If the attribute cannot be
|
||||||
|
* found or cannot be parsed then the supplied default is returned.
|
||||||
|
*
|
||||||
|
* @param attribute
|
||||||
|
* @param defaultValue
|
||||||
|
* @param sourceObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getIntegerValue(String attribute, int defaultValue, Map<Serializable, Serializable> sourceObject)
|
||||||
|
{
|
||||||
|
int integer = defaultValue;
|
||||||
|
String stringValue = (String) sourceObject.get(attribute);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
integer = Integer.parseInt(stringValue);
|
||||||
|
}
|
||||||
|
catch(NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
// No action required
|
||||||
|
}
|
||||||
|
return integer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to retrieve and parse an attribute in the supplied object to an integer. If the attribute cannot be
|
||||||
|
* found or cannot be parsed then the supplied default is returned.
|
||||||
|
*
|
||||||
|
* @param attribute
|
||||||
|
* @param defaultValue
|
||||||
|
* @param sourceObject
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean getBooleanValue(String attribute, boolean defaultValue, Map<Serializable, Serializable> sourceObject)
|
||||||
|
{
|
||||||
|
boolean bool = defaultValue;
|
||||||
|
String stringValue = (String) sourceObject.get(attribute);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bool = Boolean.getBoolean(stringValue);
|
||||||
|
}
|
||||||
|
catch(NumberFormatException nfe)
|
||||||
|
{
|
||||||
|
// No action required
|
||||||
|
}
|
||||||
|
return bool;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.
|
* Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.
|
||||||
*
|
*
|
||||||
@@ -951,6 +1038,8 @@ public class Search extends BaseScopableProcessorExtension implements Initializi
|
|||||||
// results metadata
|
// results metadata
|
||||||
meta.put("numberFound", results.getNumberFound());
|
meta.put("numberFound", results.getNumberFound());
|
||||||
meta.put("hasMore", results.hasMore());
|
meta.put("hasMore", results.hasMore());
|
||||||
|
meta.put("highlighting", results.getHighlighting());
|
||||||
|
|
||||||
// results facets
|
// results facets
|
||||||
FacetLabelDisplayHandlerRegistry facetLabelDisplayHandlerRegistry = services.getFacetLabelDisplayHandlerRegistry();
|
FacetLabelDisplayHandlerRegistry facetLabelDisplayHandlerRegistry = services.getFacetLabelDisplayHandlerRegistry();
|
||||||
Map<String, List<ScriptFacetResult>> facetMeta = new HashMap<>();
|
Map<String, List<ScriptFacetResult>> facetMeta = new HashMap<>();
|
||||||
|
Reference in New Issue
Block a user