Moodle
  1. Moodle
  2. MDL-25804

Global Search Limit by Category/Course + other parameters

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.9.10, 2.0.1
    • Fix Version/s: None
    • Component/s: Global search
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE

      Description

      Global search currently returns results from the entire moodle website.
      This may return a great number of results, many of them may be irrelevant or distracting in a specific course or category setting.
      A good feature would be if it could be limited to a specific category or course.
      This limitation should be either defined by course/site admin/teacher when setting up a global search block instance (in a specific course or the front page, or by the user at the time of search if permitted/activated by admin, perhapds through the user interface of the advanced search.
      For even better results, I also suggest adding other search parameters to the interface, such as time when document was created, type of document (doc, pdf, ppt, etc...).

        Gliffy Diagrams

          Activity

          Hide
          Nadav Kavalerchik added a comment -

          Hi Amir

          after a quick look into search/query.php...
          i suggest a quick hack:

          after the line (341):

          foreach ($hits as $listing) {
          

          add:

          if ($listing->courseid != $COURSE->id) continue;
          

          which will remove all the results that are not relative to the current course

          Show
          Nadav Kavalerchik added a comment - Hi Amir after a quick look into search/query.php... i suggest a quick hack: after the line (341): foreach ($hits as $listing) { add: if ($listing->courseid != $COURSE->id) continue; which will remove all the results that are not relative to the current course
          Hide
          Amir Elion added a comment -

          Thanks Nadav.
          What if I want full global search on the front page, but limited to course on a specific block?
          Can I configurate this hack for a specific global search block instance?
          Amir

          Show
          Amir Elion added a comment - Thanks Nadav. What if I want full global search on the front page, but limited to course on a specific block? Can I configurate this hack for a specific global search block instance? Amir
          Hide
          Nadav Kavalerchik added a comment -

          if you want it to work on a global level and on a course level at the same time,
          you could try:

          if ($listing->courseid != $COURSE->id and $COURSE->id != 1) continue;
          

          Show
          Nadav Kavalerchik added a comment - if you want it to work on a global level and on a course level at the same time, you could try: if ($listing->courseid != $COURSE->id and $COURSE->id != 1) continue;
          Hide
          Amir Elion added a comment -

          Thanks again Nadav.
          I think I might have not explained myself well.
          I want the front page search to return all the results.
          I want another search block on one of the courses to bring just the results from that course. This means I have to hack just the result for that block in the course. Can I do that with your hack somehow?
          Thanks,
          Amir

          Show
          Amir Elion added a comment - Thanks again Nadav. I think I might have not explained myself well. I want the front page search to return all the results. I want another search block on one of the courses to bring just the results from that course. This means I have to hack just the result for that block in the course. Can I do that with your hack somehow? Thanks, Amir
          Hide
          Nadav Kavalerchik added a comment -

          Yes.

          It will give all the results, when issued from the front page (course id = 1)
          and it will give results relevant to the current course, when issued from within a course context.
          ( i did not tried it myself, but i think it will work just fine )

          Show
          Nadav Kavalerchik added a comment - Yes. It will give all the results, when issued from the front page (course id = 1) and it will give results relevant to the current course, when issued from within a course context. ( i did not tried it myself, but i think it will work just fine )
          Hide
          Amir Elion added a comment -

          Now I think I understand the hack. You should be right - I will try it soon and report here.
          By the way - I think that it will not for an instance of the block but for all search blocks placed in course pages. If you have a global search block in a course - it will always bring back the results for that course only. This means you will only have full global search on front page - right?
          Another approach - can I find out the id for a specific block and add that as the condition for it to work?

          Show
          Amir Elion added a comment - Now I think I understand the hack. You should be right - I will try it soon and report here. By the way - I think that it will not for an instance of the block but for all search blocks placed in course pages. If you have a global search block in a course - it will always bring back the results for that course only. This means you will only have full global search on front page - right? Another approach - can I find out the id for a specific block and add that as the condition for it to work?
          Hide
          Nadav Kavalerchik added a comment -

          "can I find out the id for a specific block and add that as the condition for it to work?"
          Yes, sort of. you have the block's context. it's like its id. but more specific.
          but it is visible on a block level. and not at the level of which i suggested this hack.

          Talk about coincidence, i just got a list of tasks i need to fix for one of the colleges i support
          and this issue is on the list. i guess it will be solved in the next couple of weeks.
          which means, you will get it too!

          I will keep you posted

          Show
          Nadav Kavalerchik added a comment - "can I find out the id for a specific block and add that as the condition for it to work?" Yes, sort of. you have the block's context. it's like its id. but more specific. but it is visible on a block level. and not at the level of which i suggested this hack. Talk about coincidence, i just got a list of tasks i need to fix for one of the colleges i support and this issue is on the list. i guess it will be solved in the next couple of weeks. which means, you will get it too! I will keep you posted
          Hide
          Nadav Kavalerchik added a comment -

          I also noticed there is a bug on the bottom of the return list of results page, when searching an Hebrew word
          clicking on the "page 2" link to navigate to the next page of the results, does not work.
          (somthing to do with the encoding)

          Show
          Nadav Kavalerchik added a comment - I also noticed there is a bug on the bottom of the return list of results page, when searching an Hebrew word clicking on the "page 2" link to navigate to the next page of the results, does not work. (somthing to do with the encoding)
          Hide
          Amir Elion added a comment -

          Nadav,
          Tried it. This is not a good workaround:
          1. The title of search results counts the missing search results - so you get something like "Found 20 Results" and less are listed. Their numbers are also not well ordered - those that are not in the course are still counted.
          2. The second suggestion - with "and $COURSE->id != 1" brings back all the results for the full website in a course page.

          Amir

          Show
          Amir Elion added a comment - Nadav, Tried it. This is not a good workaround: 1. The title of search results counts the missing search results - so you get something like "Found 20 Results" and less are listed. Their numbers are also not well ordered - those that are not in the course are still counted. 2. The second suggestion - with "and $COURSE->id != 1" brings back all the results for the full website in a course page. Amir
          Hide
          Dan Poltawski added a comment -

          Hi,

          We removed Global Search from Moodle 2.2 onwards because it was not working reliably. I'm closing this issue as it reffers to that removed search.

          Please follow MDL-31989 for a new global search for Moodle 2.4.

          Show
          Dan Poltawski added a comment - Hi, We removed Global Search from Moodle 2.2 onwards because it was not working reliably. I'm closing this issue as it reffers to that removed search. Please follow MDL-31989 for a new global search for Moodle 2.4.

            People

            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: