Share Advanced Search

- Basics of Form based search working
 - Search by type and form based configured fields for that type
 - Still a bit rough round the edges

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@21741 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2010-08-11 14:48:37 +00:00
parent 984c17f7cd
commit 99a6c0f890
3 changed files with 87 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
<webscript> <webscript>
<shortname>search</shortname> <shortname>search</shortname>
<description>Site Search Component Data Webscript</description> <description>Site Search Component Data Webscript</description>
<url>/slingshot/search?term={term?}&amp;tag={tag?}&amp;site={site?}&amp;container={container?}&amp;sort={sort?}</url> <url>/slingshot/search?term={term?}&amp;tag={tag?}&amp;site={site?}&amp;container={container?}&amp;sort={sort?}&amp;query={query?}</url>
<format default="json">argument</format> <format default="json">argument</format>
<authentication>user</authentication> <authentication>user</authentication>
<transaction allow="readonly">required</transaction> <transaction allow="readonly">required</transaction>

View File

@@ -1,14 +1,18 @@
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js"> <import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/search/search.lib.js">
function main() function main()
{ {
var siteId = (args.site !== undefined) ? args.site : null; var params =
var containerId = (args.container !== undefined) ? args.container : null; {
var term = (args.term !== undefined) ? args.term : null; siteId: (args.site !== null) ? args.site : null,
var tag = (args.tag !== undefined) ? args.tag : null; containerId: (args.container !== null) ? args.container : null,
var sort = (args.sort !== undefined) ? args.sort : null; term: (args.term !== null) ? args.term : null,
var maxResults = (args.maxResults !== undefined) ? parseInt(args.maxResults, 10) : DEFAULT_MAX_RESULTS; tag: (args.tag !== null) ? args.tag : null,
query: (args.query !== null) ? args.query : null,
sort: (args.sort !== null) ? args.sort : null,
maxResults: (args.maxResults !== null) ? parseInt(args.maxResults, 10) : DEFAULT_MAX_RESULTS
};
model.data = getSearchResults(term, tag, maxResults, siteId, containerId, sort); model.data = getSearchResults(params);
} }
main(); main();

View File

