Giter Club home page Giter Club logo

Comments (7)

borisschapira avatar borisschapira commented on July 24, 2024

I was also astonished by this behaviour but I understood when explained in another issue : in fact, Algolia is indexing your content by pieces (see https://github.com/algolia/algoliasearch-jekyll#settings for the settings), including each paragraph separately.

When searched, the index is able to point at the specific paragraph containing the searched term 👀

from algoliasearch-jekyll.

pixelastic avatar pixelastic commented on July 24, 2024

As @borisschapira perfectly explained, the anchor in the url is here so the search result is linked to the exact HTML node in the page it references.

If you want to remove it, you can use the custom hooks and override the url attribute. For example, you can create a file in _plugins/search.rb with the following content (every page in _plugins will be loaded by Jekyll).

class AlgoliaSearchRecordExtractor
  def custom_hook_each(item, node)
    # Here you have access to the item object, right before it is pushed
    # Modify it as much as you want (in your case, changing the item[:url] key) then return it
    # item[:url] = '...'
    item
  end
end

Also note that you can run jekyll algolia push -n to do a dry-run (parse data but does not send anything to the Algolia API).

Tell me if this works for you

from algoliasearch-jekyll.

iloveip avatar iloveip commented on July 24, 2024

@borisschapira @pixelastic Thank you very much for your answers! It would be great if index could point at the specific paragraph, but instead it points at the top of the page, even though the paragraph is at the bottom.

I guess I can simply remove #algolia:{{ css_selector }} from:

<a class="algolia__result-link" href="{{ full_url }}#algolia:{{ css_selector }}">
    {{{ _highlightResult.title.value }}}
 </a>

Would that be enough?

P.S. I have a few more questions about integrating Algolia, but I'm not sure if GitHub issues is the right place to post them. Is it ok if I ask them here?

from algoliasearch-jekyll.

pixelastic avatar pixelastic commented on July 24, 2024

My mistake, I thought the url was saved, including the css_selector, in the record. As they are actually two different fields, you're right that you just have to update the link to target the page without the anchor. That will work.

To scroll the page to the correct part, you need a bit of custom JavaScript. You can have a look at how it was done on our Jekyll/Hyde demo. Basically we wait for page load, read the url, parse the anchor and scroll to the element matching the selector.

Regarding your other questions, feel free to post issues here (one thread per issue, to make tracking easier). If something is not clear enough, I'll update the documentation accordingly.

from algoliasearch-jekyll.

iloveip avatar iloveip commented on July 24, 2024

@pixelastic ok, thank you very much.

Actually, I already have this piece of code in my search.js file. (I copied the whole algolia.js file from Jekyll/Hyde demo.) But it's still not working for me.

from algoliasearch-jekyll.

pixelastic avatar pixelastic commented on July 24, 2024

Sorry to hear that it did not work for you. If you have a public url I can have a look and see what is not working.

But as I understand this issue you prefer having the results pointing to the top of the page anyway. I'll close this issue for now then, but feel free to comment back if you want to push it further.

from algoliasearch-jekyll.

iloveip avatar iloveip commented on July 24, 2024

Ok, thank you very much. I'll send you a link when I push it to GitHub.

from algoliasearch-jekyll.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.