0
votes

I am using Lucene .Net Version 3.0.3

Here is Lucene Query converted to string with the field key, value and tolerance.

+(() (((((FirstNames:John~0.8)^0.7)) (((LastNames:Smith~0.8)^0.8)) ())~2)) +(() (*:*))

I want to pass the string value to the Api where i need to convert back to Lucene Query.

I tried QueryParser and MultifieldQueryparser with the field FirstName and LastName, but not returning the exact Query as I passed.

1

1 Answers

0
votes

Generally, the methods of parsing a string to a lucene query are the QueryParsers, as you've indicated.

However, getting the string representation of a query is mostly useful for debugging and the like. It does not provide a reliable method of serialization. There is no guarantee that it will provide a string that is even parsable by any particular query parser, much less that it will be identical to the query it was generated from.

Query is [Serializable] though, so you can serialize it before sending/storing it instead. See: Object Serialization in .NET.

One warning though: As of 4.0, Lucene no longer supports query serialization. If and when Lucene.Net reaches 4.0, it is reasonable to assume it will also remove support for serialization, and you will be left to handle serialization at a higher level.