source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/library/Solarium/Query/Update/Command/Add.php @ 7576

Revision 7576, 4.6 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

Line 
1<?php
2/**
3 * Copyright 2011 Bas de Nooijer. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 *    this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 *    this listof conditions and the following disclaimer in the documentation
13 *    and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 * The views and conclusions contained in the software and documentation are
28 * those of the authors and should not be interpreted as representing official
29 * policies, either expressed or implied, of the copyright holder.
30 *
31 * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
32 * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
33 * @link http://www.solarium-project.org/
34 *
35 * @package Solarium
36 * @subpackage Query
37 */
38
39/**
40 * Update query add command
41 *
42 * For details about the Solr options see:
43 * @link http://wiki.apache.org/solr/UpdateXmlMessages#add.2BAC8-update
44 *
45 * @package Solarium
46 * @subpackage Query
47 */
48class Solarium_Query_Update_Command_Add extends Solarium_Query_Update_Command
49{
50
51    /**
52     * Documents to add
53     *
54     * @var array
55     */
56    protected $_documents = array();
57
58    /**
59     * Get command type
60     *
61     * @return string
62     */
63    public function getType()
64    {
65        return Solarium_Query_Update::COMMAND_ADD;
66    }
67
68    /**
69     * Add a single document
70     *
71     * @param object $document
72     * @return Solarium_Query_Update_Command_Add Provides fluent interface
73     */
74    public function addDocument($document)
75    {
76        $this->_documents[] = $document;
77
78        return $this;
79    }
80
81    /**
82     * Add multiple documents
83     *
84     * @param array|Traversable $documents
85     * @return Solarium_Query_Update_Command_Add Provides fluent interface
86     */
87    public function addDocuments($documents)
88    {
89        //if we don't have documents so far, accept arrays or Traversable objects as-is
90        if (empty($this->_documents)) {
91            $this->_documents = $documents;
92            return $this;
93        }
94
95        //if something Traversable is passed in, and there are existing documents, convert all to arrays before merging
96        if ($documents instanceof Traversable) {
97            $documents = iterator_to_array($documents);
98        }
99        if ($this->_documents instanceof Traversable) {
100            $this->_documents = array_merge(iterator_to_array($this->_documents), $documents);
101        } else {
102            $this->_documents = array_merge($this->_documents, $documents);
103        }
104
105        return $this;
106    }
107
108    /**
109     * Get all documents
110     *
111     * @return array
112     */
113    public function getDocuments()
114    {
115        return $this->_documents;
116    }
117
118    /**
119     * Set overwrite option
120     *
121     * @param boolean $overwrite
122     * @return Solarium_Query_Update_Command_Add Provides fluent interface
123     */
124    public function setOverwrite($overwrite)
125    {
126        return $this->_setOption('overwrite', $overwrite);
127    }
128
129    /**
130     * Get overwrite option
131     *
132     * @return boolean
133     */
134    public function getOverwrite()
135    {
136        return $this->getOption('overwrite');
137    }
138
139    /**
140     * Get commitWithin option
141     *
142     * @param boolean $commitWithin
143     * @return Solarium_Query_Update_Command_Add Provides fluent interface
144     */
145    public function setCommitWithin($commitWithin)
146    {
147        return $this->_setOption('commitwithin', $commitWithin);
148    }
149
150    /**
151     * Set commitWithin option
152     *
153     * @return boolean
154     */
155    public function getCommitWithin()
156    {
157        return $this->getOption('commitwithin');
158    }
159}
Note: See TracBrowser for help on using the repository browser.