Controlling what gets displayed in search results in confluence
Asked by Alex Yasurek:

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


Answers:
author: Adrian Moerchen
body: 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)<https://confluence.atlassian.com/display/DOC/Confluence+Search+Syntax#ConfluenceSearchSyntax-NOTsearch>

comments: author: Alex Yasurek
body: 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


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


author: Davin Studer
body: 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.

comments: author: Alex Yasurek
body: 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.


author: Davin Studer
body: 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.


author: Alex Yasurek
body: 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.


author: Davin Studer
body: 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.


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


Tags: lucene

search