Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collate option in PhraseSuggester should allow returning phrases with no matching docs #6929

Merged
merged 1 commit into from Jul 22, 2014

Conversation

Projects
None yet
3 participants
@areek
Copy link
Contributor

areek commented Jul 18, 2014

The new option return_all_phrases in PhraseSuggester collate will allow the user to control whether all the generated suggestions would be returned. Setting the option will have an additional field match_exists in the suggestion options, indicating if there were matched documents for the phrase. The default value for this is false.

Currently the request would look as follows:

curl -XPOST 'localhost:9200/_search' -d {
   "suggest" : {
     "text" : "Xor the Got-Jewel",
     "simple_phrase" : {
       "phrase" : {
         "field" :  "bigram",
         "size" :   1,
         "direct_generator" : [ {
           ...
         } ],
         "collate": {
           "query": { 
              ...
           },
           "return_all_phrases": true
         }
       }
     }
   }
 }

and the response looks as follows (only when return_all_phrases is set to true)

"suggest" : {
    "simple_phrase" : [ {
      "text" : "Xor the Got-Jewel",
      "offset" : 0,
      "length" : 17,
      "options" : [ {
        "text" : ...,
        "highlighted": ...,
        "score" : ...,
        "match_exists" : true
      }, {
        "text" : ...,
        "highlighted": ...,
        "score" : ..,
        "match_exists": false
      } ]
    } ]
  }

Closes #6927

@areek areek added the review label Jul 18, 2014

@s1monw

View changes

docs/reference/search/suggesters/phrase-suggest.asciidoc Outdated
@@ -195,6 +200,7 @@ curl -XPOST 'localhost:9200/_search' -d {
},
"params": {"field_name" : "title"}, <3>
"preference": "_primary", <4>
"return_all_phrases": true <5>

This comment has been minimized.

Copy link
@s1monw

s1monw Jul 22, 2014

Contributor

should we make this part of the "collate" : {} object? I think we can just do something like:

"collate" : {
  "prune" : true|false,
  "query" : {...}
}

This comment has been minimized.

Copy link
@areek

areek Jul 22, 2014

Author Contributor

Yes! prune is a much better name, changed

@s1monw

View changes

src/main/java/org/elasticsearch/search/suggest/Suggest.java Outdated
@@ -521,17 +522,24 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
static final XContentBuilderString TEXT = new XContentBuilderString("text");
static final XContentBuilderString HIGHLIGHTED = new XContentBuilderString("highlighted");
static final XContentBuilderString SCORE = new XContentBuilderString("score");
static final XContentBuilderString MATCH_EXISTS = new XContentBuilderString("matchExists");

This comment has been minimized.

Copy link
@s1monw

s1monw Jul 22, 2014

Contributor

maybe collate_match can be True, False, Null (omitted if Null in XContent)

This comment has been minimized.

Copy link
@areek

areek Jul 22, 2014

Author Contributor

changed to collate_match

@s1monw

View changes

src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggester.java Outdated
continue;
boolean matchExists = hasMatchingDocs(multiSearchResponse, i);
if (!matchExists && !returnAllPhrases) {
continue;

This comment has been minimized.

Copy link
@s1monw

s1monw Jul 22, 2014

Contributor

indentation is off here?

This comment has been minimized.

Copy link
@areek

areek Jul 22, 2014

Author Contributor

fixed

@s1monw

This comment has been minimized.

Copy link
Contributor

s1monw commented Jul 22, 2014

I left some naming comments

@s1monw s1monw removed the review label Jul 22, 2014

@areek

This comment has been minimized.

Copy link
Contributor Author

areek commented Jul 22, 2014

Thanks for the review, @s1monw! I updated the PR with the feedback.

@areek

This comment has been minimized.

Copy link
Contributor Author

areek commented Jul 22, 2014

Now the request looks like:

curl -XPOST 'localhost:9200/_search' -d {
   "suggest" : {
     "text" : "Xor the Got-Jewel",
     "simple_phrase" : {
       "phrase" : {
         "field" :  "bigram",
         "size" :   1,
         "direct_generator" : [ {
           ...
         } ],
         "collate": {
           "query": { 
              ...
           },
           "prune": true
         }
       }
     }
   }
 }

and the response:

"suggest" : {
    "simple_phrase" : [ {
      "text" : "Xor the Got-Jewel",
      "offset" : 0,
      "length" : 17,
      "options" : [ {
        "text" : ...,
        "highlighted": ...,
        "score" : ...,
        "collate_match" : true
      }, {
        "text" : ...,
        "highlighted": ...,
        "score" : ..,
        "collate_match": false
      } ]
    } ]
  }

If the collate option is not set, then collate_match is not included in the response.

@s1monw

This comment has been minimized.

Copy link
Contributor

s1monw commented Jul 22, 2014

LGTM

PhraseSuggester: Collate option should allow returning phrases with n…
…o matching docs

A new option `prune` has been added to allow users to control phrase suggestion pruning when `collate`
is set. If the new option is set, the phrase suggestion option will contain a boolean `collate_match`
indicating whether the respective result had hits in collation.

CLoses #6927

@areek areek merged commit f39d4e1 into elastic:master Jul 22, 2014

@areek areek deleted the areek:enhancement/6927 branch Jul 22, 2014

@clintongormley clintongormley changed the title PhraseSuggester: Collate option should allow returning phrases with no matching docs Suggesters: Collate option in PhraseSuggester should allow returning phrases with no matching docs Sep 11, 2014

@clintongormley clintongormley changed the title Suggesters: Collate option in PhraseSuggester should allow returning phrases with no matching docs Collate option in PhraseSuggester should allow returning phrases with no matching docs Jun 7, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.