Can Someone Please help me out? I am stucked at wildcard search with special characters using StandardTokenizerFactory

Please consider that maybe your expectations are incorrect.

No it should not. It should match documents that contain a word starting with FLAT. You used a WhitespaceTokenizer, so a word is defined as a sequence of non-whitespace characters. Thus you will get all documents that contain FLAT at the beginning followed by non-whitespace characters, or a whitespace followed by FLAT followed by non-whitespace characters.

As it should, considering your configuration.

You seem to be implementing some kind of parser and a custom query language. I don’t really understand what you’re trying to achieve, so I suggest you start with simpleQueryString instead. Do this, without trying to pre-process the string.

		org.apache.lucene.search.Query lucene_query = qb.simpleQueryString().onField("fullRecord")
				.matching(matchingString).createQuery();
		bool.must(lucene_query);

You can find more information about simple query string here.

1 Like

@yrodiere Please give me a suitable solution for this. How can i make my wildcard work like so that it will give me the documents starting from FLAT only if someone searches like FLAT*

@yrodiere Will your example work for wildcard? As you have suggested just qb.simpleQueryString…and all.
I want to achieve wildcard as well

@yrodiere Gentle Reminder Please suggest a solution !

The main problem is that wildcard queries ignore analysis completely. It is probably what brought you here: when a user searches for foo.* , the wildcard query will not apply analysis and thus will not drop the traling dot ( . ). It will then look for documents containing foo. (with a trailing dot), and won’t find anything since your analyzer dropped all the dots at indexing time.

1 Like

i have the same query

Yes please tell me whats the issue? .

This question was answered and the original problem marked as solved. I’m going to close this topic.

@Roma_Red if you have a question of your own, please open a new topic, including:

  • The code you’re using to build the query
  • Your mapping (code of the entities and annotations)
  • What you’re expecting (example of indexed entities and expected matching entities).
  • What you’re getting instead.

@dhanushx012 or someone else will be able to answer there.