如何搜索所有字段? [英] How to search across all the fields?

查看:83
本文介绍了如何搜索所有字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Lucene中,我们可以使用TermQuery来搜索带有字段的文本.我想知道如何在多个字段或所有可搜索字段中搜索关键字?

In Lucene, we can use TermQuery to search a text with a field. I am wondering how to search a keyword across a bunch of fields or all the searchable fields?

推荐答案

另一种方法是使用

Another approach, which doesn't require to index anything more than what you already have, nor to combine different queries, is using the MultiFieldQueryParser.

您可以提供要搜索的字段列表和查询,仅此而已.

You can provide a list of fields where you want to search on and your query, that's all.

MultiFieldQueryParser queryParser = new MultiFieldQueryParser(
                Version.LUCENE_41, 
                new String[]{"title", "content", "description"},
                new StandardAnalyzer(Version.LUCENE_41));

Query query = queryParser.parse("here goes your query");

这就是我要用Java编写的原始lucene库实现的方式.我不确定MultiFieldQueryParser在lucene.net中是否也可用.

This is how I would do it with the original lucene library written in Java. I'm not sure whether the MultiFieldQueryParser is available in lucene.net too.

这篇关于如何搜索所有字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