Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geodistance filter, missing options #200

Closed
pierrre opened this issue Jun 23, 2012 · 31 comments
Closed

Geodistance filter, missing options #200

pierrre opened this issue Jun 23, 2012 · 31 comments

Comments

@pierrre
Copy link
Contributor

pierrre commented Jun 23, 2012

There are missing options:

  • distance_type
  • optimize_bbox

Do you have any recommendation?
Are class constants required? (arc, plane, memory, indexed, none)

@pierrre
Copy link
Contributor Author

pierrre commented Jun 24, 2012

Hmmm, I think we should completely rewrite Elastica_Filter_GeoDistance.
Setters don't use setParam() (they use protected variables).
toArray() builds the array manually, so "_cache" option is not usable...

@pierrre
Copy link
Contributor Author

pierrre commented Jun 24, 2012

It should also support location as geohash:
http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-filter.html

There is a backward compatibility break in the constructor (PHP is a stupid language).

@ruflin
Copy link
Owner

ruflin commented Jun 24, 2012

Missing options: I think here we can use some constants.

Concerning setParam(): Yes, we should to that. I already did it for most of the queries and filters, but not all.

Backward compatitbility: Question is, what has first priority. Probably all params in the constructor should be optimal. What would be your suggestion?

PHP: Every language has advantages and disadvantages ;-)

@pierrre
Copy link
Contributor Author

pierrre commented Jun 24, 2012

All currently used parameters are mandatory:

  • key (field name)
  • location (latitude+longitude OR geohash)
  • distance (string format)

Other parameters are optional:

  • distance_type
  • optimize bbox

The problem is: in the current constructor, only latitude+longitude is supported, not geohash.
And we can't change that without BC break.

@ruflin
Copy link
Owner

ruflin commented Jun 25, 2012

I agree on that, but what would be the solution to allow both? Because of PHP, we cannot have two different constructors except in the case that we use two different class which inherit from an abstract class ...

BTW: I'm currently on holiday, so I'm probably going to respond less frequently ;-)

@pierrre
Copy link
Contributor Author

pierrre commented Jun 25, 2012

We could use func_get_args(), but it's really shitty...
Maybe we should break the backward compatibility for this constructor...
It is also possible to implement missing options now, and implement geohash later :P

Have a great holiday!
(I'd like to fix #76 before implementing other features)

@ruflin
Copy link
Owner

ruflin commented Jun 25, 2012

Ugh, I don't like the func_get_args function at all. I agree on breaking BC, but I don't know yet how the new implementation would work? Example?

@pierrre
Copy link
Contributor Author

pierrre commented Jun 25, 2012

public function __construct($key, $location, $distance)

$location can be:

  • an array array(48.86, 2.35) or an associative array array('latitude' => 48.86, 'longitude' => 2.35)
  • a string for geohash

@ruflin
Copy link
Owner

ruflin commented Jun 25, 2012

I quite like this solution. We could add a "deprecated" for the next to releases where we check if there are 4 params and then would convert the old params to the new version bit a function that is deprecated. Like this, people that use the never version should realize.

Please make sure to always update changes.txt with your changes because I use this file for the release notes and it makes it easy for people to look up relevant changes.

@pierrre
Copy link
Contributor Author

pierrre commented Jun 25, 2012

Hmmm, there would be 2 constructors :P
It's not possible in PHP, right?

@ruflin
Copy link
Owner

ruflin commented Jun 27, 2012

Hm, somehow my e-mail answer did not make it into github.

There would be only 1 constructor, be we would use the ugly func_get_args function to check for a fourth param. If we have a fourth param, we call a function (which is deprecated) to remodel the arguments to the new structure. This code will only exist for 1-2 releases, after that we are going to remove it.

@ruflin
Copy link
Owner

ruflin commented Jun 27, 2012

no, there would be an if clause inside the constructor

On 26.06.2012, at 00:28, Pierre Durand reply@reply.github.com wrote:

Hmmm, there would be 2 constructors :P
It's not possible in PHP, right?


Reply to this email directly or view it on GitHub:
#200 (comment)

@pierrre
Copy link
Contributor Author

pierrre commented Jun 27, 2012

It could call the constructor again with 3 arguments :P

@ruflin
Copy link
Owner

ruflin commented Jun 27, 2012

right. even better

@pierrre
Copy link
Contributor Author

pierrre commented Jul 3, 2012

We could also use the "distance_unit" parameters, instead of the (dirty) current format.
http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-filter.html

Currently, the "distance" parameter is a string ("19km").

It is possible to use the "distance" parameters as a number (19), and add the "distance_unit" parameters ("km").
I think it is better.

It will be easier to validate

    public function setDistance($distance) {
        // TODO: validate distance?
        $this->_distance = $distance;
        return $this;
    }

@pierrre
Copy link
Contributor Author

pierrre commented Jul 3, 2012

Is it a good idea to have setDistance() / setLatitude() / setLongitude() methods, because these parameters are mandatory in the constructor?

@pierrre
Copy link
Contributor Author

pierrre commented Jul 8, 2012

I just cleaned the geodistance filter:
954f1b2

Is it ok?

@ruflin
Copy link
Owner

ruflin commented Jul 11, 2012

Finally, my feedback:

  • Is is possible to use both, raw distance and distance_unit, so the user can choose?
  • I think it is good to have the setters available, as it should also possible to modify the values after the object has been instantiated
  • See comments int he pull request ;-)

