Skip to content

Commit

Permalink
closes #23 - ability to mark a field as not_analyzed
Browse files Browse the repository at this point in the history
  • Loading branch information
parisholley committed Jul 25, 2013
1 parent 1e26bf7 commit bbcf83c
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs
6 changes: 6 additions & 0 deletions src/elasticsearch/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ static function addOrUpdate($post){
**/
static function _map(){
$numeric = Config::option('numeric');
$notanalyzed = Config::option('not_analyzed');

$index = self::_index(false);

foreach(Config::fields() as $field){
Expand All @@ -133,6 +135,10 @@ static function _map(){
}elseif($field == 'post_date'){
$props['type'] = 'date';
$props['format'] = 'date_time_no_millis';
}elseif(isset($notanalyzed[$field])){
$props['index'] = 'not_analyzed';
}else{
$props['index'] = 'analyzed';
}

foreach(Config::types() as $type){
Expand Down
59 changes: 59 additions & 0 deletions tests/integration-tests/elasticsearch/SearcherIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,65 @@ public function testSearchTaxonomiesMultisite()
$this->assertEquals(array('tag' => array('tag1' => 1)), $results['facets']);
}

public function testAnalyzed()
{
update_option('fields', array('field1' => 1));
update_option('score_field_field1', 1);

register_post_type('post');

Indexer::clear();

Indexer::addOrUpdate((object) array(
'post_type' => 'post',
'ID' => 1,
'post_date' => '10/24/1988 00:00:00 CST',
'field1' => 'foo bar'
));

$this->index->refresh();

$results = $this->searcher->search('foo');

$this->assertEquals(1, $results['total']);
$this->assertEquals(array(1), $results['ids']);

$results = $this->searcher->search('foo bar');

$this->assertEquals(1, $results['total']);
$this->assertEquals(array(1), $results['ids']);
}

public function testNotAnalyzed()
{
update_option('fields', array('field1' => 1));
update_option('not_analyzed', array('field1' => 1));
update_option('score_field_field1', 1);

register_post_type('post');

Indexer::clear();

Indexer::addOrUpdate((object) array(
'post_type' => 'post',
'ID' => 1,
'post_date' => '10/24/1988 00:00:00 CST',
'field1' => 'foo bar'
));

$this->index->refresh();

$results = $this->searcher->search('foo');

$this->assertEquals(0, $results['total']);
$this->assertEquals(array(), $results['ids']);

$results = $this->searcher->search('foo bar');

$this->assertEquals(1, $results['total']);
$this->assertEquals(array(1), $results['ids']);
}

public function testScoreSort()
{
update_option('fields', array('field1' => 1, 'field2' => 1));
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit660b9e9229a95330d8e0ed341d86fc94::getLoader();
return ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b::getLoader();
6 changes: 3 additions & 3 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php generated by Composer

class ComposerAutoloaderInit660b9e9229a95330d8e0ed341d86fc94
class ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b
{
private static $loader;

Expand All @@ -19,9 +19,9 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit660b9e9229a95330d8e0ed341d86fc94', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit660b9e9229a95330d8e0ed341d86fc94', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit2f7f268913eec9074616a6dfab64738b', 'loadClassLoader'));

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
Expand Down
11 changes: 10 additions & 1 deletion wp/admin/sections/field-mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@
'type' => 'multi_checkbox',
'title' => 'Numeric Fields',
'desc' => 'Any field marked as "numeric" will enabled support for range faceting.'
),
'not_analyzed' => array(
'id' => 'not_analyzed',
'type' => 'multi_checkbox',
'title' => 'Non Analyzed Fields',
'desc' => 'Any string field marked as "non analyzed" will require search terms to match the entire value instead of any words in the value.'
)
);

foreach(Config::fields() as $field){
$fields['numeric']['options'][$field] = $field;
if($field != 'post_date'){
$fields['numeric']['options'][$field] = $field;
$fields['not_analyzed']['options'][$field] = $field;
}
}

$numeric_option = Config::option('numeric');
Expand Down

0 comments on commit bbcf83c

Please sign in to comment.