Various Share search related fixes as spotted by Andy:

- increased resultset size that is used to retrieve raw results from query before Share specific results are filtered - this means sensible results are now shown from large repository wide and sorted queries, previously results would be "missing" if they dropped out of the resultset prefiltering
 - fix to Share Search component to correctly display if more than N results were found in the repository
 - fix to add default TYPE clause to generated Share search if no other TYPE is specified - this reduces masses of potentially matches results from repository wide searches that would otherwise need to be post-filtered

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31156 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2011-10-12 10:53:06 +00:00
parent 87967a9447
commit 61b06e142f

View File

@@ -73,30 +73,16 @@ function getPersonDisplayName(userId)
* same blog post match the search criteria * same blog post match the search criteria
*/ */
var processedCache = {}; var processedCache = {};
function addToProcessed(category, key) function checkProcessedCache(key)
{ {
var cat = processedCache[category]; var found = processedCache.hasOwnProperty(key);
if (typeof cat !== "object") if (!found)
{ {
processedCache[category] = []; processedCache[key] = true;
cat = processedCache[category];
} }
cat.push(key); else if (found && logger.isLoggingEnabled())
} logger.log("...already processed item with key: " + key);
function checkProcessed(category, key) return found;
{
var cat = processedCache[category];
if (typeof cat === "object")
{
for (var x in cat)
{
if (cat[x] == key)
{
return true;
}
}
}
return false;
} }
/** /**
@@ -105,12 +91,10 @@ function checkProcessed(category, key)
function getRepositoryItem(folderPath, node) function getRepositoryItem(folderPath, node)
{ {
// check whether we already processed this document // check whether we already processed this document
var cat = "repository", refkey = "" + node.nodeRef.toString(); if (checkProcessedCache("" + node.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
// check whether this is a valid folder or a file // check whether this is a valid folder or a file
var item = t = null; var item = t = null;
@@ -160,12 +144,10 @@ function getDocumentItem(siteId, containerId, pathParts, node)
// be returned instead // be returned instead
// check whether we already processed this document // check whether we already processed this document
var cat = siteId + containerId, refkey = "" + node.nodeRef.toString(); if (checkProcessedCache("" + node.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
// check whether this is a valid folder or a file // check whether this is a valid folder or a file
var item = t = null; var item = t = null;
@@ -236,12 +218,10 @@ function getBlogPostItem(siteId, containerId, pathParts, node)
} }
// check whether we already added this blog post // check whether we already added this blog post
var cat = siteId + containerId, refkey = "" + child.nodeRef.toString(); if (checkProcessedCache("" + child.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
// child is our blog post // child is our blog post
var item, t = null; var item, t = null;
@@ -280,12 +260,10 @@ function getForumPostItem(siteId, containerId, pathParts, node)
} }
// make sure we haven't already added the post // make sure we haven't already added the post
var cat = siteId + containerId, refkey = "" + topicNode.nodeRef.toString(); if (checkProcessedCache("" + topicNode.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
// find the first post, which contains the post title // find the first post, which contains the post title
// PENDING: error prone // PENDING: error prone
@@ -323,13 +301,11 @@ function getCalendarItem(siteId, containerId, pathParts, node)
return null; return null;
} }
// make sure we haven't already added the post // make sure we haven't already added the event
var cat = siteId + containerId, refkey = "" + node.nodeRef.toString(); if (checkProcessedCache("" + node.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
var item, t = null; var item, t = null;
item = item =
@@ -363,12 +339,10 @@ function getWikiItem(siteId, containerId, pathParts, node)
} }
// make sure we haven't already added the page // make sure we haven't already added the page
var cat = siteId + containerId, refkey = "" + node.nodeRef.toString(); if (checkProcessedCache("" + node.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
var item, t = null; var item, t = null;
item = item =
@@ -402,12 +376,10 @@ function getLinkItem(siteId, containerId, pathParts, node)
} }
// make sure we haven't already added this link // make sure we haven't already added this link
var cat = siteId + containerId, refkey = "" + node.nodeRef.toString(); if (checkProcessedCache("" + node.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
var item = t = null; var item = t = null;
if (node.qnamePath.indexOf(COMMENT_QNAMEPATH) == -1 && if (node.qnamePath.indexOf(COMMENT_QNAMEPATH) == -1 &&
@@ -439,12 +411,10 @@ function getLinkItem(siteId, containerId, pathParts, node)
function getDataItem(siteId, containerId, pathParts, node) function getDataItem(siteId, containerId, pathParts, node)
{ {
// make sure we haven't already added this item // make sure we haven't already added this item
var cat = siteId + containerId, refkey = "" + node.nodeRef.toString(); if (checkProcessedCache("" + node.nodeRef.toString()))
if (checkProcessed(cat, refkey))
{ {
return null; return null;
} }
addToProcessed(cat, refkey);
var item = null; var item = null;
@@ -547,14 +517,14 @@ function getItem(siteId, containerId, pathParts, node)
*/ */
function splitQNamePath(node) function splitQNamePath(node)
{ {
var path = node.qnamePath; var path = node.qnamePath,
var displayPath = node.displayPath.split("/"); displayPath = node.displayPath.split("/"),
var parts = null; parts = null;
if (path.match("^"+SITES_SPACE_QNAME_PATH) == SITES_SPACE_QNAME_PATH) if (path.match("^"+SITES_SPACE_QNAME_PATH) == SITES_SPACE_QNAME_PATH)
{ {
var tmp = path.substring(SITES_SPACE_QNAME_PATH.length); var tmp = path.substring(SITES_SPACE_QNAME_PATH.length),
var pos = tmp.indexOf('/'); pos = tmp.indexOf('/');
if (pos >= 1) if (pos >= 1)
{ {
// site id is the cm:name for the site - we cannot use the encoded QName version // site id is the cm:name for the site - we cannot use the encoded QName version
@@ -572,7 +542,7 @@ function splitQNamePath(node)
} }
} }
return (parts != null ? parts : [ null, null, displayPath ]); return (parts !== null ? parts : [ null, null, displayPath ]);
} }
/** /**
@@ -586,8 +556,12 @@ function processResults(nodes, maxResults)
added = 0, added = 0,
parts, parts,
item, item,
failed = 0,
i, j; i, j;
if (logger.isLoggingEnabled())
logger.log("Processing resultset of length: " + nodes.length);
for (i = 0, j = nodes.length; i < j && added < maxResults; i++) for (i = 0, j = nodes.length; i < j && added < maxResults; i++)
{ {
/** /**
@@ -595,17 +569,21 @@ function processResults(nodes, maxResults)
* let the per-container helper function decide what to do. * let the per-container helper function decide what to do.
*/ */
parts = splitQNamePath(nodes[i]); parts = splitQNamePath(nodes[i]);
if (parts !== null) item = getItem(parts[0], parts[1], parts[2], nodes[i]);
if (item !== null)
{ {
item = getItem(parts[0], parts[1], parts[2], nodes[i]); results.push(item);
if (item !== null) added++;
{ }
results.push(item); else
added++; {
} failed++;
} }
} }
if (logger.isLoggingEnabled())
logger.log("Filtered resultset to length: " + results.length + ". Discarded item count: " + failed);
return ( return (
{ {
items: results items: results
@@ -807,6 +785,12 @@ function getSearchResults(params)
if (ftsQuery.length !== 0) if (ftsQuery.length !== 0)
{ {
// ensure a TYPE is specified - if no add one to remove system objects from result sets
if (ftsQuery.indexOf("TYPE:\"") === -1 && ftsQuery.indexOf("TYPE:'") === -1)
{
ftsQuery += ' AND (+TYPE:"cm:content" +TYPE:"cm:folder")';
}
// we processed the search terms, so suffix the PATH query // we processed the search terms, so suffix the PATH query
var path = null; var path = null;
if (!params.repo) if (!params.repo)
@@ -830,7 +814,7 @@ function getSearchResults(params)
} }
} }
if (path != null) if (path !== null)
{ {
ftsQuery = 'PATH:"' + path + '/*" AND (' + ftsQuery + ') '; ftsQuery = 'PATH:"' + path + '/*" AND (' + ftsQuery + ') ';
} }
@@ -875,13 +859,13 @@ function getSearchResults(params)
} }
if (logger.isLoggingEnabled()) if (logger.isLoggingEnabled())
logger.log("Search query: " + ftsQuery); logger.log("Query:\r\n" + ftsQuery + "\r\nSortby: " + (sort != null ? sort : ""));
// perform fts-alfresco language query // perform fts-alfresco language query
var queryDef = { var queryDef = {
query: ftsQuery, query: ftsQuery,
language: "fts-alfresco", language: "fts-alfresco",
page: {maxItems: params.maxResults}, page: {maxItems: params.maxResults * 2}, // allow for space for filtering out results
templates: getQueryTemplate(), templates: getQueryTemplate(),
defaultField: "keywords", defaultField: "keywords",
onerror: "no-results", onerror: "no-results",