-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Phrase Suggester: Add collate option to PhraseSuggester
The newly added collate option will let the user provide a template query/filter which will be executed for every phrase suggestions generated to ensure that the suggestion matches at least one document for the filter/query. The user can also add routing preference `preference` to route the collate query/filter and additional `params` to inject into the collate template. Closes #3482
- Loading branch information
Showing
10 changed files
with
622 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/main/java/org/elasticsearch/cluster/routing/operation/plain/Preference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.cluster.routing.operation.plain; | ||
|
||
import org.elasticsearch.ElasticsearchIllegalArgumentException; | ||
import org.elasticsearch.common.collect.Tuple; | ||
|
||
/** | ||
* Routing Preference Type | ||
*/ | ||
public enum Preference { | ||
|
||
/** | ||
* Route to specific shards | ||
*/ | ||
SHARDS("_shards"), | ||
|
||
/** | ||
* Route to preferred node, if possible | ||
*/ | ||
PREFER_NODE("_prefer_node"), | ||
|
||
/** | ||
* Route to local node, if possible | ||
*/ | ||
LOCAL("_local"), | ||
|
||
/** | ||
* Route to primary shards | ||
*/ | ||
PRIMARY("_primary"), | ||
|
||
/** | ||
* Route to primary shards first | ||
*/ | ||
PRIMARY_FIRST("_primary_first"), | ||
|
||
/** | ||
* Route to the local shard only | ||
*/ | ||
ONLY_LOCAL("_only_local"), | ||
|
||
/** | ||
* Route to specific node only | ||
*/ | ||
ONLY_NODE("_only_node"); | ||
|
||
private final String type; | ||
|
||
Preference(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String type() { | ||
return type; | ||
} | ||
/** | ||
* Parses the Preference Type given a string | ||
*/ | ||
public static Preference parse(String preference) { | ||
String preferenceType; | ||
int colonIndex = preference.indexOf(':'); | ||
if (colonIndex == -1) { | ||
preferenceType = preference; | ||
} else { | ||
preferenceType = preference.substring(0, colonIndex); | ||
} | ||
|
||
switch (preferenceType) { | ||
case "_shards": | ||
return SHARDS; | ||
case "_prefer_node": | ||
return PREFER_NODE; | ||
case "_only_node": | ||
return ONLY_NODE; | ||
case "_local": | ||
return LOCAL; | ||
case "_primary": | ||
return PRIMARY; | ||
case "_primary_first": | ||
case "_primaryFirst": | ||
return PRIMARY_FIRST; | ||
case "_only_local": | ||
case "_onlyLocal": | ||
return ONLY_LOCAL; | ||
default: | ||
throw new ElasticsearchIllegalArgumentException("no Preference for [" + preferenceType + "]"); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
49 changes: 49 additions & 0 deletions
49
src/main/java/org/elasticsearch/index/query/BytesFilterBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.query; | ||
|
||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.xcontent.*; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* FilterBuilder that constructs filters from {@link org.elasticsearch.common.bytes.BytesReference} | ||
* source | ||
*/ | ||
public class BytesFilterBuilder extends BaseFilterBuilder { | ||
|
||
private final BytesReference source; | ||
|
||
public BytesFilterBuilder(BytesReference source) { | ||
this.source = source; | ||
|
||
} | ||
|
||
@Override | ||
protected void doXContent(XContentBuilder builder, Params params) throws IOException { | ||
try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) { | ||
// unwrap the first layer of json dictionary | ||
parser.nextToken(); | ||
parser.nextToken(); | ||
builder.copyCurrentStructure(parser); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.