only propose value if the existing prefix is a real prefix

This commit is contained in:
2017-09-23 13:31:34 +02:00
parent 4360944683
commit c9ff8b5586
2 changed files with 16 additions and 7 deletions

View File

@@ -227,7 +227,7 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
final SortedSet<String> result = new TreeSet<>(); final SortedSet<String> result = new TreeSet<>();
for (final String value : availableValuesForKey) { for (final String value : availableValuesForKey) {
if (value.startsWith(propertyValuePrefix)) { if (value.startsWith(propertyValuePrefix) && !value.equals(propertyValuePrefix)) {
result.add(value); result.add(value);
} }
} }

View File

@@ -41,12 +41,14 @@ public class ProposerTest {
private void initDatabase() throws Exception { private void initDatabase() throws Exception {
tagsToPath = new LinkedHashMap<>(); tagsToPath = new LinkedHashMap<>();
final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim"); final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim");
final Tags eagleTimothy = Tags.create("bird", "eagle", "name", "Timothy");
final Tags pigeonJennifer = Tags.create("bird", "pigeon", "name", "Jennifer"); final Tags pigeonJennifer = Tags.create("bird", "pigeon", "name", "Jennifer");
final Tags flamingoJennifer = Tags.create("bird", "flamingo", "name", "Jennifer"); final Tags flamingoJennifer = Tags.create("bird", "flamingo", "name", "Jennifer");
final Tags labradorJenny = Tags.create("dog", "labrador", "name", "Jenny"); final Tags labradorJenny = Tags.create("dog", "labrador", "name", "Jenny");
final Tags labradorTim = Tags.create("dog", "labrador", "name", "Tim"); final Tags labradorTim = Tags.create("dog", "labrador", "name", "Tim");
tagsToPath.put(eagleTim, null); tagsToPath.put(eagleTim, null);
tagsToPath.put(eagleTimothy, null);
tagsToPath.put(pigeonJennifer, null); tagsToPath.put(pigeonJennifer, null);
tagsToPath.put(flamingoJennifer, null); tagsToPath.put(flamingoJennifer, null);
tagsToPath.put(labradorJenny, null); tagsToPath.put(labradorJenny, null);
@@ -63,36 +65,43 @@ public class ProposerTest {
public void testEmptyQuery() throws Exception { public void testEmptyQuery() throws Exception {
assertProposals("", 0, // assertProposals("", 0, //
new Proposal("name", "name=*", 5), // new Proposal("name", "name=*", 6), //
new Proposal("bird", "bird=*", 3), // new Proposal("bird", "bird=*", 4), //
new Proposal("dog", "dog=*", 2)// new Proposal("dog", "dog=*", 2)//
); );
assertProposals(" ", 1, // assertProposals(" ", 1, //
new Proposal("name", "name=*", 5), // new Proposal("name", "name=*", 6), //
new Proposal("bird", "bird=*", 3), // new Proposal("bird", "bird=*", 4), //
new Proposal("dog", "dog=*", 2)// new Proposal("dog", "dog=*", 2)//
); );
} }
public void testPrefixOfKey() throws Exception { public void testPrefixOfKey() throws Exception {
assertProposals("bi", 2, // assertProposals("bi", 2, //
new Proposal("bird", "bird=* ", 3) // new Proposal("bird", "bird=* ", 4) //
); );
assertProposals("bird", 4, // assertProposals("bird", 4, //
new Proposal("bird", "bird=* ", 3) // new Proposal("bird", "bird=* ", 4) //
); );
} }
public void testPrefixOfValue() throws Exception { public void testPrefixOfValue() throws Exception {
assertProposals("name =Tim", 9, //
new Proposal("Timothy", "name =Timothy ", 1)
);
/*
assertProposals("name =Je", 8, // assertProposals("name =Je", 8, //
new Proposal("Jennifer", "name =Jennifer ", 2), // new Proposal("Jennifer", "name =Jennifer ", 2), //
new Proposal("Jenny", "name =Jenny ", 1) // new Proposal("Jenny", "name =Jenny ", 1) //
); );
assertProposals("bird=eagle and n", 16, // assertProposals("bird=eagle and n", 16, //
new Proposal("name", "bird=eagle and name=* ", 1) // new Proposal("name", "bird=eagle and name=* ", 1) //
); );
*/
} }
private void assertProposals(final String query, final int caretIndex, final Proposal... expected) private void assertProposals(final String query, final int caretIndex, final Proposal... expected)