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?
Community moderators have prevented the ability to post new answers.
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); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When this was ported from the old Atlassian Answers site the code blocks got borked. I just fixed it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Good god.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey, it works ... and pretty well too. Easier than writing a whole addon for this. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe it. It's amazing, really. Just another post on AA that I file away for a rainy day.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.