[ 
https://issues.apache.org/jira/browse/GEODE-2952?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16025244#comment-16025244
 ] 

David Anuta commented on GEODE-2952:
------------------------------------

Turns out you can do exact query matches using double quotes, but it is 
dependent upon the quotes used when actually passing the query string to the 
GFSH shell. Below is an example exact query matching on the string "police 
dept" within a test index which contains both the exact string "police dept" 
and the string "police".

{noformat}
describe lucene index --name index --region region

Index Name | Region Path | Server Name |     Indexed Fields     |             
Field Analyzer              |   Status    | Query Executions | Updates | 
Commits | Documents

---------- | ----------- | ----------- | ---------------------- | 
--------------------------------------- | ----------- | ---------------- | 
------- | ------- | ---------

index      | /region     | s1          | [__REGION_VALUE_FIELD] | 
{__REGION_VALUE_FIELD=StandardAnalyzer} | Initialized | 0                | 0    
   | 0       | 0

gfsh>put --region region --key 1 --value="police dept"

Result      : true

Key Class   : java.lang.String

Key         : 1

Value Class : java.lang.String

Old Value   : <NULL>





gfsh>put --region region --key 2 --value="police"

Result      : true

Key Class   : java.lang.String

Key         : 2

Value Class : java.lang.String

Old Value   : <NULL>



gfsh>search lucene --name index --region region --queryStrings='"police dept"' 
--defaultField __REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

1   | police dept | 0.51623213



gfsh>search lucene --name index --region region --queryStrings='police dept' 
--defaultField __REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

2   | police      | 0.2876821

1   | police dept | 0.51623213



gfsh>put --region region --key 3 --value="ABC"

Result      : true

Key Class   : java.lang.String

Key         : 3

Value Class : java.lang.String

Old Value   : <NULL>





gfsh>search lucene --name index --region region 
--queryStrings='__REGION_VALUE_FIELD:"police dept"' --defaultField 
__REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

1   | police dept | 0.51623213



gfsh>search lucene --name index --region region 
--queryStrings='__REGION_VALUE_FIELD:"police dept" OR 
__REGION_VALUE_FIELD:"ABC"' --defaultField __REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

3   | ABC         | 0.2876821

1   | police dept | 0.51623213



gfsh>search lucene --name index --region region 
--queryStrings='__REGION_VALUE_FIELD:"police dept" OR 
__REGION_VALUE_FIELD:\'ABC\'' --defaultField __REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

3   | ABC         | 0.2876821

1   | police dept | 0.51623213



gfsh>search lucene --name index --region region 
--queryStrings="__REGION_VALUE_FIELD:'police dept' OR 
__REGION_VALUE_FIELD:'ABC'" --defaultField __REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

2   | police      | 0.2876821

3   | ABC         | 0.2876821

1   | police dept | 0.51623213



gfsh>search lucene --name index --region region 
--queryStrings="__REGION_VALUE_FIELD:\"police dept\" OR 
__REGION_VALUE_FIELD:'ABC'" --defaultField __REGION_VALUE_FIELD

key |    value    | score

--- | ----------- | ----------

3   | ABC         | 0.2876821

1   | police dept | 0.51623213

{noformat}

As you can see, the double quotations must be used within the actual query 
string parameter passed to the queryStrings flag in order to get a proper exact 
match on the query string through the API. In the example given in the 
description of this issue, the 'Police Dept' case failed to exact match because 
there were no double quotes around the Police Dept string and the '\"Police 
Dept\"' string failed because the double quotes were escaped when they did not 
need to be. The formatting for exact string matching on the string Police Dept 
right now must be either '"Police Dept"' (no escape characters are needed for 
parsing) or "\"Police Dept\"" (escape characters needed for flag parsing).

> gfsh doesn't support exact match lucene queries
> -----------------------------------------------
>
>                 Key: GEODE-2952
>                 URL: https://issues.apache.org/jira/browse/GEODE-2952
>             Project: Geode
>          Issue Type: Bug
>          Components: lucene
>            Reporter: Barry Oglesby
>            Assignee: David Anuta
>             Fix For: 1.2.0
>
>
> This command:
> {noformat}
> gfsh>search lucene --name=index --region=data 
> --defaultField=Resolution_Description --queryStrings='Police Dept'
> {noformat}
> Runs this lucene query:
> {noformat}
> Resolution_Description:police Resolution_Description:dept
> {noformat}
> I also tried this command which ran the same lucene query as above:
> {noformat}
> gfsh>search lucene --name=index --region=data 
> --defaultField=Resolution_Description --queryStrings='\"Police Dept\"'
> {noformat}
> The java API supports exact match queries with "" around the queryString. 
> Doing this causes this lucene query to be run:
> {noformat}
> Resolution_Description:"police dept"
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to