PageNotFound in Search

Hello everyone,

I have a issue with the result of the search query in the Experience Manager.
The search query returns all content as per the search term but for document(s) not in use it returns a /pagenotfound. Is there a way that unused documents can be excluded using the search? since the component class for search is EssentialsSearchComponent, I can only control how the search query is rendered in the search-main.ftl.

Would really appreciate some advice on this. Thanking you in advance.

Hi Annej,

Even though it is possible to extend EssentialsSearchComponent if required, I am not sure if it is possible to exclude documents which aren’t in use via HST Search API query.

We have had a similar situation in our project and have implemented the following logic (in our freemarker template) to skip rendering documents which are ended up with /pagenotfound:

<@hst.link var="pageNotFoundURL" siteMapItemRefId="pagenotfound"/>
<#if pageURL != pageNotFoundURL>
  ...
</#if>

Thanks!

Cheers,
Selva

Hello Selva,

Thank you so much for your reply. Appreciate it. This did help to me to not display the links with a ‘pagenotfound’,

<@hst.link var=“link” hippobean=item />
<#if !link?contains("/pagenotfound")>

</#if>

however, my total search results still shows the links with pagenotfound as part of the result though they appear as a blank line. I am using pageable to display the number of results, as shown below.

Showing ${pageable.startOffset +1 } to ${pageable.endOffset} of ${pageable.total} results for search term '${query?html}'

I would like to see the result as 3 out of 5 (2 being the links with a pagenotfound) . As of now I am seeing 5 out of 5. Any advices on that?

Hi Annej,

I think you will need to count the number of pagenotfound links and then deduct it from ${pageable.total} (as well as from ${pageable.endOffset}). Not sure if there is a better solution to it. Thanks!

Cheers,
Selva

Hi Selva,

Thank you for that advice. Using the count did help display the correct numbers but I’m having a pagination issue for search on a search term that exist in the documents created but not in use. Maybe the best solution would be to create classes that will extend the EssentialsSearchComponent.

Many thanks,
Annej

Hi Annej,

org.onehippo.cms7.essentials.components.EssentialsSearchComponent seem to have been extended from org.onehippo.cms7.essentials.components.EssentialsListComponent which essentially seems to construct the query using org.hippoecm.hst.content.beans.query.builder.HstQueryBuilder. So, yes, extending org.onehippo.cms7.essentials.components.EssentialsSearchComponent and update the query in such a way so that it excludes unused documents would be ideal. But, the query may be complicated to construct as page components and sitemaps are placed under workspace (hst:workspace) whereas documents would be sitting under /content/documents, so some sort of a join query needs to be constructed here. Thanks!

Cheers,
Selva