Controlling what gets displayed in search results in confluence

Does anyone know if there is a way to get to search results between the time the search engine retrieves its results and the time it gets displayed on the search results page in confluence?

The reason being is that I would like to exclude certain pages from appearing when a user does a search. All the pages I want to exclude have a title that starts with a underscore (ex: _page title). My thinking was that instead of messing around with lucene having it ignore pages that start with a underscore, I can cut it off before it displays the results in the confluence search results page.

In simple terms, I imagine adding some if statement where it checks the title of the page and if it includes a underscore, then it skips it, if not then it displays it on the search results page. I imagine this would be done in the search results page template or some place where lucene hands the search results off to confluence.

Does anyone know if what I am thinking is even remotely possible or if you know of a better way to handle my situation?

Thanks

2 answers

1 accepted

You may do something like this:

  • Write a ServletFilter, which listens to the search call (api/searchv3 or something similar)
  • Extend the send "query" with something like "AND NOT title:_*"

https://confluence.atlassian.com/display/DOC/Confluence+Search+Syntax#ConfluenceSearchSyntax-NOTsearch

Thanks. You post made me realize that its better to add "AND NOT title:_*" instead of just "-title:_" in the event the user is also adding some conditional to their search string. I am going to try doing it in javascript first and seeing how well that works before trying to create a servletfilter. Thanks

Davin Studer Community Champion Mar 26, 2014

I believe the "-" does an implied AND NOT, but exlicitly stating it is ok too ... might look nicer for your users.

1 vote
Davin Studer Community Champion Mar 25, 2014

Do you want people to be able to see these pages at all? If not then if you apply a viewing restriction to the page(s) it will not show up in search results.

These pages are includes that appear in other pages. We essentailly created a library of include pages that get brought into other pages but when people search for something that appears in those include pages, they appear first. We want the actual page that its being included in to appear first. There is also no need for people to see these include pages so thats why we want to just hide them from search results altogether.

Davin Studer Community Champion Mar 25, 2014

Ah! Well, I've got no easy options for you then ... except maybe train your users to append "-title:_" to their search string ... or find a way to auto add it.

I was hoping there was a way to do this in the page template for the search results page. Thought it would be possible to intercept the results before they get displayed on the page.

The one solution you mentioned may also work. I assume it would need to be done with javascript to append "-title:_*" to the end of search strings before it gets submitted to the engine.

Davin Studer Community Champion Mar 26, 2014

I think your options would be to use JavaScript to add it prior to form submission or to create a plugin that would do this. Either way you will need to do some development to get what you want ... I think.

I was thinking the javascript route may be easier to do then having to create a plugin that will append that to search strings.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

631 views 21 11
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you