【发布时间】:2012-08-18 18:06:00
【问题描述】:
我正在索引书籍并在书籍的不同字段上执行文本搜索:
- 标题
- 作者
- 书籍摘要
我尝试通过连接书名、作者姓名和书摘要来创建索引,但我的一些搜索没有返回预期的结果,我不明白为什么。
索引书籍以便我同时搜索所有这些字段的正确方法是什么?
--
这里是代码示例:
book_text_index = "#{book.name} #{book.author} #{book.summary}"
idx.document("book_502").add({ :text => book_text_index,
:book_id => "#{book.id}",
:name => "#{book.name}",
:author => "#{book.author}",
:summary => "#{book.summary}"
})
这是我为“Sun Tzu”的“L'art de la guerre”一书获得的结果示例。
如果我搜索作者姓名(“tzu”),它会返回这本书:
idx.search("tzu", :function => 1, :fetch => 'text' )['results']
=> [{"text"=>"L'art de la guerre Sun Tzu Youboox libres de droits Traduit pour la première fois...", "docid"=>"book_502", "query_relevance_score"=>-2967.0}]
但如果我搜索书名的一部分(“guerre”),我不会在结果中找到这本书。
idx.search("guerre", :function => 1, :fetch => 'book_id' )['结果'].map { |结果|结果[“docid”]}
=> [“book_1962”,“book_1963”,“book_1951”,“book_1832”,“book_1812”, “book_1787”、“book_1775”、“book_1778”、“book_1730”、“book_1740”]
您可以看到 book_502 不在结果中。
【问题讨论】:
-
您如何为 IndexTank 限制为每个文档 100k 的书籍编制索引?
-
我们没有在 indextank 上索引这本书的内容,只有元数据。如果我必须索引内容,我会尝试使用 Apache Tika 来提取文本内容和 Amason 弹性搜索,但这是另一个问题。