Search

Simple search using a match _all query

@param string $term

@return ElasticquentResultCollection
11710
public static function search($term = '')
    {
        $instance = new static;

        $params = $instance->getBasicEsParams();

        $params['body']['query']['match']['_all'] = $term;

        $result = $instance->getElasticSearchClient()->search($params);

        return static::hydrateElasticsearchResult($result);
    }
80631
public function get($term = null, $limit = null, $offset = 0)
    {
        if (false === $this->has_table()) return false;

        $term = $this->normalize_term($term);

        $this->db->where($term);

        $limit !== null || $limit = $this->data_limit;

        // Limit the result if $limit is int and greater than 0
        if (false !== $limit and is_int($limit) and $limit > 0) {
            // Forget about offset for now :P
            $this->db->limit($limit, $offset);
        }

        if ( ! $data = $this->db->get($this->table)) {
            $this->set_error($this->db->error());
            return false;
        }

        return 1 === $limit ? $data->row() : $data->result();
    }
755238
public function setTerm(\Neobazaar\Entity\Term $term = null)
    {
        $this->term = $term;
    
        return $this;
    }
878434
public function search($term, $limit, $offset, $orderBy = null)
    {
        $qb = $this->createQueryBuilder('m');

        $qb->where('m.name LIKE :term')
            ->andWhere('m.status IN (:statuses)')
            ->setParameters(array(
                'term' => '%'.$term.'%',
                'statuses' => array(0, 1),
            )
        );

        if ($limit) {
            $qb->setMaxResults($limit);
        }

        if ($offset) {
            $qb->setFirstResult($offset);
        }

        return $qb->getQuery()->getResult();
    }
344246
public function search(string $term, int $limit = null, array $filters = [])
    {
        $filters_array = [];

        if ($filters) {
            $filters_array = [
                'filters' => $this->resolveFilters(__FUNCTION__, $filters),
            ];
        }

        $data = [
            'term' => $term,
            'limit' => $limit,
            'filters' => $filters,
        ];

        $data = array_merge($data, $filters_array);

        $url = self::$base_url.'/search?'.http_build_query($data);

        return self::$curl->get($url);
    }
350533
protected function getTags($term)
    {
        $items = [];
        foreach ($this->getOptions() as $i => $tag) {
            /** @var ArrayData $tag */
            $tagValue = $tag->Value;
            // Map into a distinct list (prevent duplicates)
            if (stripos($tagValue, $term) !== false && !array_key_exists($tagValue, $items)) {
                $items[$tagValue] = [
                    'id' => $tag->Title,
                    'text' => $tag->Value,
                ];
            }
        }
        // @todo do we actually need lazy loading limits for StringTagField?
        return array_slice(array_values($items), 0, $this->getLazyLoadItemLimit());
    }
278462
public function addTerm(Term $term)
    {
        $term->addContentItem($this);
        $this->terms->add($term);

        return $this;
    }
682386
public function makeSearch($term)
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('User', 'read')) {
            return $this->noPermission();
        }

        $orderBy = (isset($_GET['order'])) ? $orderBy = $_GET['order'] : 'userID';
        $orderType = (isset($_GET['type'])) ? $orderType = $_GET['type'] : 'DESC';

        // join parameters for the query
        // we are left joinin the the media table
        $joins = array(
          [
            'table' => 'media',
            'type' => 'left',
            'whereTable1' => "profileImageID",
            'whereTable2' => "mediaID",
          ]
        );

        $excludeColumns = array('remember_token', 'created_at', 'updated_at');
        return Search::searchByTerm('users', $term, 1, true, array(), $excludeColumns, $orderBy, $orderType, $joins);
    }
1319685
public function suggest($term) {
  $query = new \Peyote\Select('tag_list');
  $query->columns('name')
        ->where('name', 'LIKE', '%'.$term.'%')
        ->limit(10);
  $results = $this->db->fetch($query);
  foreach ($results as $r) {
   $return[] = stripslashes($r['name']);
  }
  return $return;
 }
1198633
public function getSuggestions($term, $pageID, $limit = 5, $approved = true) {

		// Make sure the search matches the minimum autocomplete length.

		if($term && (strlen($term) > 2)) {

			// Make sure the current user has appropriate permission.

			$pageID = (int)$pageID;
			if(($page = ExtensibleSearchPage::get_by_id(ExtensibleSearchPage::class, $pageID)) && $page->canView()) {

				// Retrieve the search suggestions.

				$suggestions = ExtensibleSearchSuggestion::get()->filter(array(
					'Term:StartsWith' => $term,
					'Approved' => (int)$approved,
					'ExtensibleSearchPageID' => $pageID
				))->sort('Frequency', 'DESC')->limit($limit);

				// Make sure the search suggestions are unique.

				return $suggestions->column('Term');
			}
		}
		return array();
	}
376577
private function getSingleTerm($term)
    {
        // we don't modify numbers
        if (ctype_digit($term)) {
            return '"'.$term.'"';
        }

        // formatted number?
        $formatted = str_replace(
            [
                '-',
                '.'
            ],
            '',
            $term
        );
        if (ctype_digit($formatted)) {
            return '"'.$term.'"';
        }

        // everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard
        // thanks to https://stackoverflow.com/a/7684859/3762521
        $pattern = '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/';
        if (strlen($term) > 3 && preg_match($pattern, $term, $matches) === 1) {
            return '"'.$term.'"';
        }

        // is it a solr field query (like id:333)?
        if (preg_match($this->fieldQueryPattern, $term) === 1) {
            return $this->parseSolrFieldQuery($term);
        }

        // strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy
        if (strlen($term) >= $this->solrFuzzyBridge) {
            return $this->doAndNotPrefixSingleTerm($term, '~');
        }

        if (strlen($term) >= $this->solrWildcardBridge) {
            return $this->doAndNotPrefixSingleTerm($term, '*');
        }

        return $term;
    }
522565
public function filter_by_term($term) {
        $this->where[] = sprintf("(%s = :filterterma OR %s = :filtertermb)",
            self::resolve_field('concept', 'entries'),
            self::resolve_field('alias', 'alias'));
        $this->params['filterterma'] = $term;
        $this->params['filtertermb'] = $term;
    }
1020884
public function getTerms($taxonomy = null)
    {
        if ($taxonomy) {
            return (array_key_exists($taxonomy, $this->_terms))
                ? $this->_terms[$taxonomy]
                : array();
        }

        return $this->_terms;
    }
242495
public static function sortTerms($terms)
    {
        $sort_terms = array();
        foreach ($terms as $term) {
            $sort_terms[$term->name] = $term;
        }
        uksort($sort_terms, 'strnatcmp');

        return $sort_terms;
    }
1189953
public function searchRegion($region, $term, $params = array())
    {
        return $this->search($term, array_merge(array('country' => strtoupper($region)), $params));
    }
404860
public function search($term, $params = array())
    {
        $params = $this->getSearchParams($term, $params);
        $cacheKey = $this->cacheKey('search', $params);
        $cacheDuration = $this->iTunesConfig['cache'];

        if ($this->cache->has($cacheKey)) {
            return $this->cache->get($cacheKey);
        } else {
            return $this->cache->remember($cacheKey, $cacheDuration, function () use($term, $params) {
                return json_encode(parent::search($term, $params));
            });
        }
    }
581661
protected function getOrCreateTag($term)
    {
        // Check if existing record can be found
        $source = $this->getSourceList();
        $titleField = $this->getTitleField();
        $record = $source
            ->filter($titleField, $term)
            ->first();
        if ($record) {
            return $record;
        }

        // Create new instance if not yet saved
        if ($this->getCanCreate()) {
            $dataClass = $source->dataClass();
            $record = Injector::inst()->create($dataClass);
            $record->{$titleField} = $term;
            $record->write();
            if ($source instanceof SS_List) {
                $source->add($record);
            }
            return $record;
        }

        return false;
    }