Giving your page name more weight in the C5 site search

Permalink
Hi there,

Is there a way to give your page name more weight when it comes to the inbuilt C5 site search?

At the moment it seems to count content frequency in the page content more highly, and in fact does not highlight the page title at all in the search results (although I don't know if that means it is discounting it, or just not highlighting).

I read about including custom attributes in the search results - so I guess a way around this could be adding a meta title to each page, and then adding this attribute to be recognised by the search tool - but is there another way round this?

 
Mainio replied on at Permalink Reply
Mainio
In programming, I'd like to believe that "everything is possible" having been around engineers who always complain about technical limitations :)

But yes, this is quite simple problem. Concrete5 uses the MySQL's MATCH function to do the search index matching.

For MySQL related issues you very often find good answers from Stack Overflow:
http://stackoverflow.com/questions/547542/how-can-i-manipulate-mysq...

So I'm giving an example of the basic query search with the default sample content installation of c5.

The basic search query done against the page search index table is like this:
SELECT * FROM PageSearchIndex psi WHERE match(psi.cName, psi.cDescription, psi.content) against ("concrete5")


Of course the full version is a bit more complicated but this already does a) the content search b) the page name search which your issue is regarding to.

In the default c5 sample content installation this returns page names in this order (6 first results):
- Welcome to concrete5
- Home
- Extend concrete5
- About
- Get More Add-Ons
- Update concrete5

Now, if we want to make the page name "weight" more, the query should return the names first that contain "concrete5", right? I believe this is what you're aiming to do...

From the stack overflow thread you can find the guide on adding the relevance selectors to this query and sorting by them. So in your case you want to first order by the page name relevance. So let's modify the query above a bit:
-- modified
SELECT 
   MATCH(psi.cName)AGAINST ('concrete5') AS rel1,
   MATCH(psi.cDescription)AGAINST ('concrete5') AS rel2,
   MATCH(psi.content)AGAINST ('concrete5') AS rel2,
   psi.* FROM PageSearchIndex psi WHERE MATCH(psi.cName, psi.cDescription, psi.content) AGAINST ("concrete5")
   ORDER BY rel1 DESC


So this should sort the results by the page name relevance as the first criteria. Let's try what order this query returns for the page names (3 first results):
- Welcome to concrete5
- Extend concrete5
- Update concrete5

So looks like this did the trick.

Now the hard part: to apply this to the page search, you need to apply the above query to the page_list class you can find from /concrete/models/page_list.php

Hopefully this helps you out and can guide you to the direction you're aiming at!

Best,
Antti / Mainio