It's just an idea the search

Tamás Varga Posted in Beginning Developers 8 months ago

When searching, it would help a lot to select by name and place of residence. Example: John Smith Los Angeles and John Smith Florida, I need John Smith of Florida, then I type this into the search engine- John Smith Florida. I can find you quickly and easily if you have a lot of John.

Breton Rafael Amorim Replied 4 weeks ago

After a glass of wine, I started to make more changes on Custom Fields :-P

I will put my solution here to help anyone in the future. I don't send all code because is a premium component. Also, isn't not finished.

First, I added into CustomField/.../input/location.php a hidden field. Then, I added this JS code to the hidden field:

 $(document).ready(function () {
    if ($('#<?php echo $params['name']; ?>').length) {
        var placesAutocomplete = places({
            container: document.getElementById('<?php echo $params['name']; ?>')
            type: 'city',
            hitsPerPage: 3,
            aroundLatLngViaIP: true
        }); (suggestions) {
            if (!suggestions[0]) {
            $('input[name="<?php echo $params['name'] . '-latlng'; ?>"]').val(cleanStrLatLng(JSON.stringify(suggestions[0].latlng)));
        placesAutocomplete.on('change', e => $('input[name="<?php echo $params['name'] . '-latlng'; ?>"]').val(cleanStrLatLng(JSON.stringify(e.suggestion.latlng))));

    function cleanStrLatLng(strLatLng){
        return strLatLng.replace(/\"|}|{|lat|lng|:/g, "");

With these modifications, on page load, the hidden field is filled by lat and lng data. And, on location change event, this value is updated. To save this information on DB, I copy ossnuserfields_names and add an if condition to create one more field into fields list to be saved.

At this point it's working. Next part is make the search work. Guess I need more wine :-)

Indonesian Arsalan Shah Replied 4 weeks ago

Honestly I am confused about Agolia and how it works, do we need to add data to Agolia first? I am not getting good picture about Agolia. There is something similar here

German Michael Zülsdorff Replied 4 weeks ago

Ja, so i would do 2 things in parallel:
1. use that Algolia API to add a coordinates entity whenever a new member enters his location
2. run a little standalone script looping through already existing members and do the same if the entity isn't already in place

Indonesian Arsalan Shah Replied 4 weeks ago


    $user = new OssnUser();
    $list = $user->searchUser(array(
            'entities_pairs' => array(
                            'name'  => 'gender',
                            'value' => 'male',
                            'name'   => 'intrested_in',
                            'value'  => true,
                            'wheres' => "([this].value IN('men', 'women'))",

Just a example you can search users by entities values

Breton Rafael Amorim Replied 4 weeks ago

I intended to make a new post, but my question is on the same subject.

When I started to customize the OSSN, I didn't realize the importance of the master rule of don't touch a component... Maybe in the future, I make a new component to fix this.

I toke place field and logic from OSSNWall (or Events, I don't remember) and added in User Custom Field. Also, I put in OssnWall a code to take that information and put it automatically in user posts (I know, I broke the rule again and made a new problem to solve in the future). Users can change this information if want.

The tricky part is with the search. My customer wants a search tool with the kind of user they want to relate to (eg. men want a woman or couple male/female) and some distance over some place (50 or 100km, the customer doesn't know the final value yet). The default value is the user place. The search for the kind of user is done and working. The question is how I can make the place search? In my mind, I intended to convert on the fly user place into geocoding (lat, lng) and make the search, but making this kind of conversion to all users in select takes a long time. The Algolia has a conversion API ( to convert the place into coordinates.

I appreciate if someone sends me a inspiration to make this search work.


German Michael Zülsdorff Replied 8 months ago

in order to find something it has to be stored first, of course. ;)
And currently the standard Ossn has no dedicated database row to store the place of residence of a member.
You may create rows like that by means of the Custom User Fields component, but even then new fields like that are not searchable ... maybe a future version of this component will do ....

In the meantime I'd suggest the following:
Use the Bio component and advise your members to include a line like
location: Hamburg

This way you may do a Bio search for 'hamburg' and find all members located in Hamburg.
Not 100% foolproof though, because a member might have a line like '... and my wife is from Hamburg'
but you may use the exact search term 'location: hamburg' then and get the right result.

Yes, yes ... far from perfect and it would need your members to agree on that ... but a first step

pk SIHS Kazmi Replied 8 months ago

its a wild card search - where ever it finds the searched key phrase it displays