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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器