Searchable user custom fields and bad advice from ask.discourse.org

Maybe this should be two topics, but it’s an example of trying to solve a particular problem with the AI, and I still want an answer. :slight_smile:

I am helping someone who wants a bunch of user custom fields to be searchable. I told them they’d need a plugin, but they don’t. You can check the “searchable” option in the user settings (just how long has this been true?):

I can even type a / and search for user custom fields and it searches incrementally!

The problem I’m trying to solve is that they want to be able to search by location and it appears that the only way to do that right now is to have a user custom field with a second copy of the address, which seems yucky.

So I asked ask.discourse.org:

https://ask.discourse.com/discourse-ai/ai-bot/shared-ai-conversations/FOFRYdsQy6B--c0W-X6K4A

The interesting thing is that I thought that what the AI has to say is true, but almost none of it is.

Searching for a location (if it’s in a custom field) can be done (with the custom field hack), but it seems to get that nuance in the user directory search?

" There is no built-in way to search user custom fields via the search bar." That’s what I thought! I even gave them a huge price to write a plugin that would do that and then I find out it already exists.

I too suggested the data explorer solution; another bad idea. (So I’m **just as stupid as the AI!?!?!)

Also, the AI seems to frequently try to solve problems for the whole world and not just discourse:

Can we tell it to assume that questions are about Discourse (I’ll try to remind it in my future prompts). Can we tell it to never, ever recommend writing an .hbs file?

Back to the problem of searching for addresses

I guess a simple solution would be a plugin that had a callback on user profile edits that wrote the location to a user custom field location. I think that having it show on the card would allow it to be searched and shown in the search and then use CSS to hide it or the actual location field from the user card/profile.

2 Likes

Aah, not that long. :slight_smile:

I think the perfect solution would be a change to core to get the inbuilt user fields to also be searchable. It is a bit of an oddity that custom ones have more functionality than the default ones.

Though the new config pages format might work well for their inclusion. Having the ability to show/hide/disable as well as optionally making them searchable, etc would be a nice improvement.

You should be able to pull this info out using the data explorer though? But I’m assuming this is for their user base to use rather than an admin report?

4 Likes

Agreed.

Yeah (data explorer was my suggestion until I realized that for years the functionality was on core). They want users to be able to find each other, like if they have the same equipment or are traveling to another city.

2 Likes

Putting the ‘ideal’ aside for a moment…

If they have a set of other custom fields already that are searchable then creating a new ‘Location’ one would probably be the smoothest option. :thinking:

If you can migrate the existing values from the inbuilt Location field to this new Location custom field, and then ‘retire’ the default one by hiding the input box in the profile and the display in profiles and user cards then that should do it?

1 Like

That’s actually what they started with (they had actually used location for something else). But now they want to use the location plugin, which, for some reason, uses location. :rofl:

1 Like

Ahh. Right. That is slightly more of a tangle. :slight_smile:

Are they showing these custom fields on signup? If so, I think they’d need to keep the custom field for Location as I’m not sure you can have the default one on the signup form (same for if they’ve included the extra columns in the user directory too).

(That’s more to do with which you’d consider to be the ‘primary’ one, rather than being able to dispense with either)

I think you may be left with copying the custom field value to the default location. :thinking: (and hiding it to make it more ‘meta’ data just for the Location plugin to use)

Could this be an addition to the Location plugin to cater for this for everyone?

2 Likes