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

Use facets for metadata #148

Merged
merged 14 commits into from
Feb 6, 2015
Merged

Use facets for metadata #148

merged 14 commits into from
Feb 6, 2015

Conversation

tommyp
Copy link
Contributor

@tommyp tommyp commented Jan 21, 2015

This PR contains the work necessary to reduce specificity in FinderFrontend. To do this we need to remove each Document's Model and use the Finder to figure out what fields we are asking to be returned from Rummager and what metadata values should we show for each document. The way I've done this is adding the concept of a FilterableFacet and changing Facet to represent information about a set of metadata key/value pairs and if this should be filterable we then suggest a type of {multi-select|date} and it becomes a FilterableFacet.

The commits roughly go as follows:

  • Use the Finder's facets to tell Rummager what values we want returned
  • Remove document Models and Parser
  • Refactor the facets to become Facet and FilterableFacet and expose Finder#metadata and Finder#filters
  • Allow metadata labels for when the name of the facet isn't what we want to label the metadata with
  • Set a summaries flag on the Finder to decide if we should show them
  • Refactor AbstractDocument to Document and use the facets to convert metadata values to labels
  • Pass the FinderPresenter object down to the Document
  • Cleanup the features by updating the fixture content item with the metadata flags and the closed_date facet

After some discussion with @evilstreak I took a bit of a different approach and added extra commits which do the following:

  • Set if the facet should be filterable and if it should be displayed as result metadata by having every type of facet be a Facet class or one of it's child classes.
  • Remove filterable being hardcoded into the Filterable Facet class, but we still use this class so we can set the values of the facets.
  • FacetParser now uses this new way of initialising the Facets.
  • Use these new type of facets to specify tag and date metadata for the document
  • Add the updated schema attrs to the CMA Cases content item fixture.

The additional commits were made to handle edge cases in:

  1. International Development Funding where we have metadata which is filterable but not displayed under the results.
  2. AAIB Reports which has free text fields which aren't filterable, though these are only displayed in SpecialistFrontend.

@@ -64,8 +76,7 @@ def related

def results
@results ||= ResultSet.get(
slug,
document_type,
self,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm really unsure about this. It makes the owning object unclear.

My gut says to start by removing calls to the some_finder_presenter.results method here with direct uses of ResultSet, but I'm not entirely sure.

@tommyp tommyp force-pushed the use-facets-for-metadata branch 3 times, most recently from 7357fd9 to a743bae Compare January 30, 2015 11:35
@tommyp tommyp changed the title Use facets for metadata DO NOT MERGE Use facets for metadata Feb 2, 2015
@tommyp
Copy link
Contributor Author

tommyp commented Feb 2, 2015

Hold off merging this while I do some investigation. Think I've found a small issue with DSU.

@tommyp tommyp force-pushed the use-facets-for-metadata branch 4 times, most recently from 917d9ec to 4ca0b5e Compare February 2, 2015 17:08
@tommyp tommyp changed the title DO NOT MERGE Use facets for metadata Use facets for metadata Feb 2, 2015
@tommyp
Copy link
Contributor Author

tommyp commented Feb 2, 2015

This is good to go now. I noticed some weirdness with the metadata labels not being changed to short_name so I fixed that and cleaned up one of the commits which was changed later.

tommyp added a commit that referenced this pull request Feb 3, 2015
First pass at a doc for what the Finder Content Item should contain.
Leaving the facets for now until
#148 is merged.
description = description.gsub(/\.\s[A-Z].*/, '.') if description.present? && finder.show_summaries?
end

def date_metadata_keys
Copy link
Contributor

Choose a reason for hiding this comment

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

I think all these metadata key and mapping methods can be private

@evilstreak
Copy link
Contributor

Review still in progress! TBC

@tommyp tommyp force-pushed the use-facets-for-metadata branch from 4ca0b5e to 5952134 Compare February 3, 2015 18:26

# This truncates the description at the end of the first sentence
description = description.gsub(/\.\s[A-Z].*/, '.') if description.present? && finder.show_summaries?
end
Copy link
Contributor

Choose a reason for hiding this comment

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

What about something like this to break it down a bit?

def summary
  if finder.show_summaries? && description.present?
    description.gsub(/\.\s[A-Z].*/, '.')
  end
end

private # or in the initializer
def description
  attrs.fetch(:description, nil)
end

@tommyp tommyp force-pushed the use-facets-for-metadata branch 2 times, most recently from e61d488 to 00ce854 Compare February 5, 2015 11:01
@tommyp tommyp force-pushed the use-facets-for-metadata branch 2 times, most recently from 04506c1 to 8778e01 Compare February 5, 2015 11:33

def initialize(attrs)
def initialize(attrs, finder)
attrs = attrs.with_indifferent_access
Copy link
Contributor

Choose a reason for hiding this comment

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

What prompted the change to turn this into a HashWithIndifferentAccess?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the test data is JSON, but the hash returned in the real world is symbols so all these setters in the initialize method fail in the tests. Should I change all the data?

Copy link
Contributor

Choose a reason for hiding this comment

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

We should make the test data reflect the real world data – otherwise someone could remove this line and replace all the fetch arguments with strings, and the tests would indicate everything is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For reference for anyone else this was discussed offline. This line was originally in https://github.com/alphagov/finder-frontend/blob/master/app/parsers/document_parser.rb#L3 but because we don't have a DocumentParser anymore I moved this line to the initialize method of Document.

@evilstreak
Copy link
Contributor

Sorry for adding another round of comments. This really is good work.

I'll come over and work with you to get it merged today.

tommyp added 14 commits February 5, 2015 14:15
This commit removes the document models which defined what attrs to be
returned as metadata and if a summary should be shown.
As we no longer need to parse documents, we can remove this file and
it's spec.
We can now use the facets to generate the metadata apart from certain
metadata keys which not have a corresponding filter so we need to
introduce a distinction.

This commit does a fair bit of refactoring around this as well as
introducing a `filterable?` method to the existing facet types. I've
also exposed methods for `Finder#filters` and `Finder#metadata` to
access these more easily.

I've also replace the existing Facet class with one which is
unfilterable and all the other facets are subclasses from
FilterableFacet which subclasses from Facet itself.
This commit alows us to see if the Finder should show summaries.
Now that we don't need this Abstract class we can rename it to Document.
This commit also refactors it to recieve the Finder which it uses to see
if it should have a summary along with the facets which are used to do
metadata value to label conversion.
As we use the Finder and it's Facets we need to pass it down through to
the Document. This commit updates the ResultSet model, the
ResultSetParser and the latter's spec.
This class still exists so we can set the values, but now we can define
filterable using the facet attrs set in the schema.
This commit updates the FacetParser to handle unfilterable facets
properly and updates it's spec.
With the new facet structure,  we can use this to figure out what are
dates and what are text based metadata.
This commit adds the short_names to the facets in the CMA Case Finder
fixture along with the closed date facet.
This new method is a bit cleaner than what was there previously.
This new method removes an unnecessary method and moves the short_name
call to the Finder.
@tommyp tommyp force-pushed the use-facets-for-metadata branch from 8778e01 to 17fd23d Compare February 5, 2015 14:15
evilstreak added a commit that referenced this pull request Feb 6, 2015
@evilstreak evilstreak merged commit 21ea795 into master Feb 6, 2015
@evilstreak evilstreak deleted the use-facets-for-metadata branch February 6, 2015 09:04
@evilstreak
Copy link
Contributor

🎆

@tommyp
Copy link
Contributor Author

tommyp commented Feb 6, 2015

🎉🎉

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