How To Use Wildcard as the First Character of a String on Confluence Search

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

Use Cause

  1. User wants to search for pages/attachments using a wildcard at the beginning of the string.
  2. User wants to search for pages/attachments that mention specific URLs without using the exact URL.

 

例:  

http://dev.example.com/
dev-no-http.example.com

 

検索語結果
"dev-no-http.example.com"いいえ
"http://dev.example.com/"はい
"http://dev.example.com"いいえ
"dev.example.com"いいえ
"example.com"いいえ

 

 

 

ソリューション

Considering the same domains mentioned above, when we perform the search we need to be exact or use wildcards. However, Lucene does not support wildcard at the beginning of the word being searched (see documentation and CONF-32846 - Getting issue details... STATUS ).

Having that in mind, we'd have the following alternatives:

その他の症状 1
http\:\/\/dev.example.com*
  • Here we are escaping the special characters with a backslash before the special char. Then, instead of using the / at the end, we are using a wildcard symbol: *

From Lucene Documentation (here):

Escaping Special Characters

Lucene supports escaping special characters that are part of the query syntax. The current list special characters are

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ /

To escape these character use the \ before the character. For example to search for (1+1):2 use the query:

\(1\+1\)\:2

 

その他の症状 2
"http://dev.example.com/"
  • Here we use the exact term, which returns the expected results.

 

その他の症状 3
 /http:\/\/dev.example.com\//
  • Lucene supports regular expression searches matching a pattern between forward slashes, so we can escape the special characters and use the slashes to find the text as well.

See this Lucene documentation (here):

Regular Expression Searches

Lucene supports regular expression searches matching a pattern between forward slashes "/". The syntax may change across releases, but the current supported syntax is documented in the RegExp class. For example to find documents containing "moat" or "boat":

/\[mb\]oat/

 

その他の症状 4
/.*http:\/\/dev.example.com.*/
  • Then, we can escape the special characters again and use wildcard along with the slashes from the alternative 3. This will work as a wield card to search the pages/attachments that contain the text we're looking for, but will not search for the exact text.

 

その他の症状 5
/.*dev.example.com*./
  • This works just as alternative 4, but the wildcard works for text before "dev" and after "com".

 

その他の症状 6
/.*dev.example.com*./ OR "http://dev.example.com/"
  • This would perform the search for pages/attachments containing dev.example.com and the exact text.

 

最終更新日: 2016 年 2 月 26 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.