mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
91385: 5.0 specific merge of MNT-12824 - Search is not returning any results (broken since merge of MNT-12639). Also fix issue with quering more results than needed for the new paged result search screen in Share - should be faster. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94798 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -511,74 +511,66 @@ function getItem(siteId, containerId, pathParts, node, populate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Splits the qname path to a node.
|
* Splits the qname path to a node to extract Site information and display path parts.
|
||||||
|
* The display path will be truncated to match the overridden root node if present.
|
||||||
*
|
*
|
||||||
* Returns an array with:
|
* Returns an array with:
|
||||||
* [0] = site
|
* [0] = site or null
|
||||||
* [1] = container or null if the node does not match
|
* [1] = container or null
|
||||||
* [2] = remaining part of the cm:name based path to the object - as an array
|
* [2] = remaining part of the cm:name based path to the object - as an array
|
||||||
*/
|
*/
|
||||||
function splitQNamePath(node, rootNodeDisplayPath, rootNodeQNamePath, qnameOnly)
|
function splitQNamePath(node, rootNodeDisplayPath, rootNodeQNamePath, qnameOnly)
|
||||||
{
|
{
|
||||||
var path = node.qnamePath,
|
var path = node.qnamePath,
|
||||||
displayPath = qnameOnly ? null : utils.displayPath(node).split("/"),
|
displayPath = qnameOnly ? null : utils.displayPath(node).split("/"),
|
||||||
parts = null,
|
siteId = null,
|
||||||
overriden = false;
|
containerId = null;
|
||||||
|
|
||||||
var nodeDisplayPath = utils.displayPath(node).split("/");
|
|
||||||
// restructure the display path of the node if we have an overriden root node
|
|
||||||
if (!qnameOnly && rootNodeDisplayPath != null && path.indexOf(rootNodeQNamePath) === 0 && path.indexOf(SITES_SPACE_QNAME_PATH) === -1)
|
|
||||||
{
|
|
||||||
nodeDisplayPath = nodeDisplayPath.splice(rootNodeDisplayPath.length);
|
|
||||||
displayPath = nodeDisplayPath;
|
|
||||||
overriden = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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),
|
// this item is contained within a Site
|
||||||
pos = tmp.indexOf('/');
|
|
||||||
if (path.indexOf(rootNodeQNamePath) === 0 && !path.equals(rootNodeQNamePath))
|
// ensure we have not matched a Site folder directly or some node created under the st:sites folder that is not a Site
|
||||||
|
var qpathUnderSitesFolder = path.substring(SITES_SPACE_QNAME_PATH.length),
|
||||||
|
positionContainer = qpathUnderSitesFolder.indexOf("/");
|
||||||
|
if (positionContainer !== -1)
|
||||||
{
|
{
|
||||||
nodeDisplayPath = nodeDisplayPath.splice(rootNodeDisplayPath.length);
|
// Decode the Site ID from the qname path using the util method - as we may not have displayPath
|
||||||
displayPath = nodeDisplayPath;
|
// the displayPath will look something like this: ["", "Company Home", "Sites", "MySite", "documentLibrary", "MyFolder"]
|
||||||
overriden = true;
|
var siteQName = Packages.org.alfresco.util.ISO9075.decode(qpathUnderSitesFolder.substring(positionContainer));
|
||||||
}
|
siteId = siteQName.substring(siteQName.indexOf(":") + 1);
|
||||||
if (pos >= 1)
|
var qpathContainer = qpathUnderSitesFolder.substring(positionContainer + 1);
|
||||||
{
|
var positionUnderContainer = qpathContainer.indexOf("/");
|
||||||
if (rootNodeQNamePath != null && path.indexOf(rootNodeQNamePath) === 0 && !path.equals(rootNodeQNamePath))
|
if (positionUnderContainer !== -1)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < rootNodeQNamePath.split("/").length-1; i++)
|
// extract container id from the qname path - strip off namespace
|
||||||
{
|
containerId = qpathContainer.substring(0, positionUnderContainer);
|
||||||
nodeDisplayPath.unshift(null);
|
|
||||||
}
|
|
||||||
displayPath = nodeDisplayPath;
|
|
||||||
}
|
|
||||||
var siteQName = Packages.org.alfresco.util.ISO9075.decode(tmp.split("/")[0]);
|
|
||||||
siteId = siteQName.substring(siteQName.indexOf(":") + 1);
|
|
||||||
tmp = tmp.substring(pos + 1);
|
|
||||||
pos = tmp.indexOf('/');
|
|
||||||
if (pos >= 1)
|
|
||||||
{
|
|
||||||
// strip container id from the path
|
|
||||||
var containerId = tmp.substring(0, pos);
|
|
||||||
containerId = containerId.substring(containerId.indexOf(":") + 1);
|
containerId = containerId.substring(containerId.indexOf(":") + 1);
|
||||||
|
|
||||||
parts = [ siteId, containerId, qnameOnly ? null : displayPath.slice(5, displayPath.length) ];
|
// construct remaining part of the cm:name based display path to the object
|
||||||
|
// by removing everything up to the path of the item under the container folder
|
||||||
|
if (!qnameOnly) displayPath = displayPath.slice(5, displayPath.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (overriden && parts == null)
|
|
||||||
{
|
{
|
||||||
displayPath.unshift("");
|
// check if we have an overridden root node and the node is under that path
|
||||||
|
if (!qnameOnly && rootNodeDisplayPath !== null && path.indexOf(rootNodeQNamePath) === 0)
|
||||||
|
{
|
||||||
|
// restructure the display path of the node
|
||||||
|
displayPath = displayPath.splice(rootNodeDisplayPath.length);
|
||||||
|
// empty element is required at the start of the repository paths - we want to show it as the repo root later
|
||||||
|
displayPath.unshift("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (parts !== null ? parts : [ null, null, displayPath ]);
|
return [ siteId, containerId, displayPath ];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the search results. Filters out unnecessary nodes
|
* Processes the search results, extracting the given page of results from the startIndex up to the maxPageResults
|
||||||
|
* from the total list of nodes passed in. Filters out unnecessary nodes
|
||||||
*
|
*
|
||||||
* @return the final search results object
|
* @return the final search results object
|
||||||
*/
|
*/
|
||||||
@@ -655,6 +647,72 @@ function processResults(nodes, maxPageResults, startIndex, rootNode, meta)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the search results for a single page. Filters out unnecessary nodes
|
||||||
|
*
|
||||||
|
* @return the final search results object
|
||||||
|
*/
|
||||||
|
function processResultsSinglePage(nodes, startIndex, rootNode, meta)
|
||||||
|
{
|
||||||
|
// empty cache state
|
||||||
|
processedCache = {};
|
||||||
|
var results = [],
|
||||||
|
failed = 0,
|
||||||
|
parts,
|
||||||
|
item,
|
||||||
|
rootNodeDisplayPath = rootNode ? utils.displayPath(rootNode).split("/") : null,
|
||||||
|
rootNodeQNamePath = rootNode ? rootNode.qnamePath : null;
|
||||||
|
|
||||||
|
if (logger.isLoggingEnabled())
|
||||||
|
logger.log("Processing resultset of length: " + nodes.length);
|
||||||
|
|
||||||
|
for (var i = 0, j = nodes.length; i < j; i++)
|
||||||
|
{
|
||||||
|
// For each node we extract the site/container qname path and then
|
||||||
|
// let the per-container helper function decide what to do.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
parts = splitQNamePath(nodes[i], rootNodeDisplayPath, rootNodeQNamePath, false);
|
||||||
|
item = getItem(parts[0], parts[1], parts[2], nodes[i], true);
|
||||||
|
if (item !== null)
|
||||||
|
{
|
||||||
|
results.push(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
// THOR-833
|
||||||
|
if (logger.isWarnLoggingEnabled() == true)
|
||||||
|
{
|
||||||
|
logger.warn("search.lib.js: Skipping node due to exception when processing query result: " + e);
|
||||||
|
logger.warn("..." + nodes[i].nodeRef);
|
||||||
|
}
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logger.isLoggingEnabled())
|
||||||
|
logger.log("Filtered resultset to length: " + results.length + ". Discarded item count: " + failed);
|
||||||
|
|
||||||
|
return (
|
||||||
|
{
|
||||||
|
paging:
|
||||||
|
{
|
||||||
|
totalRecords: results.length,
|
||||||
|
totalRecordsUpper: -1,
|
||||||
|
startIndex: startIndex,
|
||||||
|
numberFound: meta ? meta.numberFound : -1
|
||||||
|
},
|
||||||
|
facets: meta ? meta.facets : null,
|
||||||
|
items: results,
|
||||||
|
spellcheck: meta ? meta.spellcheck : null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to escape the QName string so it is valid inside an fts-alfresco query.
|
* Helper to escape the QName string so it is valid inside an fts-alfresco query.
|
||||||
* The language supports the SQL92 identifier standard.
|
* The language supports the SQL92 identifier standard.
|
||||||
@@ -787,11 +845,16 @@ function resolveRootNode(reference)
|
|||||||
}
|
}
|
||||||
else if (reference.substring(0, 1) == "/")
|
else if (reference.substring(0, 1) == "/")
|
||||||
{
|
{
|
||||||
node = search.xpathSearch(reference)[0];
|
var res = search.xpathSearch(reference);
|
||||||
|
if (res.length === 0)
|
||||||
|
{
|
||||||
|
logger.warn("Unable to resolve specified root node reference: " + reference);
|
||||||
|
}
|
||||||
|
else node = res[0];
|
||||||
}
|
}
|
||||||
if (node === null)
|
if (node === null)
|
||||||
{
|
{
|
||||||
logger.log("Unable to resolve specified root node reference: " + reference);
|
logger.warn("Unable to resolve specified root node reference: " + reference);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -1130,7 +1193,8 @@ function getSearchResults(params)
|
|||||||
query: ftsQuery,
|
query: ftsQuery,
|
||||||
language: "fts-alfresco",
|
language: "fts-alfresco",
|
||||||
page: {
|
page: {
|
||||||
maxItems: params.maxResults + 1
|
maxItems: params.maxResults > 0 ? params.maxResults + 1 : params.pageSize,
|
||||||
|
skipCount: params.maxResults > 0 ? 0 : params.startIndex
|
||||||
},
|
},
|
||||||
templates: qt.template,
|
templates: qt.template,
|
||||||
defaultField: "keywords",
|
defaultField: "keywords",
|
||||||
@@ -1151,12 +1215,23 @@ function getSearchResults(params)
|
|||||||
nodes = [];
|
nodes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return processResults(
|
if (params.maxResults > 0)
|
||||||
nodes,
|
{
|
||||||
params.pageSize < params.maxResults ? params.pageSize : params.maxResults,
|
return processResults(
|
||||||
params.startIndex,
|
nodes,
|
||||||
rootNode,
|
params.pageSize,
|
||||||
rs.meta);
|
params.startIndex,
|
||||||
|
rootNode,
|
||||||
|
rs.meta);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return processResultsSinglePage(
|
||||||
|
nodes,
|
||||||
|
params.startIndex,
|
||||||
|
rootNode,
|
||||||
|
rs.meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user