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

Issue #66: Add template for search #133

Merged
merged 9 commits into from
Oct 29, 2024
Merged

Conversation

TomoTsuyuki
Copy link
Contributor

@TomoTsuyuki TomoTsuyuki commented Oct 17, 2024

Include a template area for searching.

Testing instruction

  • Go to "Site administration" > "General" > "Advanced features".
  • Enable Global search.
  • Go to "Site administration" > "Plugins" > "Activity modules" > "CMS" > "Manage content types"
  • Click "Add new content type".
  • Set "Template test" in "Name", "test" in "ID Number", "Template test" in "Name" under "Activity fields", and "{{name}} Testsearchstring" in "Content" under "Activity field".
  • Click "Save and display" and confirm the "Some name Testsearchstring" is in "Preview"
  • Create a course.
  • Turn on "Edit mode" and add "Template test" CMS activity.
  • Go to "Site administration" > "Plugin" > "Search" > "Search areas".
  • Click "Gradual reindex" for cms activity, and run "Global search indexing" schedule task.
  • Search "Testsearchstring" in global search box.
  • Confirm the "Testsearchstring" is in the result.

@TomoTsuyuki
Copy link
Contributor Author

I updated the code to try to use a rendered template, if possible.
Some of data sources may be used with user records and the renderer may throw an exception.
Use raw template when rendered template doesn't work.
Note: User-specific data cannot be indexed.

@TomoTsuyuki
Copy link
Contributor Author

Updated instruction with custom field:

  • Go to "Site administration" > "General" > "Advanced features".
  • Enable Global search.
  • Go to "Site administration" > "Plugins" > "Activity modules" > "CMS" > "Manage content types"
  • Click "Add new content type".
  • Set "Template test" in "Name", "test" in "ID Number", tick "Custom fields" for "Datasources", "Template test" in "Name" under "Activity fields", and "{{name}} Testsearchstring {{fields.test}}" in "Content" under "Activity field".
  • Click "Save and display" and confirm the "Some name Testsearchstring" is in "Preview"
  • Click "Add a new category" in "Custom field settings".
  • Click "Add a new custom field", and click "Short text".
  • Set "Test" in "Name", "test" in "Short name", and click "Save changes".
  • Create a course.
  • Turn on "Edit mode" and add "Template test" CMS activity with "CustomFieldTest" in "Other fields".
  • Go to "Site administration" > "Plugin" > "Search" > "Search areas".
  • Click "Gradual reindex" for cms activity, and run "Global search indexing" schedule task.
  • Search "Testsearchstring" in global search box.
  • Confirm the "Testsearchstring" is in the result.
  • Search "CustomFieldTest" in global search box.
  • Confirm the "CustomFieldTest" is in the result.

@TomoTsuyuki
Copy link
Contributor Author

I merged file search from other PR, as it's for same issue.

Testing instruction for file search:

  • Install customfield_file plugin into customfield/field/file
  • Go to "Site administration" > "General" > "Advanced features".
  • Enable Global search.
  • Go to "Site administration" > "Plugin" > "Search" > "Manage global search".
  • Choose search engine which supports file search.
  • Set up the search engine and turn on "File search".
  • Go to "Site administration" > "Plugins" > "Activity modules" > "CMS" > "Manage content types"
  • Click "Add new content type".
  • Set "File test" in "Name", "filetest" in "ID Number", tick "Custom fields" for "Datasources", "File test" in "Name" under "Activity fields".
  • Click "Save and display".
  • Click "Add a new category" in "Custom field settings".
  • Click "Add a new custom field", and click "File".
  • Set "Test file" in "Name", "testfile" in "Short name", and click "Save changes".
  • Create a course.
  • Prepare a text file, "Filestring" in the file. (e.g. using command echo 'Filestring' > testfile)
  • Turn on "Edit mode" and add "Test file" CMS activity, and upload the prepared file..
  • Go to "Site administration" > "Plugin" > "Search" > "Search areas".
  • Click "Gradual reindex" for cms activity, and run "Global search indexing" schedule task.
  • Search "Filestring" in global search box.
  • Confirm the "Filestring" is in the result.


$fileareas = $this->get_search_fileareas();
// File is in "customfield_file" for component, "value" for filearea, and for customfield data id for itemid.
$contextid = \context_system::instance()->id;
Copy link
Member

Choose a reason for hiding this comment

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

is it correct context ID for files?

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 file customfiled, it's using context which is from custom field handler context.
$context = $this->get_field()->get_handler()->get_configuration_context();
https://github.com/andrewhancox/moodle-customfield_file/blob/11a770aa46fa170d498a062a6cf3c75def145bc4/classes/data_controller.php#L76

The get_configuration_context function in mod_cms is using \context_system::instance();, so the context for the file should be correct.

return \context_system::instance();

Copy link
Member

Choose a reason for hiding this comment

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

Can you please create an issue for mod_cms and cross link it to andrewhancox/moodle-customfield_file#10
So we can fix mod_cms search once related customfield_file is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the issue #136

@dmitriim dmitriim merged commit 8f0cf15 into MOODLE_401_STABLE Oct 29, 2024
11 checks passed
@dmitriim dmitriim deleted the issue66-add-template branch October 29, 2024 22:00
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.

2 participants