0

I have an application in which Highlighter.getBestFragments return correctly when a query like "fulltext:rajath AND filepath:rajath" is entered. However if the same query contain a "/" in the filepath is entered, meaning if the query is like "fulltext:rajath AND filepath:rajath/rajath1", Highlighter.getBestFragments method returns an empty string. Please let me know how this problem could be solved. I am suspecting heavily that the issue is because of the forward slash in the query. Is there any way to escape it?

Currently I am using lucene 2.9.3 in my application where the highlighting is not happening correctly. But the query "fulltext:rajath AND filepath:rajath/rajath1" used to highlight keyword rajath correctly in lucene 2.2.0. Both in 2.2.0 and 2.9.3 When "fulltext:rajath AND filepath:rajath/rajath1" is entered, internal query changes to [+fulltext:rajath +filepath:"rajath rajath1"]

Kevin Reid
  • 37,492
  • 13
  • 80
  • 108
Rajath
  • 215
  • 5
  • 13

1 Answers1

0

in Lucene 4.x forward slash (/) is now a special character, which is used to signal a regular expression search. You will need to escape your slashes, like:

String query = "filepath:rajath\\/rajath1";

Or you can have lucene do the escaping for you, like:

String searchfor = "rajath/rajath1";
String escapedsearch = QueryParserBase.escape(searchfor);
String query = "filepath:" + escapedsearch;
femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • Currently I am using lucene 2.9.3 in my application where the highlighting is not happening correctly. But the query "fulltext:rajath AND filepath:rajath/rajath1" used to highlight keyword rajath correctly in lucene 2.2.0. Both in 2.2.0 and 2.9.3 When "fulltext:rajath AND filepath:rajath/rajath1" is entered, internal query changes to [+fulltext:rajath +filepath:"rajath rajath1"]. – Rajath Aug 03 '13 at 03:59