Просмотр исходного кода

Merge pull request #891 from weseek/feat/add-tag-prefix-option-on-search

add search prefix for tag
Yuki Takei 7 лет назад
Родитель
Сommit
7470d03687
1 измененных файлов с 16 добавлено и 8 удалено
  1. 16 8
      src/server/util/search.js

+ 16 - 8
src/server/util/search.js

@@ -698,6 +698,8 @@ SearchClient.prototype.parseQueryString = function(queryString) {
   const notPhraseWords = [];
   const notPhraseWords = [];
   const prefixPaths = [];
   const prefixPaths = [];
   const notPrefixPaths = [];
   const notPrefixPaths = [];
+  const tags = [];
+  const notTags = [];
 
 
   queryString.trim();
   queryString.trim();
   queryString = queryString.replace(/\s+/g, ' '); // eslint-disable-line no-param-reassign
   queryString = queryString.replace(/\s+/g, ' '); // eslint-disable-line no-param-reassign
@@ -726,25 +728,29 @@ SearchClient.prototype.parseQueryString = function(queryString) {
       return;
       return;
     }
     }
 
 
-    // https://regex101.com/r/lN4LIV/1
-    const matchNegative = word.match(/^-(prefix:)?(.+)$/);
-    // https://regex101.com/r/gVssZe/1
-    const matchPositive = word.match(/^(prefix:)?(.+)$/);
+    // https://regex101.com/r/pN9XfK/1
+    const matchNegative = word.match(/^-(prefix:|tag:)?(.+)$/);
+    // https://regex101.com/r/3qw9FQ/1
+    const matchPositive = word.match(/^(prefix:|tag:)?(.+)$/);
 
 
     if (matchNegative != null) {
     if (matchNegative != null) {
-      const isPrefixCondition = (matchNegative[1] != null);
-      if (isPrefixCondition) {
+      if (matchNegative[1] === 'prefix:') {
         notPrefixPaths.push(matchNegative[2]);
         notPrefixPaths.push(matchNegative[2]);
       }
       }
+      else if (matchNegative[1] === 'tag:') {
+        notTags.push(matchNegative[2]);
+      }
       else {
       else {
         notMatchWords.push(matchNegative[2]);
         notMatchWords.push(matchNegative[2]);
       }
       }
     }
     }
     else if (matchPositive != null) {
     else if (matchPositive != null) {
-      const isPrefixCondition = (matchPositive[1] != null);
-      if (isPrefixCondition) {
+      if (matchPositive[1] === 'prefix:') {
         prefixPaths.push(matchPositive[2]);
         prefixPaths.push(matchPositive[2]);
       }
       }
+      else if (matchPositive[1] === 'tag:') {
+        tags.push(matchPositive[2]);
+      }
       else {
       else {
         matchWords.push(matchPositive[2]);
         matchWords.push(matchPositive[2]);
       }
       }
@@ -758,6 +764,8 @@ SearchClient.prototype.parseQueryString = function(queryString) {
     not_phrase: notPhraseWords,
     not_phrase: notPhraseWords,
     prefix: prefixPaths,
     prefix: prefixPaths,
     not_prefix: notPrefixPaths,
     not_prefix: notPrefixPaths,
+    tag: tags,
+    not_tag: notTags,
   };
   };
 };
 };