Creating Search-Entries
Search-Entries are added by the Indexer.
Add
The most basic way to create a SearchEntry is by doing:
Indexer::add(Url::create('http://n2n.rocks'), 'Titel', $n2nLocale, 'searchableText', 'keyword1 keyword2', 'description', array(), 'groupkey')
This method is the most unattractive because you need to define the most things by yourself. It is very circumstantial.
Add By Html
Indexer::addByHtml() by using this the Indexer finds out:
- title, description, keywords by Meta-Tags defined in the searchableHtml and
- searchableText by looking at the content between HTML-Tags.
Indexer::addByHtml(Url::create('https://n2n.rocks/'), $searchableHtml, N2nLocale n2nLocale, array());
This method is still circumstantial but easier than a usual add.
Add By HtmlView
One of the easiest ways to add a SearchEntry is by calling this method:
Indexer::addFromHtmlView($htmlView, array('hello', 'bye'));
The Indexer will read url, n2nlocale, title, description and keywords from the HtmlView.
Here is an example how this would look in a controller:
public function index() { $this->beginTransaction(); $htmlView = $this->createView('..\view\home.html'); $this->indexer->addFromHtmlView($htmlView, array()); $this->forwardView($htmlView); }
Add by Response
Another easy way to add a SearchEntry is to use the Indexer::addByResponse() method.
This has to happen after ControllerAdapter::forward() has been called.
public function index() { $this->beginTransaction(); $this->forward('..\view\home.html'); $this->indexer->addFromResponse($this->getResponse()); }