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_Query_Facet_Term extends Search_Query_Facet_Abstract implements Search_Query_Facet_Interface
9{
10	private $operator = 'or';
11	private $count;
12	private $order;
13	private $min_doc_count;
14
15	static function fromField($field)
16	{
17		return new self($field);
18	}
19
20	function getCount()
21	{
22		return $this->count;
23	}
24
25	function setCount($count)
26	{
27		$this->count = $count;
28		return $this;
29	}
30
31	function setRenderMap(array $map)
32	{
33		return $this->setRenderCallback(
34			function ($value) use ($map) {
35				if (isset($map[$value])) {
36					return $map[$value];
37				} else {
38					return $value;
39				}
40			}
41		);
42	}
43
44	function getType()
45	{
46		return 'terms';
47	}
48
49	function setOperator($operator)
50	{
51		$this->operator = in_array($operator, ['and', 'or']) ? $operator : 'or';
52		return $this;
53	}
54
55	function getOperator()
56	{
57		return $this->operator;
58	}
59
60	/**
61	 * @return null|array [field => order]
62	 */
63	public function getOrder()
64	{
65		$order = null;
66
67		if ($this->order) {
68			$searchQueryOrder = \Search_Query_Order::parse($this->order);
69			$order = [$searchQueryOrder->getField() => $searchQueryOrder->getOrder()];
70		}
71
72		return $order;
73	}
74
75	/**
76	 * @param string $order
77	 *
78	 * @return $this
79	 */
80	public function setOrder($order)
81	{
82		$this->order = $order;
83		return $this;
84	}
85
86	/**
87	 * @return int
88	 */
89	public function getMinDocCount()
90	{
91		return $this->min_doc_count;
92	}
93
94	/**
95	 * @param int $min_doc_count
96	 *
97	 * @return Search_Query_Facet_Term
98	 */
99	public function setMinDocCount($min)
100	{
101		$this->min_doc_count = $min;
102		return $this;
103	}
104
105}
106