1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8class Search_Index_TypeAnalysisDecorator extends Search_Index_AbstractIndexDecorator
9{
10	private $identifierClass;
11	private $numericClass;
12	private $mapping = [];
13
14	function __construct(Search_Index_Interface $index)
15	{
16		parent::__construct($index);
17		$this->identifierClass = get_class($index->getTypeFactory()->identifier(1));
18		$this->numericClass = get_class($index->getTypeFactory()->numeric(1));
19	}
20
21	function addDocument(array $document)
22	{
23		$new = array_diff_key($document, $this->mapping);
24		foreach ($new as $key => $value) {
25			$this->mapping[$key] = $value instanceof $this->identifierClass || $value instanceof $this->numericClass;
26		}
27		return $this->parent->addDocument($document);
28	}
29
30	function getIdentifierFields()
31	{
32		return array_keys(array_filter($this->mapping));
33	}
34
35	function getFieldCount()
36	{
37		return count(array_keys($this->mapping));
38	}
39}
40