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

Allow facet level sorting #300

Merged
merged 6 commits into from
Jul 11, 2017
Merged

Allow facet level sorting #300

merged 6 commits into from
Jul 11, 2017

Conversation

whikloj
Copy link
Member

@whikloj whikloj commented Dec 14, 2016

JIRA Ticket: https://jira.duraspace.org/browse/ISLANDORA-1337

https://groups.google.com/forum/#!topic/islandora/-sO_VrHBIQg

What does this Pull Request do?

Add a configuration option to facets to allow you to change the sort order from by count to by labels.

What's new?

New solr_field_settings parameter sort_by with either count or index (count is default).

How should this be tested?

  1. Apply PR.
  2. Make a facet with some values for testing. Leave Sort By as Counts.
  3. Do search, see normal facet ordering.
  4. Edit the facet and change Sort By to Labels. Save settings.
  5. Re-run search and see facets ordered by labels.

Example:

  • Does this change require documentation to be updated? There is not much documentation about Facets, so I guess no.
  • Does this change add any new dependencies? No
  • Does this change require any other modifications to be made to the repository (ie. Regeneration activity, etc.)? No
  • Could this change impact execution of existing code? No

Interested parties

@DiegoPino (as he was working Islandora-1337)

Copy link

@DiegoPino DiegoPino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whikloj as always, thanks for this. You are way more concrete and faster than me. I would just ask for some minor corrections:
Travis is failing because of some minor coding standard issues
See: https://travis-ci.org/Islandora/islandora_solr_search/jobs/184075282#L455-L457

It passes other tests because, as we all already known, in many modules and versions codesniffer is simply not running.

@@ -854,6 +854,17 @@ class IslandoraSolrFacets {
}

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing short description of the function here

@@ -854,6 +854,17 @@ class IslandoraSolrFacets {
}