@pierrre
Copy link
Contributor Author

pierrre commented Jul 11, 2012

It is really difficult to implement raw distance + distance unit & distance, because we have to support the old constructor (for retrocompatibility).
If we drop the old constructor, it could be easier to implement distance unit.

It is not easy to have setters for latitude, longitude, or geohash, because they require the "key" parameter.
If we create the filter with the geohash parameter, what happen if we call setLatitude() alone????

Maybe we could add a setLocation($key, $location) method.
It also means we'll have to unset the previous value in the "params".

What should we do?

@ruflin
Copy link
Owner

ruflin commented Jul 14, 2012

Ah, this strange thing named BC again ;-)

A suggestion from my side: We keep the old constructor, but split up the distance and the unit (regexp, ...). We then store it seperate in the object, which also allows the setter.

Fro the setLatitude(): I would argue, nothing happens until toArray() is called, where an exception is thrown. Either the geohash or the longitude AND latitude have to be set.

I would suggest, that we have a seperate function setKey(...).

Perhaps things get simpler, if we do not store latitude / longitude already in an array (even though it is passed in an array) and create the structure for the request in toArray().

Somehow it doesn't feel 100% logical yet, also what I described above :-(

@pierrre
Copy link
Contributor Author

pierrre commented Jul 28, 2012

Do you think we need distance + unit feature?

@ruflin
Copy link
Owner

ruflin commented Jul 29, 2012

I would be nice ;-)

@pierrre
Copy link
Contributor Author

pierrre commented Jul 30, 2012

I have an idea: the last parameter could be a string (distance + unit as string) or an associative array (distance as float, and unit as string)

We could also add a setter: setDistance($distance, $unit = null)
Unit is optionnal.

@ruflin
Copy link
Owner

ruflin commented Jul 31, 2012

I like both :-) And if only a string is passed to setDistance? Will the function try to split it up?

@pierrre
Copy link
Contributor Author

pierrre commented Jul 31, 2012

No, it will use the parameter as a string.
If unit is null, we cast the first argument as a string, and use the basic filtre structure.
If distance is not null, we cast the first argument as a float and the second as a string, and we use the advanced filter structure.

@ruflin
Copy link
Owner

ruflin commented Jul 31, 2012

Right, forgot that there were two structures. Sorry.

@ruflin
Copy link
Owner

ruflin commented Jan 13, 2013

Any updates here?

@ruflin
Copy link
Owner

ruflin commented Jun 5, 2015

@pierrre As you closed this, I assume this is not needed anymore or already implemented.

@pierrre
Copy link
Contributor Author

pierrre commented Jun 5, 2015

Yes, I closed all my old issues: https://github.com/pierrre?tab=activity
I use the official PHP client.

@ruflin
Copy link
Owner

ruflin commented Jun 5, 2015

Ok, thx. Even though I would prefer that you would still use Elastica ;-)

@pierrre
Copy link
Contributor Author

pierrre commented Jun 5, 2015

:-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants