pagefind icon indicating copy to clipboard operation
pagefind copied to clipboard

Can not find pages with exact match in the title

Open groteck opened this issue 11 months ago • 3 comments

Hi, first thanks for the project.

We are integrating pagefind and we have like 12 thousand products and every product has a page, for trademark reasons like 8 thousand products have company name as part of their title (an h1 tag) and we find that searching by the company name doesn't return any results or only results like Company-something else.

Using the playground we get much many results but not sure about why or how to translate that to the pagefind js and why the results are different. I understand that maybe pagefind was not tested under this exact conditions.

Options:

  1. We index the pages removing spaces 😄 , this can be an option we add hidden html tags with pagefind specific content so whit that maybe We can create an "artificial" list of results.
  2. Maybe there is a way to debug better since the playground have a different set of results (maybe because is not react base or something astro related).
  3. Maybe the issue https://github.com/CloudCannon/pagefind/issues/795 is related and the fix will also help us?

groteck avatar Apr 16 '25 16:04 groteck

👋 heya @groteck

Hmm, there shouldn't be a difference between the playground versus actual usage. The core search that sits beneath each is the same.

The linked issues might be related, I need to catch up and tackle that one. Otherwise, if you have any sample you can share that reproduces the issue I can take a closer look.

bglw avatar Apr 28 '25 06:04 bglw

Hi @groteck did you manage to find a solution for this?

I'm trying to integrate PageFind for an Astro site using astro-pagefind (astro-pagefind repo).

What I encountered is that when it comes to showing the search results, even though I search for the exact title in the <h1> header of a page, it doesn't get shown in the search results. But if I search for a text in a <h2> tag on the same page, it shows up in the search result, and the title of the search result is the text of the previous <h1> tag.

My suspicion is that something is wrong with the default weights added to header tags. A related issue is Weights ignored? · Issue #729 · Pagefind/pagefind

Povindu avatar Jun 05 '25 13:06 Povindu

Hey :)
 I am working with @groteck on the same project. 
The search page became more complicated since I implemented many workarounds to make the search work for us. The search is done in a form where a user inputs his search term and clicks on a search button. This will trigger a onSubmit() function that will call the search() function from pagefind. There are other places in the project where a search is performed while typing in an input field(using debouncedSearch()).

After a lot of try and error I found a couple of stuff:

  • I think pagefind search was thought to be used to search while typing (onChange) where every character is preloaded before the search (using the debouncedSearch) debouncedSearch preloading-search-terms . Searching a search term all at once will not work well and most of the time will give empty results. For example searching in an onSubmit() function using the search() function from pagefind where the hole search term is given to the search() function.

  • Pasting a search term in an input field will not work very well even if the search was done in an onChange() function. To make pasting work I implemented an onPaste function for the input field.

 function handlePaste(event: React.ClipboardEvent<HTMLInputElement>) {
     const searchQuery = event.clipboardData.getData('text');
     let searchQueryChars = '';
     for (let char of searchQuery) {
         searchQueryChars += char;
         window.pagefind.preload(searchQueryChars);
     }
 }
  • The search() function does not work as expected. The search() function should use preload under the hood to preload every character in the search term just like in the handlePaste function above (proposal).

  • Searching for a search term using debounce search in an onChange() function (I mean while typing) gives accurate results unless the search term was pasted in the input field then the search will most likely give and empty result. Calling the handlePaste() function onPaste() in the input field will solve the issue.

Please feel free to ask if you didn't understand something in my comment :)

YoussefNassar avatar Sep 01 '25 11:09 YoussefNassar