/**
*
* @return mixed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like codeSniffer is expecting a comment after/partof @return statement? Kinda new for me, or i'm just getting old.

@whikloj
Copy link
Member Author

whikloj commented Dec 15, 2016

@DiegoPino Oops, I made that function and then never used it. I have removed it, that should remove those errors.

@DiegoPino
Copy link

@whikloj thanks. Will test and should be ready to merge by today. =)

@DiegoPino
Copy link

@whikloj will wait until we reach the 24hr mark. I'm fine with this by the way 😃

}

if (isset($this->settings['solr_field_settings']['sort_by']) && $this->settings['solr_field_settings']['sort_by'] == 'index') {
ksort($buckets);
Copy link

@adam-vessey adam-vessey Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running this way... this would return the top number of results by count, ordered by value; while, it may be expected that it gives the top values (how I first read it, anyway). For example, say you're limiting the number of values returned, and by numbers, would only get things near the bottom of things lexicographically... Could end up with strange results.

May have to go jam things into the $params_array... Untested, but thinking something like:

$facet_array = islandora_solr_get_fields('facet_fields', TRUE, FALSE);
[...]
$params_array = array(
  'facet' => 'true',
  'facet.mincount' => variable_get('islandora_solr_facet_min_limit', '2'),
  'facet.limit' => variable_get('islandora_solr_facet_max_limit', '20'),
  'facet.field' => explode(',', $facet_fields),
);
foreach ($facet_array as $field => $info) {
  $settings = $info['solr_field_settings'];
  if (($settings['sort_by'] == 'count' && $params_array['facet.limit'] < 0) ||
    ($settings['sort_by'] == 'index' && $params_array['facet.limit'] > 0)) {
    // Avoid specifying default behaviour:
    // @see https://wiki.apache.org/solr/SimpleFacetParameters#facet.sort
    // "The default is count if facet.limit is greater than 0, index otherwise."
    $params_array["facet.{$field}.sort"] = $settings['sort_by'];
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-vessey I did that, but the problem was that you then still have to sort it this way as (for example) sorting by content model in solr you are sorting

islandora:compoundCModel
islandora:bookCModel
islandora:pageCModel

but then in Islandora you see the transformed text but still sorted based on the old text values.

I can go do what you are suggesting, but we still need to sort here to account for the later transformations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-vessey Just re-reading your comments

For example, say you're limiting the number of values returned, and by numbers, would only get things near the bottom of things lexicographically... Could end up with strange results.

This is totally true, but all I am providing is a way to re-order the facets you have from by count to by value. I was trying not to sell this as anything more than adjusting the sort order of your existing facets.

Copy link

@adam-vessey adam-vessey Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@whikloj

Just trying to avoid confusion... The JIRA ticket indicates:

This would implement facet.sort ...

... which is not happening here... Should this be a distinct ticket?

Also, I feel that there may be mixups between the two... Could expand on the description beside the option, to be more explicit in the difference.

... Dealing with the transformations... I'm not sure there's any clean way to do it generally... Almost feeling like it may be more reliably done with something concatenating things together into a purpose-built field in the index... something like the text to display/the:pid, and having something strip off the /the:pid bit when displaying (some arbitrary separator could be used instead of a forward-slash... just using it here as an example)... Dunno...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-vessey Oops, that is my mistake. I did try that until I ran in issue of sorting by one value then displaying a different one (ie. replace with object label). I'll update the ticket with the issue I had with that method.

I'll also work on some more descriptive wording for the options (maybe switch to radio buttons).

As for transformations, I see what you are suggesting. Which isn't a bad idea, but would require a wholesale change to the way facets are created...I think. If not, I'm open to it. But I might need a little direction.

@DiegoPino
Copy link

@adam-vessey @whikloj are we OK with this one? Would love to see this in the new release (as a new feature). Thanks

@adam-vessey
Copy link

@DiegoPino, @whikloj: Were it described as a feature separate from ISLANDORA-1337 (as in, a separate ticket entirely)... I think it would be fine? The original discussion (linked from ISLANDORA-1337) regarded ordering dates/years, which could end up with holes as described above with "strange results".

... Also, thinking we should be more explicit about what this new ticket does... As if/when ISLANDORA-1337 is actually implemented using facet.sort, I imagine there being confusion about how the two options may interact.

@whikloj
Copy link
Member Author

whikloj commented Feb 21, 2017

@adam-vessey Those are fair points... I can see a clear path to using facet.sort with dates and numbers. Its just handling the renderText which changes the text value we sorted on to the object label. That could cause you to get odd results.

But I'll move back to that attempt and perhaps you can help me solve any issues that arise.

@DiegoPino I'm not sure this will be complete for code freeze, but I'll see what I can do.

@DiegoPino
Copy link

@whikloj no worries. Thanks for taking care of this. @adam-vessey thanks for the reviews. Even if not ready for code freeze, i really appreciate the work implied 😄

@@ -236,6 +236,19 @@ class IslandoraSolrQueryProcessor {
$params_array = array_merge($params_array, $params_date_facets);
}

// Determine the default facet sort order.
// https://cwiki.apache.org/confluence/display/solr/Faceting#Faceting-Thefacet.sortParameter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 240 is giving "Line exceeds 80 characters; contains 96 characters". Since It's a link, so not sure how you want to split that into 2 lines.

@DiegoPino
Copy link

@whikloj give me ping when you feel you are ready for another review. Thanks!

@whikloj
Copy link
Member Author

whikloj commented Apr 17, 2017

Sorry for the delay, so this seems to work.

But again if you add (for example) the content model and replace the entry with the object label, then the order will be wrong again.

Not sure there is a simple solution to that problem...so I think this is a handy feature so long as you are aware of that.

@whikloj
Copy link
Member Author

whikloj commented Apr 24, 2017

bump

@DiegoPino
Copy link

@whikloj i got confused by your comment, sorry. how do we make people aware of the limitations? is that another ticket?

@whikloj
Copy link
Member Author

whikloj commented Apr 24, 2017

@DiegoPino I'm not sure what the best way to handle that would be.

Perhaps just a warning that if you use this sort on a field that you have already enabled "Replace PID with Object Label" then the sort order will not work. But I'm not really sure.

@DiegoPino
Copy link

@whikloj I feel that what you suggest there is fine, a warning/little comment on the UI side should be enough. No rush on this. I'm not the best at wording stuff, so feel free to suggest/commit and we can ask @manez or @adam-vessey to review?

@DiegoPino
Copy link

@whikloj this just needs that last piece of wording and we should be ready to merge. Thanks

@whikloj
Copy link
Member Author

whikloj commented May 3, 2017

@DiegoPino I stuck that under the radio buttons on the facet configuration... I think that is probably the best place for it.
752ebdf

@whikloj
Copy link
Member Author

whikloj commented Jul 11, 2017

bump

@DiegoPino
Copy link

@whikloj oh... i had forgotten about this. I will merge now. This was checked and tested, and wording was Ok for me.

@DiegoPino DiegoPino merged commit c836f6a into Islandora:7.x Jul 11, 2017
@whikloj whikloj deleted the ISLANDORA-1337 branch February 7, 2019 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants