PageRenderTime 11ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/zf/library/Zend/Search/Lucene/Search/QueryEntry/Phrase.php

http://github.com/eryx/php-framework-benchmark
PHP | 116 lines | 35 code | 14 blank | 67 comment | 2 complexity | 89c8b340566b96c87d7b2482ca1b9229 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause
  1<?php
  2/**
  3 * Zend Framework
  4 *
  5 * LICENSE
  6 *
  7 * This source file is subject to the new BSD license that is bundled
  8 * with this package in the file LICENSE.txt.
  9 * It is also available through the world-wide-web at this URL:
 10 * http://framework.zend.com/license/new-bsd
 11 * If you did not receive a copy of the license and are unable to
 12 * obtain it through the world-wide-web, please send an email
 13 * to license@zend.com so we can send you a copy immediately.
 14 *
 15 * @category   Zend
 16 * @package    Zend_Search_Lucene
 17 * @subpackage Search
 18 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: Phrase.php 23775 2011-03-01 17:25:24Z ralph $
 21 */
 22
 23/** Zend_Search_Lucene_Search_QueryEntry */
 24require_once 'Zend/Search/Lucene/Search/QueryEntry.php';
 25
 26/**
 27 * @category   Zend
 28 * @package    Zend_Search_Lucene
 29 * @subpackage Search
 30 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 31 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 32 */
 33class Zend_Search_Lucene_Search_QueryEntry_Phrase extends Zend_Search_Lucene_Search_QueryEntry
 34{
 35    /**
 36     * Phrase value
 37     *
 38     * @var string
 39     */
 40    private $_phrase;
 41
 42    /**
 43     * Field
 44     *
 45     * @var string|null
 46     */
 47    private $_field;
 48
 49
 50    /**
 51     * Proximity phrase query
 52     *
 53     * @var boolean
 54     */
 55    private $_proximityQuery = false;
 56
 57    /**
 58     * Words distance, used for proximiti queries
 59     *
 60     * @var integer
 61     */
 62    private $_wordsDistance = 0;
 63
 64
 65    /**
 66     * Object constractor
 67     *
 68     * @param string $phrase
 69     * @param string $field
 70     */
 71    public function __construct($phrase, $field)
 72    {
 73        $this->_phrase = $phrase;
 74        $this->_field  = $field;
 75    }
 76
 77    /**
 78     * Process modifier ('~')
 79     *
 80     * @param mixed $parameter
 81     */
 82    public function processFuzzyProximityModifier($parameter = null)
 83    {
 84        $this->_proximityQuery = true;
 85
 86        if ($parameter !== null) {
 87            $this->_wordsDistance = $parameter;
 88        }
 89    }
 90
 91    /**
 92     * Transform entry to a subquery
 93     *
 94     * @param string $encoding
 95     * @return Zend_Search_Lucene_Search_Query
 96     * @throws Zend_Search_Lucene_Search_QueryParserException
 97     */
 98    public function getQuery($encoding)
 99    {
100        /** Zend_Search_Lucene_Search_Query_Preprocessing_Phrase */
101        require_once 'Zend/Search/Lucene/Search/Query/Preprocessing/Phrase.php';
102        $query = new Zend_Search_Lucene_Search_Query_Preprocessing_Phrase($this->_phrase,
103                                                                          $encoding,
104                                                                          ($this->_field !== null)?
105                                                                              iconv($encoding, 'UTF-8', $this->_field) :
106                                                                              null);
107
108        if ($this->_proximityQuery) {
109            $query->setSlop($this->_wordsDistance);
110        }
111
112        $query->setBoost($this->_boost);
113
114        return $query;
115    }
116}