如何搜索单词的一部分.我正在使用lucene [英] how to search a part of word. I am using lucene

查看:103
本文介绍了如何搜索单词的一部分.我正在使用lucene的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在搜索中,我想搜索单词的一部分,这意味着如果我有一个像infrastructure这样的单词,我只想搜索infra.
请帮助我提供代码,并告诉我如何显示一些数据作为摘要.
谢谢您,

Hi,
In my search I want to search a part of a word, this means if I have a word like infrastructure, I want to search only infra.
Please help me with code and please tell me how to show some data as summary.
Thank you,

推荐答案

有很多方法可以做到这一点,一个更清晰的问题会有所帮助.

如果您有单词列表,可以尝试:
There are a lot of ways to do this and a clearer question would have helped.

If you have a list of words, you could try:
for each word in list
  if word contains search
    output word



如果您只有原始文字:



If you only have the raw text:

for each occurance of search in text
  highlight search
output highlighted text



再一次,您可以为单词及其出现的文档建立索引.这将更加有趣,因为您需要知道哪些完整的单词可以包含您的搜索词.在这里,您可以执行提取搜索词两侧的文本以输出每个文档的标准.

一开始,他们的实际需求尚不清楚,因此我无法为您提供真实的代码.



Then again you could have an index of words and the documents they occur in. This will be more fun as you''ll need to know which full words can contain your search term. Here you can do the standard of extracting the text either side of the search term to output for each document.

As I started, they actual requirement is unclear and so I have not been able to give you real code.

Update your question with more detail and I will endevour to give you more of an answer.


使用StringTokenizer,例如StringTokenizer tkn = new StringTokenizer(StringToBeSeached,StringToSeach);

请注意,在具有要查找的主字符串之后,应该初始化令牌生成器,因此您不能在之前分配令牌生成器.例如,如果您打算从文件中读取字符串,并查看它们是否包含子字符串,则每次从文件中读取新字符串时都必须初始化令牌生成器.
Use StringTokenizer e.g StringTokenizer tkn = new StringTokenizer( StringToBeSeached, StringToSeach);

Notice that you should initialize tokenizer after you have you main string to look-in, so you cant allocate tokenizer before. For example, if you are intended to read strings from a file and look in them if they have a sub-string you seach then you have to initialize tokenizer each time you read a new string from the file.


这篇关于如何搜索单词的一部分.我正在使用lucene的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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