You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Alex Chesser - Katalyst <ac...@katalystadvantage.com> on 2017/05/05 19:58:24 UTC

[lucenenet] How do you handle an unmatched quote?

Hi mailing list folks!

I was wondering how other members of the list have solved the problem of
unmatched special characters?

As an example, I have a lucene.net search with the following results:


   - term1 term2  - returns a search based on any occurrences of term1 &
   term2
   - "term1 term2" - returns a search based on the exact phrase "term1
   term2"
   - "term1 term2 - throws an exception "Lexical error" - <EOF> after :
   "\"term1 term2

now in searching for an answer, I saw online that there is one option which
is to add a call to ESCAPE on the query parser

Query query = parser.Parse(QueryParser.Escape(request.Phrase));




but in this case, I'm seeing the results appear as:

   - term1 term2  - returns a search based on any occurrences of term1 &
   term2
   - "term1 term2" - same as above
   - "term1 term2 - same as above

however, to in my opinion, the results should probably behave as:

   - term1 term2  - returns a search based on any occurrences of term1 &
   term2
   - "term1 term2" - returns a search based on the exact phrase "term1
   term2"
   - "term1 term2 - same as the results of term1 term2

I wonder if anyone else has encountered this or has come up with a
different solution?

Re: [lucenenet] How do you handle an unmatched quote?

Posted by Itamar Syn-Hershko <it...@code972.com>.
Take a look at the SimpleQueryParser (
https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.QueryParser/Simple/SimpleQueryParser.cs)
from the QueryParser package. It handles syntax errors gracefully.

--

Itamar Syn-Hershko
Freelance Developer & Consultant
Elasticsearch Partner
Microsoft MVP | Lucene.NET PMC
http://code972.com | @synhershko <https://twitter.com/synhershko>
http://BigDataBoutique.co.il/

On Fri, May 5, 2017 at 10:58 PM, Alex Chesser - Katalyst <
achesser@katalystadvantage.com> wrote:

> Hi mailing list folks!
>
> I was wondering how other members of the list have solved the problem of
> unmatched special characters?
>
> As an example, I have a lucene.net search with the following results:
>
>
>    - term1 term2  - returns a search based on any occurrences of term1 &
>    term2
>    - "term1 term2" - returns a search based on the exact phrase "term1
>    term2"
>    - "term1 term2 - throws an exception "Lexical error" - <EOF> after :
>    "\"term1 term2
>
> now in searching for an answer, I saw online that there is one option which
> is to add a call to ESCAPE on the query parser
>
> Query query = parser.Parse(QueryParser.Escape(request.Phrase));
>
>
>
>
> but in this case, I'm seeing the results appear as:
>
>    - term1 term2  - returns a search based on any occurrences of term1 &
>    term2
>    - "term1 term2" - same as above
>    - "term1 term2 - same as above
>
> however, to in my opinion, the results should probably behave as:
>
>    - term1 term2  - returns a search based on any occurrences of term1 &
>    term2
>    - "term1 term2" - returns a search based on the exact phrase "term1
>    term2"
>    - "term1 term2 - same as the results of term1 term2
>
> I wonder if anyone else has encountered this or has come up with a
> different solution?
>