开发者

Handling special characters with lucene

开发者 https://www.devze.com 2023-01-23 10:44 出处:网络
i haven\'t found the answer to my problem so I decided to write my question to get some help. I use lucene to index the objects in computer memory(they exist only in my java code). While processing t

i haven't found the answer to my problem so I decided to write my question to get some help.

I use lucene to index the objects in computer memory(they exist only in my java code). While processing the code I index (using WhitespaceAnalyzer) the field with value objA/4.

My problem starts when I want to find it after the indexation (also using WhitespaceAnalyzer).

When i create a query obj* , I find all objects that start with obj - if i create a query objA/4 I also can find this object.

However i don't know how to find all objects starting with objA/ , when I create a query objA/* lucene is changing it to obja/* and finds nothing.

I've checked and "/" is not a special character so i dont need any "\" preceding it.

So my question is how to ask to get all objects that 开发者_JAVA百科starts with objA/ (for example - objA/0, objA/1, objA/2, objA/3)?


Are you using QueryParser.escape(String) to escape everything correctly?


The code i'm using:

String node = "objA/*";   

 Query node_query = MultiFieldQueryParser.parse(node, "nodeName", new WhitespaceAnalyzer());

 BooleanQuery bq = new BooleanQuery();  

 bq.add(node_query, BooleanClause.Occur.MUST);

 System.out.println("We're asking for - " + bq);  

 IndexSearcher looker = new IndexSearcher(rep_index);

 Hits hits = looker.search(bq);
0

精彩评论

暂无评论...
验证码 换一张
取 消