dongwei7048 2009-07-02 14:21 采纳率: 100%
浏览 68
已采纳

Lucene中的多期通配符查询?

I'm using Zend_Search_Lucene, the PHP port of Java Lucene. I currently have some code that will build a search query based on an array of strings, finding results for which at least one index field matches each of the strings submitted. Simplified, it looks like this:

(Note: $words is an array constructed from user input.)

$query = new Zend_Search_Lucene_Search_Query_Boolean();
foreach ($words as $word) {
  $term1 = new Zend_Search_Lucene_Index_Term($word, $fieldname1);
  $term2 = new Zend_Search_Lucene_Index_term($word, $fieldname2);
  $multiq = new Zend_Search_Lucene_Search_Query_MultiTerm();
  $multiq->addTerm($term1);
  $multiq->addTerm($term2);
  $query->addSubquery($multiq, true);
}
$hits = $index->find($query);

What I would like to do is replace $word with ($word . '*') — appending an asterisk to the end of each word, turning it into a wildcard term.

But then, $multiq would have to be a Zend_Search_Lucene_Search_Query_Wildcard instead of a Zend_Search_Lucene_Search_Query_MultiTerm, and I don't think I would still be able to add multiple Index_Terms to each $multiq.

Is there a way to construct a query that's both a Wildcard and a MultiTerm?

Thanks!

  • 写回答

2条回答 默认 最新

  • douniani679741 2009-07-02 16:44
    关注

    Not in the way you're hoping to achieve it, unfortunately:

    Lucene supports single and multiple character wildcard searches within single terms (but not within phrase queries).

    and even if it were possible, would probably not be a good idea:

    Wildcard, range and fuzzy search queries may match too many terms. It may cause incredible search performance downgrade.

    I imagine the way to go if you insist on multiple wildcard terms, would be two execute two separate searches, one for each wildcarded term, and bundle the results together.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题