【问题标题】:Match whole field in Lucene在 Lucene 中匹配整个字段
【发布时间】:2009-08-25 13:46:03
【问题描述】:

我目前正在使用 lucene 索引数据库。我正在考虑将表 ID 存储在索引中,但我找不到按该字段检索文档的方法。我想一些伪代码会进一步澄清这个问题:

document.add("_id", 7, Field.Index.UN_TOKENIZED, Field.Store.YES);
// How can I query the document with _id=7
// without getting the document with _id=17 or _id=71?

【问题讨论】:

  • 您使用的是哪个版本的 Lucene API?您使用的是哪种方法(从 Lucene 2.4 开始,Document.add() 采用 Fieldable)?
  • 我实际上使用的是 php 端口(由 Zend 提供),但不知道这可能会有所不同,因为查询语法应该相同。
  • 查询语法不同。原则依旧。作为 php 的移植,Zend 目前支持 Lucene 2.3,比当前的 Java Lucene 版本大约落后两个版本。
  • 好的,非常感谢,我不知道。

标签: php zend-framework lucene


【解决方案1】:

Zend Lucene 的编辑: 您将需要一个关键字类型字段才能对其进行搜索。 对于索引,请使用以下内容:

$doc->addField(Zend_Search_Lucene_Field::Keyword('_id', '7'));

对于搜索,使用:

$idTerm  = new Zend_Search_Lucene_Index_Term('_id', '7');
$idQuery = new Zend_Search_Lucene_Search_Query_Term($idTerm);

【讨论】:

    【解决方案2】:

    只是说我刚刚在我的 Zend Lucene 搜索引擎上成功实现了这一点。但是,经过一段时间的故障排除后,我发现字段名称和字段值与显示的方式相反。更正示例:

    // Fine - no change here
    $doc->addField(Zend_Search_Lucene_Field::Keyword('_id', '7'));
    
    // Reversed order of parameters
    $idTerm  = new Zend_Search_Lucene_Index_Term('7', '_id',);
    $idQuery = new Zend_Search_Lucene_Search_Query_Term($idTerm);
    

    希望对大家有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多