Hello.

I am faced with a trivial issue: Everytime my Query is being fired as a Boolean Query...

Providing Input : <param name="user_name" value="USER_NAME_MENTIONED"/>\*

This input is provided. Since this contains special characters I use escape method of QueryParser (removed escaping for * and ? since they are needed for WildCard and Prefix Searches.)

public static String escape(String s) {

        System.out.println("CALLED");
        StringBuilder sb = new StringBuilder();

        try
        {
        for (int i = 0; i < s.length(); i++) {
          char c = s.charAt(i);
// These characters are part of the query syntax and must be escaped if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':' || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
            || c == '|' || c == '&' || c == '/') {
            sb.append('\\');
          }
          sb.append(c);
        }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
        return sb.toString();
      }

/*The function which is used to provide the HIT:*/

            Directory directory=null;;
            IndexReader reader=null;
            IndexSearcher searcher=null;
            Analyzer analyzer=null;
            try
            {
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_44);

directory = FSDirectory.open(new File(strMainIndexPath.replace("\\", "/"))); reader = DirectoryReader.open(directory); //location where indexes are.
                searcher = new IndexSearcher(reader);

System.out.println("Searching for '" + searchString + "' using QueryParser"); QueryParser queryParser = new QueryParser(Version.LUCENE_44,"contents",analyzer);

searchString=CommonMethods.escape(searchString); //MENTIONED ABOVE

System.out.println("ESCAPE STRING AFTER THE ESCAPE FUNCTION OF QUERYPARSER >>> " + searchString);

                Query query = queryParser.parse(searchString);

System.out.println("Type of query: " +query.getClass().getSimpleName()); //GETTING IT AS BOOLEAN ALWAYS..

The last output is always BOOLEAN Query... Even if I am appending * at the end, the query is always Boolean...
I have to use QueryParser ONLY....
Absolutely no manipulation is done on string from being given as in input to the string which is provided to this search function.

Kindly guide..

TIA.

--
Regards

Ankit Murarka

"What lies behind us and what lies before us are tiny matters compared with what 
lies within us"

Reply via email to