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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器