Search and site-properties

I’m working on a global search, 4.7.10, and having to sites (site/0 and site/1).

In site-X.properties i have:
cms.site.url = http://cmsqa.sio.no/en

datasource:

      <datasource name="getContentByQuery">
    <parameter name="query">${ isempty(param.q) ? "a" : buildFreetextQuery("data/*", param.q, "AND" ) }</parameter>
    <parameter name="orderBy"/>
    <parameter name="index">${select(param.index, 0)}</parameter>
    <parameter name="count">20</parameter>
    <parameter name="includeData">true</parameter>
    <parameter name="childrenLevel">1</parameter>
    <parameter name="parentLevel">0</parameter>
  </datasource>

When I’m on site/0 and searching I get hits all over the place.
I want to restrict my global search to selected content archives, and only a few content types and/or languages.
How do I do that?

I also get "cmsga.sio.no/[undefined]: Not able to create link to site 1: No valid cms.site.url defined in site-1.properties.

What am I doing wrong?

1 Like
  • First of all - you should probably run a getContentByCategory query if you want to query a specific archive.
  • Second, you may add query parameters such as contenttype = xx and language = xx if you want to limit it further (see doc for specific index names)

When it comes to the second - are you trying to cross-link between sites? Optionally, this might be a problem related to the /en part of the site url.

Hi,

My example is not tested, I’m just writting it from the top of my mind. Use getContentByCategory to filter which content archive folders to look inside. Then add your param.q to the query-part, and add on the filtering for language with concat.

https://enonic.com/docs/4.7/content-data-sources.html#Contentdatasources-getContentByCategory

buildFreetextQuery with “AND” is a very strict search, try using “OR” instead.

The query for “language” you should double check in your content source that this is what the language setting is really stored as and change if needed.

<datasources>
  <datasource name="getContentByCategory">
    <parameter name="categoryKeys">100,101,102,103,104</parameter>
    <parameter name="levels">1</parameter>
    <parameter name="query">${ concat( "language = 'en' AND ( ", isempty(param.q) ? "a" : buildFreetextQuery("data/*", param.q, "OR" ) , " )" ) }</parameter>
    <parameter name="orderBy"></parameter>
    <parameter name="index">${select(param.index, 0)}</parameter>
    <parameter name="count">20</parameter>
    <parameter name="includeData">true</parameter>
    <parameter name="childrenLevel">1</parameter>
    <parameter name="parentLevel">0</parameter>
  </datasource>
</datasources>

The last issue I’ll let somebody else answer as I have hardly ever touched those settings. Perhaps remove the http and domain-part?

Anyways, hope this gets you a bit further with your global search.