Limit quick search to current space

This patch changes the quick search at the top of each Confluence page to search the current space. Where there is no space available (dashboard and administration, for example), the quick search will continue to be a global search.

This is a source code modification for Confluence 2.2.8. It should work in at least all the 2.2.x versions.

Modify main.vmd

Open main.vmd in the theme which you use (default is in confluence/decorators). Find the line that includes the quick search form:

#quickSearch()

Change this line to:

#quickSearch($sitemeshPage.getProperty("page.spacekey"))

Modify macros.vm

In confluence/template/includes/macros.vm, find the quick search macro that starts like this:

#macro (quickSearch)
    ...
#end

Insert a new version of the #quickSearch macro directly below it with the following code:

#macro (quickSearch $spaceKey)
    <form method="POST" action="$req.contextPath/dosearchsite.action" name="searchForm" style="padding: 1px; margin: 1px">
        <input type="hidden" name="quickSearch" value="true" />
        #if (!$spaceKey)
        <input type="hidden" name="searchQuery.spaceKey" value="conf_global" />
        #else
        <input type="hidden" name="searchQuery.spaceKey" value="$spaceKey" />
        #end
        <input type="text" accessKey="$action.getTextStrict('search-pages-action.accesskey')" name="searchQuery.queryString" size="25"/>
        <input type="submit" value="$action.getText('search.name')"/>
    </form>
#end

This macro takes a spaceKey parameter, and if it is non-null, passes that to the quicksearch as the spaceKey parameter.

Restart Confluence

You need to restart Confluence after changing macros.vm.

Problems with this patch?

This patch is not officially supported, so please do not raise support requests about it. Add a comment below instead.

Labels

patch patch Delete
space space Delete
search search Delete
specific specific Delete
limit limit Delete
quick quick Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 11, 2006

    Mark Stralka says:

    When I make these changes and restart Tomcat the quicksearch box disappears.&nbs...

    When I make these changes and restart Tomcat the quicksearch box disappears.  I'm running Confluence 2.2.8.

    1. Sep 11, 2006

      Matt Ryall says:

      Are you certain you didn't remove the existing #quickSearch() macro? This needs ...

      Are you certain you didn't remove the existing #quickSearch() macro? This needs to remain, and you need to insert the new one below it.

      Is the quicksearch visible on the dashboard or administration sections still?

      1. Sep 19, 2006

        Mark Stralka says:

        Thank you Matt, but I did not removethe #quickSearch() macro.&nbsp; My files loo...

        Thank you Matt, but I did not removethe #quickSearch() macro.  My files look like this:

        template/includes/macros.vm

        #macro (quickSearch)
            <form method="POST" action="$req.contextPath/dosearchsite.action" name="searchForm" style="padding: 1px; margin: 1px">
                <input type="hidden" name="quickSearch" value="true" />
                #* search only global spaces by default *#
                <input type="hidden" name="searchQuery.spaceKey" value="conf_global" />
                <input type="text" accessKey="$action.getTextStrict('search-pages-action.accesskey')" name="searchQuery.queryString" size="25"/>
                <input type="submit" value="$action.getText('search.name')"/>
            </form>
        #end
        
        #macro (quickSearch $spaceKey)
            <form method="POST" action="$req.contextPath/dosearchsite.action" name="searchForm" style="padding: 1px; margin: 1px">
                <input type="hidden" name="quickSearch" value="true" />
                #if (!$spaceKey)
                <input type="hidden" name="searchQuery.spaceKey" value="conf_global" />
                #else
                <input type="hidden" name="searchQuery.spaceKey" value="$spaceKey" />
                #end
                <input type="text" accessKey="$action.getTextStrict('search-pages-action.accesskey')" name="searchQuery.queryString" size="25"/>
                <input type="submit" value="$action.getText('search.name')"/>
            </form>
        #end

        decorates/main.vmd looks like this:

        <td align="right" valign="middle" width="1%" nowrap>
                        #quickSearch($sitemeshPage.getProperty("page.spacekey"))
                </td>

        Thank you for any future suggestions

        1. Sep 20, 2006

          Matt Ryall says:

          What you have pasted above looks correct to me. To debug the problem, I'd sugges...

          What you have pasted above looks correct to me. To debug the problem, I'd suggest adding some noticeable content inside the <td> in the decorator, and also inside the new macro in macros.vm. You need to restart Confluence to pick up changes to macros.vm, then you should be able to work out whether the new macro is being called.

          Is the search box visible in some spaces but not others? Or on the dashboard or admin pages?

  2. Nov 29, 2007

    Wolfgang says:

    Hi Matt,\\ we habe the same issue. The search field disappears when we do the ch...

    Hi Matt,

    we habe the same issue. The search field disappears when we do the changes. We run on 2.5.4. Do you know if Mark solved the issues?

    KR Mirko

  3. Feb 04, 2008

    Jim Barrick says:

    This macro seems to work well enough under 2.72 except that the bottom of the se...

    This macro seems to work well enough under 2.72 except that the bottom of the search results offer a link to search results in other spaces.  We need some kind of option that allows us to HIDE search results in other spaces