Fix sort parameters to use field aliases, validate in query object

pwolanin - July 1, 2009 - 23:17
Project:Apache Solr Search Integration
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Currently the sort parameters don't respect any field aliases that are set into the query object - since this affects Drupal.org, we want to fix it. We also have sort validation happening in the module instead of inside the query object where it belongs.

#1

pwolanin - July 1, 2009 - 23:45
Status:active» needs work

here's a start

AttachmentSize
sort-fix-507708-1.patch 5.77 KB

#2

pwolanin - July 2, 2009 - 03:45
Status:needs work» needs review

I'm not sure about the variable return type of method get_solrsort() versus adding another method to the interface.

AttachmentSize
sort-fix-507708-2.patch 10.82 KB

#3

pwolanin - July 2, 2009 - 03:45

I'm not sure about the variable return type of method get_solrsort() versus adding another method to the interface.

AttachmentSize
sort-fix-507708-2.patch 10.82 KB

#4

pwolanin - July 2, 2009 - 04:30

slight cleanup

AttachmentSize
sort-fix-507708-3.patch 10.88 KB

#5

JacobSingh - July 2, 2009 - 04:43

Overall good, here's one small point:

- function get_solrsort();
+ function get_solrsort($as_array = FALSE);

Generally speaking, a function should have only one return type. I suggest doing something like:

function get_sort_column()

function get_sort_direction()

or always return a structure.

#6

JacobSingh - July 2, 2009 - 04:49

if (!empty($fv['apachesolr_search']['retain-filters']) && $fv['apachesolr_search']['querystring']) {
- $querystring = $fv['apachesolr_search']['querystring'] . '&retain-filters';
+ $querystring = $fv['apachesolr_search']['querystring'] . '&retain-filters=1';
}

This isn't really related, but whatever.

ummm.....

'type' => 'bigass'

?!?

+ $this->parse_sortstring($sortstring);

Too bad we don't have overloading in PHP. Really would be nicer as an overloaded set_solrsort.

public function set_available_sort($field, $sort) {
- $this->available_sorts[$field] = $sort;
+ public function set_available_sort($name, $sort) {
+ // We expect non-aliased sorts to be added.
+ $this->available_sorts[$name] = $sort;
+ }
+

A little unclear about this...

+ protected function parse_sortstring($sortstring) {
+ // Validate and set sort parameter
+ $fields = implode('|', array_keys($this->available_sorts));

Where is the | being used here? The function to set available sorts doesn't look like it would be expecting a pipe in the array key.

#7

pwolanin - July 2, 2009 - 05:21

Guess I left my test field aliases in there...

The '|' is for the later regex so we validate that we only have an allowed sort.

AttachmentSize
sort-fix-507708-7.patch 10.23 KB

#8

JacobSingh - July 2, 2009 - 05:27

Looks good to me.

#9

pwolanin - July 2, 2009 - 05:36

doxygen fix

AttachmentSize
sort-fix-507708-8.patch 10.27 KB

#10

pwolanin - July 2, 2009 - 05:52
Status:needs review» fixed

committed to 6.x

#11

System Message - July 16, 2009 - 06:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.