Search Extractors
Use search extractors to add useful indexes to Confluence's search to find pages that meet specific criteria. Some examples are:
Search for all home pages
Search for pages with large attachments
Search all pages for a specific label
Search for all pages last modified by a specific user
Search for pages created in a specific year
Read more about extractors in the Confluence Extractor Module documentation.
To create a search extractor, follow these steps:
- Navigate to Administration > Search Extractors > Create Search Extractor.
- Enter a Name for your search extractor.
- Enter an optional Note to describe your search extractor.
- Enter a script by doing one of the following:
- For existing code, enter a file name in the Script File field.
For new code, enter it in the Inline Script field.
Select Show Snippets to view examples of code.
- Select Add to save the new search extractor.
Example Extractors
All of the following examples are available on Administration > Search Extractors > Create Search Extractor > Show Snippets.
Search Page By Year Extractor
The extractor returns all the pages created in a year.
Line 7: Create an instance of Calendar
.
Line 8: Set the time of our calendar to match the page’s creation date.
Line 9: Get the year the page was created.
Line 10: Store the year as a field in the Lucene document.
The following screen shot shows an example search result for year : 2017
:
Pages With Label Extractor
This extractor returns all the pages that contain the finance label.
Line 9: Create a new Label, "finance".
Line 12: If the page has the "finance" label, store that as a field in the Lucene document.
The search string for this extractor is label : finance
.
Pages With Attachments Size Extractor
This extractor helps to search all the pages with attachment more than 20 meg in size.
Line 9: Calculate 20 megabytes as bytes.
Line 10: Get all attachments for a page and get total size in bytes.
Line 13: If the total attachment size is large enough, store attachment with value 20 for the page.
The search string for this extractor is attachment : 20
.
Page Last Modified By Extractor
This extractor finds all the pages that were last modified by a specific user.
Line 7: Get the name of the last modifier.
Line 8: Store the modifier field with user name as its value.
Use the Confluence username to do a search. For an example if user name is "rfranco" then the search string will be modifier : rfranco
.