Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Confluence Search Macro/People Search configuration

sherlack September 22, 2014

Hi,

Is there a way to configure the search macro to auto add a wildcard at the end of search query? For example in the People directory our client wants to be able to search for People that start with the following 3 letters "Car", but they dont want to use the wildcard. Is there anyway to solve this in confluence configuration?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
Davin Studer
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.
September 26, 2014

Here is a simplified version of what I am referring to for those who might want to try this. In our organization it was way more complex so I don't want to post that code as it would not be relevant for anybody but us. We added multiple fields that users could search based on name, department, extension, location, etc. I even populated drop down fields in my new form with Ajax calls to a service I wrote. We populated all that extra user profile data using the User Profiles for Confluence plugin which gives you the ability to create more profile fields than Confluence naively supports. It also adds those fields to the index so that they are searchable like this "fieldname:value". Anyway, we filled it out quite a bit, but if you just want to use what is already in Confluence you could do something like this.

AJS.toInit(function(){
	var url = window.location.pathname;
	var newForm = '';
	if(url.indexOf('dopeopledirectorysearch.action') != -1 || url.indexOf('browsepeople.action') != -1) {
		//Hide default form
		AJS.$('#people-search').css('display', 'none');
		
		//Add new form
		newForm += '<form action="#" class="aui" id="newPeopleSearchForm" style="text-align: right;">';
		newForm += '	<input type="text" id="newQueryString" name="newQueryString" class="text" value="' + parseSearchString() + '" size="30">';
		newForm += '	<input type="submit" id="newSearch" name="newSearch" class="aui-button" value="Search">';
		newForm += '	<input type="submit" id="newClear" name="newClear" class="aui-button aui-button-link" value="Clear"">';
		newForm += '</form>';
		AJS.$('#people-search').before(newForm);
		
		//User clicked Search button
		AJS.$('#newSearch').click(function(event){
			event.preventDefault();
			//Fill original search field with our new value
			AJS.$("#queryString").val(createSearchString());
			
			//Submit the original form
			AJS.$("#people-search").submit();
		});
		
		//User clicked clear button
		AJS.$('#newClear').click(function(event){
			event.preventDefault();
			AJS.$('input[name="clear"]').click();
		});
		
		//User hit enter while in search field
		AJS.$('#newQueryString').keyup(function(event){
			if(event.keyCode == 13){
				AJS.$('#newSearch').click();
			}
		});
	}
});
function createSearchString(){
	//Fill out logic here.
	//You may want to look for spaces and add the wild card
	//to the end of each word or something like that.
	return AJS.$('#newQueryString').val() + '*';
}
function parseSearchString(){
	//Fill out logic here.
	//Depending upon what you did when you created the 
	//search string you will need to undo that so that the user
	//can be presented with what they originally typed rather
	//than the changed version.
	var queryString = AJS.$('#queryString').val();
	return queryString.substring(0, queryString.length - 1);
}
Fred Bunting October 2, 2014

Thank you, Davin! :)

Priyanka Lavania
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 30, 2019

Hi Davin,

We have a requirement to exclude personal spaces from search, trying to use above script but does not seems to be working. Using Confluence 6.15.4. Any suggestions?

It is not even adding a test text to the search value.

Davin Studer
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.
July 31, 2019

When this was ported from the old Atlassian Answers site the code blocks got borked. I just fixed it.

Like Priyanka Lavania likes this
Priyanka Lavania
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 31, 2019

Thanks Davin,

I tried to put above code in custom HTML but doesn't seem to be giving me required result. Tried to add 'test' string to the search value

Also tried to add NOT spacekey:\~* to the string to exclude personal spaces, no luck so far...

 

Regards,

Priyanka

3 votes
Davin Studer
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.
September 23, 2014

What we did in our org was we hijacked the people directory page with JavaScript using the custom html section  in Confluence Admin. I included a javascript that first checks to see if the people directory is the current page. If it is then it hides(not deletes) the default search form and creates its own. When the new form is submitted it appends on the the wildcard and then populates the original hidden form with the search string. Then it programatically clicks the original search button.

Steven F Behnke
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.
September 24, 2014

Good god.

Davin Studer
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.
September 24, 2014

Hey, it works ... and pretty well too. Easier than writing a whole addon for this. :)

Steven F Behnke
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.
September 24, 2014

I believe it. It's amazing, really. Just another post on AA that I file away for a rainy day.

Fred Bunting September 25, 2014

Whoa. Any chance you can post the JavaScript?

TAGS
AUG Leaders

Atlassian Community Events