全文搜索字段和原则2

时间:2022-10-22 18:45:21

We're using Doctrine 2 and have some fairly simple search requirements in which we'd normally set fulltext on a field. I've had a good google around and it seems there is no way to do this with Doctrine.

我们使用的是Doctrine 2,并且有一些相当简单的搜索需求,其中我们通常在字段上设置全文。我有一个很好的谷歌,似乎没有办法这么做的教义。

We're using Zend Framework 2 for this project and I wondered if anyone had any ideas of a good workaround?

我们在这个项目中使用Zend Framework 2,我想知道是否有人有好的解决方案?

I don't think using lots of LIKEs in the query would yeild fast enough search results, but I think at the same time using something like Solr or Elastic search would be way too overkill for searching just one field in a simple manner.

我不认为在查询中使用大量的like会有足够快的搜索结果,但我认为同时使用Solr或弹性搜索这样的东西对以简单的方式搜索一个字段来说太过了。

Any suggestions? I get the feeling we're going to have to hack something together. At the moment we're creating the database by running the orm:schema:create tool from the command line.

有什么建议吗?我觉得我们得一起搞点什么。目前,我们正在通过运行orm:schema:create工具从命令行创建数据库。

Any suggestions?

有什么建议吗?

1 个解决方案

#1


3  

Simply said, there is no solution if you stick with Doctrine2 and you don't want to use LIKE queries and you don't want to introduce a search engine.

简单地说,如果你坚持教条2,你不想使用查询,也不想引入搜索引擎,就没有解决方案。

Doctrine2 relies on InnoDB and InnoDB (currently) does not support fulltext. So focusing on fulltext or LIKE queries are no option I'd say. However, there is a much simpler way than using Solr or ElasticSearch, as they are both using Lucene as engine. You can create a Lucene index on your file system (within your project dir) and use ZendSearch for indexing and querying.

Doctrine2依赖于InnoDB,而InnoDB(目前)不支持全文。所以专注于全文或类似的查询是不可能的。然而,有一种比使用Solr或弹性搜索更简单的方法,因为它们都使用Lucene作为引擎。您可以在您的文件系统(在您的项目目录中)创建Lucene索引,并使用ZendSearch进行索引和查询。

Require zendframework/zendsearch via composer and do this for your search:

要求zendframework/zendsearch通过composer进行搜索,并为此进行搜索:

use ZendSearch\Lucene\Lucene;
use ZendSearch\Lucene\Document;
use ZendSearch\Lucene\Document\Field;

// this is relative to your project say /var/www/site/data/search
$dir = 'data/search';

// Create index
Lucene::create($dir);

// Insert a new document
$index = Lucene::open($dir);
$doc   = new Document;

$doc->addField(Field::keyword('foo', 'bar'));
$index->addDocument($doc);

// Search the index
$index  = Lucene::open($dir);
$result = $index->query('foo:bar');

echo count($result);

There is no need to install a binary on your server (like Solr and ElasticSearch) to support search. It's even faster than fulltext search, but you have to keep your index up2date of course to support proper search.

无需在服务器上安装二进制文件(如Solr和ElasticSearch)来支持搜索。它甚至比全文搜索还要快,但你当然要让你的索引保持最新,以支持适当的搜索。

#1


3  

Simply said, there is no solution if you stick with Doctrine2 and you don't want to use LIKE queries and you don't want to introduce a search engine.

简单地说,如果你坚持教条2,你不想使用查询,也不想引入搜索引擎,就没有解决方案。

Doctrine2 relies on InnoDB and InnoDB (currently) does not support fulltext. So focusing on fulltext or LIKE queries are no option I'd say. However, there is a much simpler way than using Solr or ElasticSearch, as they are both using Lucene as engine. You can create a Lucene index on your file system (within your project dir) and use ZendSearch for indexing and querying.

Doctrine2依赖于InnoDB,而InnoDB(目前)不支持全文。所以专注于全文或类似的查询是不可能的。然而,有一种比使用Solr或弹性搜索更简单的方法,因为它们都使用Lucene作为引擎。您可以在您的文件系统(在您的项目目录中)创建Lucene索引,并使用ZendSearch进行索引和查询。

Require zendframework/zendsearch via composer and do this for your search:

要求zendframework/zendsearch通过composer进行搜索,并为此进行搜索:

use ZendSearch\Lucene\Lucene;
use ZendSearch\Lucene\Document;
use ZendSearch\Lucene\Document\Field;

// this is relative to your project say /var/www/site/data/search
$dir = 'data/search';

// Create index
Lucene::create($dir);

// Insert a new document
$index = Lucene::open($dir);
$doc   = new Document;

$doc->addField(Field::keyword('foo', 'bar'));
$index->addDocument($doc);

// Search the index
$index  = Lucene::open($dir);
$result = $index->query('foo:bar');

echo count($result);

There is no need to install a binary on your server (like Solr and ElasticSearch) to support search. It's even faster than fulltext search, but you have to keep your index up2date of course to support proper search.

无需在服务器上安装二进制文件(如Solr和ElasticSearch)来支持搜索。它甚至比全文搜索还要快,但你当然要让你的索引保持最新,以支持适当的搜索。