@@ -1,17 +1,22 @@
/** /**
* Search Component * Search Component
* *
* Inputs: * Takes the following object as Input:
* optional: site = the site to search into, null for all sites * params
* optional: container = the component the search in, null for all components in the site * {
* optional: term = search terms, should be supplied if tag is not * siteId: the site identifier to search into, null for all sites
* optional: tag = search tag, should be supplied if term is not * containerId: the component the search in, null for all components in the site
* maxResults = maximum results to return * term: search terms
* tag: search tag
* query: advanced search query json
* sort: sort parameter
* maxResults: maximum results to return
* };
* *
* Outputs: * Outputs:
* items - Array of objects containing the search results * items - Array of objects containing the search results
*/ */
const DEFAULT_MAX_RESULTS = 100; const DEFAULT_MAX_RESULTS = 250;
const SITES_SPACE_QNAME_PATH = "/app:company_home/st:sites/"; const SITES_SPACE_QNAME_PATH = "/app:company_home/st:sites/";
const QUERY_TEMPLATES = [ const QUERY_TEMPLATES = [
{field: "keywords", template: "%(cm:name cm:title cm:description ia:whatEvent ia:descriptionEvent lnk:title lnk:description TEXT)"}]; {field: "keywords", template: "%(cm:name cm:title cm:description ia:whatEvent ia:descriptionEvent lnk:title lnk:description TEXT)"}];
@@ -499,12 +504,18 @@ function processResults(nodes, maxResults)
* *
* "or" is the default operator, AND and NOT are also supported - as is any other valid fts-alfresco * "or" is the default operator, AND and NOT are also supported - as is any other valid fts-alfresco
* elements such as "quoted terms" and (bracket terms) and also propname:propvalue syntax. * elements such as "quoted terms" and (bracket terms) and also propname:propvalue syntax.
*
* @param params Object containing search parameters - see API description above
*/ */
function getSearchResults(term, tag, maxResults, siteId, containerId, sort) function getSearchResults(params)
{ {
var nodes; var nodes,
ftsQuery = "",
term = params.term,
tag = params.tag,
formData = params.query;
var ftsQuery = ""; // Simple keyword search and tag specific search
if (term !== null && term.length !== 0) if (term !== null && term.length !== 0)
{ {
ftsQuery = "(" + term + ") PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(term) + "/member\""; ftsQuery = "(" + term + ") PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(term) + "/member\"";
@@ -514,35 +525,81 @@ function getSearchResults(term, tag, maxResults, siteId, containerId, sort)
ftsQuery = "PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(tag) + "/member\""; ftsQuery = "PATH:\"/cm:taggable/cm:" + search.ISO9075Encode(tag) + "/member\"";
} }
// Advanced search form data search.
// Supplied as json in the standard Alfresco Forms data structure:
// prop_<name>:value|assoc_<name>:value
// name = namespace_propertyname|pseudopropertyname
// value = string value - comma separated for multi-value, no escaping yet!
// - underscore represents colon character in name
// - pseudo property is one of any cm:content url property: mimetype|encoding|size
// - always string values - interogate DD for type data
if (formData !== null && formData.length !== 0)
{
var formJson = jsonUtils.toObject(formData);
// extract form data and generate search query
for (var p in formJson)
{
// retrieve value and check there is someting to search for
// currently all values are returned as strings
var propValue = formJson[p];
if (propValue.length !== 0)
{
if (p.indexOf("prop_") === 0)
{
// found a property - is it namespace_propertyname or pseudo property format?
var propName = p.substr(5);
if (propName.indexOf("_") !== -1)
{
// property name - convert to DD property name format
propName = propName.replace("_", ":");
// TODO: inspect DD type - handle boolean, number etc?
ftsQuery += ' ' + propName + ':"' + propValue + '"';
}
else
{
// pseudo cm:content property
// TODO: andyh to fix query parser impl
ftsQuery += ' cm:content.' + propName + ':' + propValue;
}
}
}
}
// extract data type for this search
ftsQuery = 'TYPE:"' + formJson.datatype + '" AND (' + ftsQuery + ')';
}
if (ftsQuery.length !== 0) if (ftsQuery.length !== 0)
{ {
// we processed the search terms, so suffix the PATH query // we processed the search terms, so suffix the PATH query
var path = SITES_SPACE_QNAME_PATH; var path = SITES_SPACE_QNAME_PATH;
if (siteId !== null && siteId.length > 0) if (params.siteId !== null && params.siteId.length > 0)
{ {
path += "cm:" + search.ISO9075Encode(siteId) + "/"; path += "cm:" + search.ISO9075Encode(params.siteId) + "/";
} }
else else
{ {
path += "*/"; path += "*/";
} }
if (containerId !== null && containerId.length > 0) if (params.containerId !== null && params.containerId.length > 0)
{ {
path += "cm:" + search.ISO9075Encode(containerId) + "/"; path += "cm:" + search.ISO9075Encode(params.containerId) + "/";
} }
else else
{ {
path += "*/"; path += "*/";
} }
ftsQuery = "PATH:\"" + path + "/*\" AND (" + ftsQuery + ") "; ftsQuery = 'PATH:"' + path + '/*" AND (' + ftsQuery + ') ';
ftsQuery += "AND -TYPE:\"{http://www.alfresco.org/model/content/1.0}thumbnail\""; ftsQuery += 'AND -TYPE:"cm:thumbnail"';
// sort field - expecting field to in one of the following formats: // sort field - expecting field to in one of the following formats:
// - short QName form such as: cm:name // - short QName form such as: cm:name
// - pseudo cm:content field starting with "." such as: .size // - pseudo cm:content field starting with "." such as: .size
// - any other directly supported search field such as: TYPE // - any other directly supported search field such as: TYPE
var sortColumns = []; var sortColumns = [];
var sort = params.sort;
if (sort != null && sort.length != 0) if (sort != null && sort.length != 0)
{ {
var asc = true; var asc = true;
@@ -579,7 +636,7 @@ function getSearchResults(term, tag, maxResults, siteId, containerId, sort)
var queryDef = { var queryDef = {
query: ftsQuery, query: ftsQuery,
language: "fts-alfresco", language: "fts-alfresco",
page: {maxItems: maxResults}, page: {maxItems: params.maxResults},
templates: QUERY_TEMPLATES, templates: QUERY_TEMPLATES,
defaultField: "keywords", defaultField: "keywords",
onerror: "no-results", onerror: "no-results",
@@ -593,5 +650,5 @@ function getSearchResults(term, tag, maxResults, siteId, containerId, sort)
nodes = []; nodes = [];
} }
return processResults(nodes, maxResults); return processResults(nodes, params.maxResults);
} }