Results 1 to 6 of 6
  1. #1
    girirajgupta is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Search with special characters returns nothing

    Hi
    I have been using standard analyzer to index which splits field at special character.
    For e.g. A&B would generate two tokens A and B
    When searching A&B,queryparser returns nothing.Search for A returns it.
    Checked the generated query,search string A&B is not getting sliptted in two tokens,whole string is being searched.

    It seems while parsing queryparser only splits string when space/! is there otherwise whole string is being used.

    Please suggest how to fix this problem.

    Regards,
    Giriraj

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Search with special characters returns nothing

    Can you provide an SSCCE that demonstrates the problem?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    girirajgupta is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Re: Search with special characters returns nothing

    String searchText = "A&B";
    QueryParser queryParser = new QueryParser(Version.LUCENE_30, searchInProperty, new StandardAnalyzer(Version.LUCENE_30));

    Query query = queryParser.parse(searchText);
    mSearcher.search(query, collector);

    Generated query-
    pzSearchLucene: search=A&B
    query parsed > +searchInProperty:"A&B"

    Expected parsed query
    +searchInProperty:"A" +searchInProperty:"B"

    This works if there is an space or ! character

    Regards,
    Raj
    Last edited by girirajgupta; 02-19-2014 at 02:37 PM.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: Search with special characters returns nothing

    Just for my understanding; you're saying that searching for "A & B" (with added spaces) works as you expect it, but searching for "A&B" does not?

    Because from my perspective, that simply makes sense.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    girirajgupta is offline Member
    Join Date
    Feb 2014
    Posts
    3
    Rep Power
    0

    Default Re: Search with special characters returns nothing

    Yes "A & B" or "A B" works ,ideally "A&B" should also get splitted because of standard analyzer like it does for "A-B".
    Last edited by girirajgupta; 02-19-2014 at 03:07 PM.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,083
    Rep Power
    4

    Default Re: Search with special characters returns nothing

    for different reasons I think, a dash '-' is a word split token. I know that because I had to setup my own analyzer to micromanage which tokens Lucene uses as whitepspace tokens (specifically NOT a dash because that is a common component of a company name).

    what I did was basically get the source of Lucene and look how the DefaultAnalyzer was constructed, then I made my own tailored to my needs specifically. With my own whitspace tokenizer that looks like this:

    Java Code:
        public class XXXWhitespaceTokenizer extends CharTokenizer {
    
            public XXXWhitespaceTokenizer(Version matchVersion, Reader in) {
                super(matchVersion, in);
            }
    
            @Override
            protected boolean isTokenChar(int c) {
                return !(c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == ',' || c == ';');
            }
        }
    I can't share all the code of the analyzer since I don't own it. Perhaps if you add the & to that, it works for you too.
    Last edited by gimbal2; 02-19-2014 at 03:26 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Escaping Special Characters
    By djgovins in forum Lucene
    Replies: 6
    Last Post: 07-08-2011, 06:05 PM
  2. Special Characters on GUI
    By keo in forum AWT / Swing
    Replies: 4
    Last Post: 05-01-2011, 10:40 PM
  3. Special characters question
    By alexalex1234 in forum Advanced Java
    Replies: 1
    Last Post: 03-24-2011, 11:33 AM
  4. XML with special characters
    By Kaizah in forum XML
    Replies: 1
    Last Post: 11-06-2009, 02:26 PM
  5. special characters
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-16-2007, 01:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •