lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ankit Murarka <ankit.mura...@rancoretech.com>
Subject Re: Query type always Boolean Query even if * and ? are present.
Date Thu, 12 Sep 2013 15:22:52 GMT
I also tried it with this query:

<param name="user_name" value="USER_NAME_MENTIONED"/>*

I am still getting it as Boolean Query.. It should be Prefix...

On 9/12/2013 8:50 PM, Jack Krupansky wrote:
> The trailing asterisk in your query input is escaped with a backslash, 
> so the query parser will not treat it as a wildcard.
>
> -- Jack Krupansky
>
> -----Original Message----- From: Ankit Murarka
> Sent: Thursday, September 12, 2013 10:19 AM
> To: java-user@lucene.apache.org
> Subject: Query type always Boolean Query even if * and ? are present.
>
> 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"


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message