Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
fix multiple find
Browse files Browse the repository at this point in the history
  • Loading branch information
himiklab committed May 18, 2019
1 parent 1ca5d1e commit 18c181b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function behaviors()
['name' => 'title', 'value' => $model->title],
['name' => 'body', 'value' => strip_tags($model->body)],
['name' => 'url', 'value' => $model->url, 'type' => SearchBehavior::FIELD_KEYWORD],
// ['name' => 'model', 'value' => 'page', 'type' => SearchBehavior::FIELD_UNSTORED],
['name' => 'model', 'value' => 'page', 'type' => SearchBehavior::FIELD_UNSTORED],
];
}
],
Expand Down
15 changes: 8 additions & 7 deletions src/Search.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @link https://github.com/himiklab/yii2-search-component-v2
* @copyright Copyright (c) 2014-2017 HimikLab
* @copyright Copyright (c) 2014-2019 HimikLab
* @license http://opensource.org/licenses/MIT MIT
*/

Expand All @@ -13,22 +13,22 @@
use yii\helpers\FileHelper;
use ZendSearch\Lucene\Analysis\Analyzer\Analyzer;
use ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8;
use ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8Num;
use ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8\CaseInsensitive;
use ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8Num;
use ZendSearch\Lucene\Analysis\Analyzer\Common\Utf8Num\CaseInsensitive as CaseInsensitiveNum;
use ZendSearch\Lucene\Document;
use ZendSearch\Lucene\Document\Field;
use ZendSearch\Lucene\Index\Term as IndexTerm;
use ZendSearch\Lucene\Lucene;
use ZendSearch\Lucene\Search\Query\MultiTerm;
use ZendSearch\Lucene\Search\Query\Boolean as QueryBoolean;
use ZendSearch\Lucene\Search\Query\Term;
use ZendSearch\Lucene\Search\Query\Wildcard;
use ZendSearch\Lucene\Search\QueryParser;

/**
* Yii2 Zend Lucine search component v2.
*
* @see http://framework.zend.com/manual/1.12/en/zend.search.lucene.html
* @see https://framework.zend.com/manual/1.12/en/zend.search.lucene.html
* @author HimikLab
* @package himiklab\yii2\search
*/
Expand Down Expand Up @@ -120,12 +120,13 @@ public function find($term, $fields = [])
];
}

$fieldTerms[] = new IndexTerm($term);
$query = new QueryBoolean();
$query->addSubquery(QueryParser::parse($term), true);
foreach ($fields as $field => $fieldText) {
$fieldTerms[] = new IndexTerm($fieldText, $field);
$query->addSubquery(new Term(new IndexTerm($fieldText, $field)), true);
}
return [
'results' => $this->luceneIndex->find(new MultiTerm($fieldTerms)),
'results' => $this->luceneIndex->find($query),
'query' => $term
];
}
Expand Down

0 comments on commit 18c181b

Please sign in to comment.