Created
December 8, 2016 13:25
-
-
Save durgesh97025/86a68ede086bd8fab31ec7a75c521868 to your computer and use it in GitHub Desktop.
Parse Taxonomy Value From Search Results. Used in Search Result Item Display Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseTaxonomySearchResultValue(val){ | |
var taxValue = {TermSetGuids: [], TermValues: []}; | |
var parts = val.split(';'); | |
parts.forEach(function(part){ | |
if (part.startsWith("GP0|#")) //term? | |
{ | |
var termGuid = part.replace("GP0|#", ""); | |
taxValue.TermValues.push({ TermGuid: termGuid}); | |
} | |
else if (part.startsWith("GTSet|#")) //term set? | |
{ | |
taxValue.TermSetGuids.push(part.replace("GTSet|#", "")); | |
} | |
else if (part.startsWith("L0|#")) //Term with label? | |
{ | |
var termParts = part.replace("L0|#0", "").split('|'); | |
var termGuid = termParts[0]; | |
var termLabel = termParts[1]; | |
var result = taxValue.TermValues.filter(function(tv){ | |
return tv.TermGuid == termGuid; | |
}); | |
if (result.length == 0) | |
taxValue.TermValues.push({TermGuid : termGuid, Label : termLabel}); | |
else | |
result[0].Label = termLabel; | |
} | |
}); | |
return taxValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment