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_Expr_ImplicitPhrase implements Search_Expr_Interface
9{
10	private $parts;
11	private $weight = 1.0;
12
13	function __construct(array $parts)
14	{
15		$this->parts = $parts;
16	}
17
18	function __clone()
19	{
20		$this->parts = array_map(function ($part) {
21			return clone $part;
22		}, $this->parts);
23	}
24
25	function addPart(Search_Expr_Interface $part)
26	{
27		$this->parts[] = $part;
28	}
29
30	function setType($type)
31	{
32		foreach ($this->parts as $part) {
33			$part->setType($type);
34		}
35	}
36
37	function setField($field = 'global')
38	{
39		foreach ($this->parts as $part) {
40			$part->setField($field);
41		}
42	}
43
44	function setWeight($weight)
45	{
46		$this->weight = (float) $weight;
47	}
48
49	function getWeight()
50	{
51		return $this->weight;
52	}
53
54	function getBasicOperator()
55	{
56		global $prefs;
57		if ($prefs['unified_lucene_default_operator'] == 1) {
58			return new Search_Expr_And($this->parts);
59		} else {
60			return new Search_Expr_Or($this->parts);
61		}
62	}
63
64	function walk($callback)
65	{
66		$results = [];
67		foreach ($this->parts as $part) {
68			$results[] = $part->walk($callback);
69		}
70
71		return call_user_func($callback, $this, $results);
72	}
73
74	function traverse($callback)
75	{
76		return call_user_func($callback, $callback, $this, $this->parts);
77	}
78}
79