dandange8005 / Ultra-Essentials

Blackboard Ultra Essentials - LC Guide for staff
https://xerte.cardiff.ac.uk/play_18321#UltraEssentials
MIT License
1 stars 0 forks source link

Adding a search function to Ultra Essnetials #44

Open dandange8005 opened 8 months ago

dandange8005 commented 8 months ago

Algolia

https://www.algolia.com/doc/

Integrating Algolia into your documentation project involves a few key steps. Here's a simplified guide to get you started:

  1. Sign Up and Setup: First, sign up for an Algolia account if you haven't already. After signing up, create a new index in Algolia's dashboard. An index is where your search data will be stored.

  2. Index Your Content: To make your documentation searchable, you need to index it with Algolia. This can be done by either using Algolia's API directly or one of their SDKs (for JavaScript, PHP, etc.). You will need to create a script or use a tool to extract your documentation content and format it into JSON objects that Algolia can understand. Each object should represent a piece of your documentation (like a page or section) and might include fields like title, content, and any other metadata you find useful.

    Here's an example of how you might format a document for Algolia:

    {
     "title": "How to Integrate Algolia",
     "content": "Step-by-step guide to integrating Algolia into your project.",
     "url": "/docs/integration-guide"
    }
  3. Push Data to Algolia: Use Algolia's API or SDK to push your formatted documentation content to the index you created. If you're using JavaScript, the process might look something like this:

    const algoliasearch = require('algoliasearch');
    const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
    const index = client.initIndex('your_index_name');
    
    const docs = [/* your documentation objects here */];
    
    index.saveObjects(docs, { autoGenerateObjectIDIfNotExist: true })
     .then(({ objectIDs }) => {
       console.log(objectIDs);
     })
     .catch(err => {
       console.error(err);
     });
  4. Integrate Search into Your Frontend: Add a search input to your Xerte Bootstrap template. Use Algolia's InstantSearch.js library to easily integrate the search functionality. InstantSearch.js provides out-of-the-box components for search inputs, results, and pagination.

    Here's a basic example of how to set up InstantSearch.js in your project:

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/instantsearch.css/themes/satellite.min.css" />
    <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
    
    <div id="search-box"></div>
    <div id="hits"></div>
    
    <script>
     const search = instantsearch({
       indexName: 'your_index_name',
       searchClient: algoliasearch('YourApplicationID', 'YourSearchOnlyAPIKey'),
     });
    
     search.addWidget(
       instantsearch.widgets.searchBox({
         container: '#search-box',
       })
     );
    
     search.addWidget(
       instantsearch.widgets.hits({
         container: '#hits',
         templates: {
           item: document.getElementById('hit-template').innerHTML,
         },
       })
     );
    
     search.start();
    </script>
  5. Customize and Refine: After integrating the basic search functionality, you might want to customize the search experience or refine the search results. Algolia offers features like faceting, filtering, and relevance tuning to enhance search capabilities.

dandange8005 commented 2 months ago

The problem

There is no search functionality on our resource site which is a huge limitation from resources point of view.

I would like to implement a search functionality to be implemented to our LCE resource.

Essential feature

Enhanced