简体   繁体   English

使用lucene在非分析字段中搜索

[英]search on non analyzed field using lucene

I am trying to search using Apache Lucene index. 我正在尝试使用Apache Lucene索引进行搜索。 For it i have created Lucene index on a field filepath which is showing the path and it is not analyzed . 为此,我在字段filepath上创建了Lucene索引,该索引显示了路径,并且未进行分析。

Now i am not able to search on the non analyzed field . 现在,我无法在非分析领域进行搜索。 Is it possible to search on non analyzed field . 是否可以在非分析领域进行搜索。 or is there any way to stop the splitting of the words to be store while analyzed. 还是有什么方法可以阻止分析时要存储的单词分裂。

You're able to search for non-analyzed field query but there will be a match only in case of field value being completely equals to search term. 您可以搜索未分析的字段查询,但只有在字段值完全等于搜索词的情况下才会匹配。 As mindas mentioned - phrase query should be used for that. 就像提到的那样-短语查询应用于此目的。

In case you want to search for that field, you'd need to reindex your documents with that field being analyzed. 如果要搜索该字段,则需要使用正在分析的该字段重新索引文档。

You can try using existing Analyzers / Tokenizers (ie set StandardAnalyzer when creating IndexWriter, for example) or implement your own one that will split file path into tokens using file separator as delimiter. 您可以尝试使用现有的分析器/令牌生成器(例如,在创建IndexWriter时设置StandardAnalyzer),也可以实现自己的分析器/令牌生成器,使用文件分隔符作为分隔符将文件路径拆分为令牌。

In case you're interested, there's Solr's PathHierarchyTokenizerFactory that already splits some hierarchical path into tokens before storing then to index and that makes file path search much easier. 如果您感兴趣,Solr的PathHierarchyTokenizerFactory已经在存储之前将一些分层路径拆分为令牌,然后再进行索引,这使文件路径搜索更加容易。

Is it possible to search on non analyzed field 是否可以在未分析的字段上进行搜索

In order to search non-analyzed fields, you need to use phrase query . 为了搜索未分析的字段,您需要使用短语查询

or is there any way to stop the splitting of the words to be store while analyzed 还是有什么方法可以阻止分析时要存储的单词分裂

Sorry, I don't get this. 对不起,我不明白。 If a field is not analyzed, it is neither split and stored as is. 如果未分析字段,则不会拆分和存储该字段。 Can you clarify your question? 你能澄清你的问题吗?

Yes, you can replace standardAnalyzer by others like KeywordAnalyzer in IndexSearcher config. 是的,您可以在IndexSearcher配置中用其他关键字(例如KeywordAnalyzer)替换standardAnalyzer。 It will treat the field as one term for search. 它将把该字段视为搜索的一个术语。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM