@alfresco/aca-content 7.3.0-19540132034 → 7.3.0-19567695900

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2772,9 +2772,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImpor
2772
2772
  */
2773
2773
  function isOperator(input) {
2774
2774
  if (input) {
2775
- input = input.trim().toUpperCase();
2776
2775
  const operators = ['AND', 'OR'];
2777
- return operators.includes(input);
2776
+ return operators.includes(input.trim());
2778
2777
  }
2779
2778
  return false;
2780
2779
  }
@@ -2841,17 +2840,49 @@ function extractUserQueryFromEncodedQuery(encodedQuery) {
2841
2840
  * @returns string
2842
2841
  */
2843
2842
  function extractSearchedWordFromEncodedQuery(encodedQuery) {
2844
- if (encodedQuery) {
2845
- const userQuery = extractUserQueryFromEncodedQuery(encodedQuery);
2846
- return userQuery !== '' && userQuery !== undefined
2847
- ? userQuery
2848
- .split('AND')
2849
- .map((searchCondition) => {
2850
- const searchTerm = searchCondition.includes('"') ? searchCondition.split('"')[1] : searchCondition.trim();
2851
- return searchTerm?.endsWith('*') && searchTerm !== '*' ? searchTerm.slice(0, -1) : searchTerm;
2852
- })
2853
- .join(' ')
2854
- : '';
2843
+ if (!encodedQuery) {
2844
+ return '';
2845
+ }
2846
+ const userQuery = extractUserQueryFromEncodedQuery(encodedQuery);
2847
+ if (!userQuery) {
2848
+ return '';
2849
+ }
2850
+ const tokenRegex = /\(([^()]+)\)|\b(AND|OR)\b/g;
2851
+ const fragments = [];
2852
+ let match;
2853
+ while ((match = tokenRegex.exec(userQuery))) {
2854
+ if (match[1]) {
2855
+ fragments.push(extractWordFromQuery(match[1]));
2856
+ }
2857
+ else if (match[2] === 'OR') {
2858
+ fragments.push('OR');
2859
+ }
2860
+ }
2861
+ if (fragments.length === 0) {
2862
+ return userQuery
2863
+ .split(/\bAND\b|\bOR\b/)
2864
+ .map((part) => extractWordFromQuery(part))
2865
+ .filter(Boolean)
2866
+ .join(' ')
2867
+ .trim();
2868
+ }
2869
+ return fragments.join(' ').trim();
2870
+ }
2871
+ /**
2872
+ * Extracts the searched word from a part of search query
2873
+ *
2874
+ * @param queryPart encoded query
2875
+ * @returns searched word
2876
+ */
2877
+ function extractWordFromQuery(queryPart) {
2878
+ const regex = /:"([^"]+)"/;
2879
+ const quoted = regex.exec(queryPart);
2880
+ if (quoted) {
2881
+ return quoted[1].replace(/\*$/, '');
2882
+ }
2883
+ const trimmedPart = queryPart.trim();
2884
+ if (trimmedPart && !isOperator(trimmedPart)) {
2885
+ return trimmedPart;
2855
2886
  }
2856
2887
  return '';
2857
2888
  }