Results 1 to 2 of 2
  1. #1
    user011 is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Wildcard query with a dash in value

    hi -

    I am using the Standard Analyzer and Tokenizer. I have field with values such as:

    TEST-0001
    RAZOR-0001
    CARP-0001
    MISS-RAZOR-001

    I need to write a query that is the equivalent of a 'starts with'. So, if my search term (searchTerm) was RAZOR-0* (using a wildcard), then only 1 record will be returned:

    RAZOR-0001

    Right now, 2 records are returned:

    RAZOR-0001
    MISS-RAZOR-0001

    Here is my query:

    qb.keyword().wildcard().onField("catalog").matchin g(searchTerm + "*").createQuery()

    Any help is appreciated.

    thanks

  2. #2
    user011 is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Default Re: Wildcard query with a dash in value

    Solved: For the field, I used a custom keyword analyzer that also uses the lower case filter.

    here is my custom analyzer:

    Java Code:
    public class IdCustomAnalyzer extends Analyzer {
    
    	@Override 
        public TokenStream tokenStream(String fieldName, Reader reader) {	 
    		TokenStream tokenStream = new KeywordTokenizer(reader); 
                tokenStream = 
                        new LowerCaseFilter(Version.LUCENE_36, tokenStream); 
                return tokenStream; 
        } 
    
    }


    Quote Originally Posted by user011 View Post
    hi -

    I am using the Standard Analyzer and Tokenizer. I have field with values such as:

    TEST-0001
    RAZOR-0001
    CARP-0001
    MISS-RAZOR-001

    I need to write a query that is the equivalent of a 'starts with'. So, if my search term (searchTerm) was RAZOR-0* (using a wildcard), then only 1 record will be returned:

    RAZOR-0001

    Right now, 2 records are returned:

    RAZOR-0001
    MISS-RAZOR-0001

    Here is my query:

    qb.keyword().wildcard().onField("catalog").matchin g(searchTerm + "*").createQuery()

    Any help is appreciated.

    thanks

Similar Threads

  1. Combine exact Match and wildcard query
    By gfreeman in forum Lucene
    Replies: 1
    Last Post: 07-16-2012, 06:55 PM
  2. Convert dash to underscorde
    By ŖΫ ỏ Ңόρę in forum New To Java
    Replies: 4
    Last Post: 04-04-2011, 08:06 PM
  3. open file with wildcard?
    By minotaurus in forum New To Java
    Replies: 1
    Last Post: 03-01-2011, 10:15 AM
  4. draw smooth dash-ed line
    By sarveshwar in forum Java 2D
    Replies: 3
    Last Post: 03-01-2011, 08:23 AM
  5. Pbm in Generic WildCard?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 02-07-2011, 09:07 PM

Tags for this Thread

Posting Permissions

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