Confluence - search result for empty pages

mybucket2018 November 1, 2016

Is there any way we could search for empty pages in Confluence? I don't want to create a User Macro to achive this. Is there any way of this being done using the search?

The Search Field page advises that you can search for body content.

search.png

2 answers

0 votes
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 4, 2016

Unfortunately, Confluence uses Lucene in the background for its search, which is not very good at finding empty fields (especially for tokenized fields, like contentBody. I know you said you didn't care for a user macro, but I figured I'd include one anyway. You can use it to search for text in a page (we used it to find link content), and I updated it so that if you search for "blankpage" (without the quotes) then it will find all blank pages. In addition, an icon is displayed next to the page title if the page has children, so that you can see the blank pages that are used as a "folder" and which ones are really orphaned pages.

## @noparams
#set ( $containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager') )
#set ( $getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null) )
#set ( $containerManager=$getInstanceMethod.invoke(null,null) )
#set ( $containerContext=$containerManager.containerContext )
#set ( $webResourceManager = $containerContext.getComponent('webResourceManager') )
$webResourceManager.requireResource('com.atlassian.auiplugin:aui-select2')
#set ( $requestedSearch = "" )
#set ( $requestedSearch = $req.getParameter('requestedSearch') )
#set ( $requestedSpaces = "" )
#set ( $requestedSpaces = $req.getParameter('requestedSpaces') )
#set ( $requestCharacter = "?" )
#if ( $content.getUrlPath().contains("?") )
  #set ( $requestCharacter = "&" )
#end
#if ( $requestedSearch == "" )
  <form class="aui top-label" onsubmit="return false;">
    <div class="field-group top-label">
      <label for="requested-search">Enter Search Terms:</label> 
      <input id="requested-search" class="text long-field" type="text" name="requestedSearch">
    </div>
    <div class="field-group">
      <label for="requestedSpaces">Spaces to search:</label>
      <select class="select" id="requestedSpaces" name="requestedSpaces" multiple>
      #set ( $allSpaces = $spaceManager.getAllSpaces() )
      #foreach ( $space in $allSpaces )
        #if ( $space.isGlobal() )
          <option value="$space.key">$space.name - $space.key</option>
        #end
      #end
    </div>
    <button class="button submit" onclick="window.location = '$content.getUrlPath()' + '${requestCharacter}requestedSearch=' + encodeURIComponent(document.getElementById('requested-search').value) + '&requestedSpaces=' + jQuery('#requestedSpaces').select2('val').join();">Search</button>
  </form>
  <script>
    jQuery("#requestedSpaces").auiSelect2();
  </script>
#else
  #set ( $searchTerm = $requestedSearch )
  #foreach ( $spaceKey in $requestedSpaces.split(",") )
    #set ( $space = $spaceManager.getSpace($spaceKey) )
    <p> Pages containing $searchTerm in $space.name </p>
    #set ( $spacePages = $pageManager.getPages($space, true) )
    <table>
      <tbody>
        <tr>
          <th>
            <p>Page</p>
          </th>
        </tr>
      #foreach ($page in $spacePages)
        #set ( $pageMarkup = $page.getBodyAsString() )
        #if ( ($searchTerm == "blankpage" && $pageMarkup.trim() == "") || $pageMarkup.contains($searchTerm) )
          <tr>
            <td>
              <p>
                <a href="$action.getGlobalSettings().getBaseUrl()$page.getUrlPath()">$page.title</a>
                #if ( $searchTerm == "blankpage" && $page.hasChildren() )
                  <span class="aui-icon aui-icon-small aui-iconfont-group">has children</span>
                #end
              </p>
            </td>
          </tr>
        #end
      #end
      </tbody>
    </table>
  #end
#end
0 votes
Rob Woodgate
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 2, 2016

Hi Martin,

Simple answer: No, you can't search for empty pages using standard Confluence search.  These are the search plugins in the marketplace - one of them might have what you need.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events