Searchable HTML

Search Module Html

Here we learn how the Indexer scans through html for searchable text.

  1. Title, Description and Keywords
  2. Text that is classified as searchable

Title, Description and Keywords

The title can be determined by the title Tag.
The description and Keywords can be determined by Meta-Tags.

<head>
    <title>n2n Rocks!!!</title>
    <meta name="keywords" content="Best, Framework, Fast, Flexible">
    <meta name="description" content="n2n rocks because it is the best framework. It is fast and flexible">
</head>

These Tags are read in the Index::addFromHtml()Index::addByHtmlView() and Index::addByResponse() methods.
All of these methods take the parameters autoTitle, autoKeywords and autoDescription which are used as flags.
If set to false then you can set these attributes using the usual setter methods like so

$searchEntry = $indexer->addFromHtmlView($htmlView, array('hello', 'bye'), null, false, false, false);
$searchEntry->setTitle('n2n Rocks!!!');
$searchEntry->setDescription('n2n rocks because it is the best framework. It is fast and flexible');
$searchEntry->setKeywordsStr('Best, Framework, Fast,Flexible')

 

Text that is classified as searchable

By default the Indexer classifies every text that is not part of a HTML-Tag as searchable.
<head>
    <title>searchable text</title>
    <script>searchable text</script>
</head>
<body>
    <nav>searchable text</nav>   
    <div>      
        <p>searchable text</p>      
        <p>searchable text</p>   
    </div>
    <p>searchable text</p>
</body>

To exclude content from being searchable you must use the data-search attribute with the value being either "included" or "excluded".
The following example shows you how you can do this.

<head data-search="excluded">
    <title data-search="included">searchable text</title>
    <script>unsearchable text</script>
</head>
<body>
    <nav data-search="excluded">unsearchable text</nav>   
    <div>      
        <p>searchable text</p>      
        <p>searchable text</p>   
    </div>
    <p>searchable text</p>
</body>

Content that is between a HTML-Tag with data-search="excluded" will not be searchable if it is not followed by a data-search="included"

« Creating Search-Entries Cleaning up Search Entries »

Kommentare

Du musst eingeloggt sein, damit du Beiträge erstellen kannst.

Fragen