-
Notifications
You must be signed in to change notification settings - Fork 1
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
Problem with large pages #1
Comments
Hello @yhoiseth ! I'm Tom and I work at Algolia, I used to work on laravel integration, we have a This is our documentation for our splitter : https://www.algolia.com/doc/framework-integration/laravel/advanced-use-cases/split-large-records/?language=php And this is the repo of our laravel integration : https://github.com/algolia/scout-extended Cheers |
That's great, I really appreciate it ❤ Let me know if you need to talk things through or something. (Just be aware that I wouldn't consider myself a Django expert 😉) |
For now, we have worked around this issue by making a similar solution using Elasticsearch and Bootstrap Autocomplete. I'm sharing how to achieve it here in case anyone else runs into a similar problem. Caveats and prerequisites
DemoSee the search box in the navbar on https://www.entrepedia.com/. HowSet up ElasticsearchSee Backends — Wagtail Documentation. (The other backends don't work as well because they don't return results until words are almost written out. Elasticsearch can return results when the query is as little as one character.) Set up search endpointWhen you start a Wagtail project, it sets up a default search endpoint. In order to make it work with Bootstrap Autocomplete, you need to change Next, you need to return the search results as JSON if the autocomplete is doing the searching. There are many ways to do this. A slightly ugly but functional way is to add the following guard above the existing from json import dumps
from django.http import HttpResponse
# …
if request.is_ajax():
data = []
for hit in search_results:
data.append({"url": hit.url, "text": hit.title})
return HttpResponse(dumps(data), content_type="application/json") Set up frontendFor the frontend, we need a search field and some JavaScript. These are the relevant parts: <input
aria-label="Search"
autocomplete="off"
class="form-control"
id="search-input"
name="q"
type="search"
>
<script
src="https://cdn.jsdelivr.net/gh/xcash/[email protected]/dist/latest/bootstrap-autocomplete.min.js"
></script>
<script>
$(document).ready(function () {
var $searchInput = $("#search-input");
$searchInput.autoComplete({
minLength: 1,
resolverSettings: {
url: "{% url "search" %}"
}
});
$searchInput.on("autocomplete.select", function (event, item) {
window.location.pathname = item.url;
});
$searchInput.on("keydown", function (event) {
if (event.keyCode === 13) {
return false; // Do not submit form on ENTER
}
});
});
</script> |
Hi @KalobTaulien, Just a heads-up in case you didn't notice this 🙂 TLDR: You might want to add some info about the size limit to your blog post as a courtesy to readers. |
Hi,
Thanks a lot for sharing. I encountered an issue that I suspect others will encounter, too.
Algolia has—at least to me—surprisingly small limits on record sizes:
It appears that for Enterprise accounts, you can have larger limits.
In practice, this means that if you e.g. have a page with a
body
,title
,search_description
, etc. of more than 10 000 characters put together (which is quite common), you'll encounter an error when indexing.Algolia's official solution to this problem is splitting records, e.g. by paragraph.
I inquired with Algolia's support team how to do this with the Django integration. They answered that they don't think it's possible.
My assessment is that, in order to index large pages in Wagtail/Django, we would need to split records and build the index using Algolia's generic Python client. That, however, seems like a hack and more trouble than it's worth to us. (I'd be very interested in knowing if anyone has done this or has found a different solution.)
Also, regarding the blog post Using Algolia Search with Wagtail, I think it would be useful to add a warning about Algolia's record size limits. With such a warning, I probably wouldn't have spent any time trying to implement Algolia. It could, for example, say something like:
The text was updated successfully, but these errors were encountered: