From 1f4991d0576ec976cf2e2d90db943a00ea00bb97 Mon Sep 17 00:00:00 2001 From: Steve Preston Date: Tue, 11 Nov 2014 16:23:53 -0500 Subject: [PATCH 1/4] Added option check to ignore warnings when searching --- README.markdown | 3 ++- Services/Search/Sphinxsearch.php | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 29d7362..6f7f609 100644 --- a/README.markdown +++ b/README.markdown @@ -54,6 +54,7 @@ $indexesToSearch = array('Items'); $options = array( 'result_offset' => 0, 'result_limit' => 25, + 'ignore_warnings' => true, 'field_weights' => array( 'Name' => 2, 'SKU' => 3, @@ -65,7 +66,7 @@ $sphinxSearch->setFilter('disabled', array(1), true); $searchResults = $sphinxSearch->search('search query', $indexesToSearch, $options); ``` -This would again search `Items` for `search query`, but now it will only return up to the first 25 matches and weight the `Name` and `SKU` fields higher than normal. Note that in order to define a `result_offset` or a `result_limit`, you must explicitly define both values. Also, this search will use [the Extended query syntax](http://sphinxsearch.com/docs/current.html#extended-syntax), and exclude all results with a `disabled` attribute set to 1. +This would again search `Items` for `search query`, but now it will only return up to the first 25 matches and weight the `Name` and `SKU` fields higher than normal. Note that in order to define a `result_offset` or a `result_limit`, you must explicitly define both values. Also, this search will use [the Extended query syntax](http://sphinxsearch.com/docs/current.html#extended-syntax), and exclude all results with a `disabled` attribute set to 1. The ignore_warnings option is recommended if you plan on using the @@relaxed option, as it returns a warning when non-existent fields are referenced. diff --git a/Services/Search/Sphinxsearch.php b/Services/Search/Sphinxsearch.php index 7ba0354..557a0a3 100644 --- a/Services/Search/Sphinxsearch.php +++ b/Services/Search/Sphinxsearch.php @@ -176,7 +176,13 @@ public function search($query, array $indexes, array $options = array(), $escape * Perform the query. */ $results = $this->sphinx->query($query, $indexNames); - if( $results['status'] !== SEARCHD_OK ) + + /** + * If status is not ok and status is not ignored warning + * This is required for '@@relaxed' to work correctly since it returns a warning on non-existent fields + */ + if( $results['status'] !== SEARCHD_OK && + !($results['status'] == SEARCHD_WARNING && isset($options['ignore_warnings']) && $options['ignore_warnings']) ) throw new \RuntimeException(sprintf('Searching index "%s" for "%s" failed with error "%s".', $label, $query, $this->sphinx->getLastError())); return $results; From 1a71e735a481795b50ce27e07e466cabf46a5ae0 Mon Sep 17 00:00:00 2001 From: Steve Preston Date: Wed, 12 Nov 2014 09:41:25 -0500 Subject: [PATCH 2/4] Changed package info in composer.json --- composer.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 8fa3328..79e0d38 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,15 @@ { - "name": "search/sphinxsearch-bundle", + "name": "spreston/sphinxsearch-bundle", "type": "symfony-bundle", - "description": "Sphinx search bundle for Symfony 2", + "description": "Sphinx search bundle for Symfony 2. Forked from https://github.com/timewasted/Search-SphinxsearchBundle", "keywords": ["sphinx", "sphinxsearch", "symfony2"], - "homepage": "https://github.com/timewasted/Search-SphinxsearchBundle", + "homepage": "https://github.com/spreston/Search-SphinxsearchBundle", "license": "BSD-2-Clause", "authors": [ + { + "name": "Steve Preston", + "email": "spreston@bcgtrans.com" + }, { "name": "Ryan Rogers", "email": "ryan@timewasted.me" From 502c2a863ff21cde374a3517e583fb605ac7b865 Mon Sep 17 00:00:00 2001 From: Steve Preston Date: Wed, 12 Nov 2014 10:10:37 -0500 Subject: [PATCH 3/4] Fixed vendor dir --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 79e0d38..c0d1ee7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "spreston/sphinxsearch-bundle", + "name": "search/sphinxsearch-bundle", "type": "symfony-bundle", "description": "Sphinx search bundle for Symfony 2. Forked from https://github.com/timewasted/Search-SphinxsearchBundle", "keywords": ["sphinx", "sphinxsearch", "symfony2"], From 5a991a2f25b1dd7318ac58921e1bda47197a4399 Mon Sep 17 00:00:00 2001 From: Steve Preston Date: Wed, 12 Nov 2014 10:44:25 -0500 Subject: [PATCH 4/4] Fixed readme --- README.markdown | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 6f7f609..19e26de 100644 --- a/README.markdown +++ b/README.markdown @@ -1,8 +1,6 @@ About SphinxsearchBundle ======================== - - Installation: ------------- @@ -11,7 +9,19 @@ Installation: ### Step 1: Download the bundle -How you actually download the bundle is entirely up to you. The easiest way is to grab it from [packagist.org](http://packagist.org/). +How you actually download the bundle is entirely up to you. Since I'm not sure how much time I'll be able to spend maintaining this bundle, I've opted to keep it as a VCS bundle for now and not put it on packagist. This may change in the future if there is enough interest. The relevant portions of composer.json are: + +``` JSON + "repositories": [ + { + "type": "vcs", + "url": "git@github.com:spreston/Search-SphinxsearchBundle.git" + } + ], + "require": { + "search/sphinxsearch-bundle": "dev-master", + } +``` ### Step 2: Configure the bundle @@ -30,7 +40,7 @@ sphinxsearch: At least one index must be defined, and you may define as many as you like. -In the above sample configuration, `Categories` is used as a label for the index named `%sphinxsearch_index_categories%` (as defined in your `sphinxsearch.conf`). This allows you to avoid having to hard code raw index names inside of your code. +In the above sample configuration, `Categories` is used as a label for the index named `%sphinxsearch_index_categories%` (as defined in your `sphinxsearch.conf`). This allows you to avoid having to hard code raw index names inside of your configuration. @@ -74,7 +84,9 @@ License: -------- ``` -Copyright (c) 2012, Ryan Rogers +Copyright (c) + 2012, Ryan Rogers + 2014, Steve Preston All rights reserved. Redistribution and use in source and binary forms, with or without