You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2017/10/26 22:11:25 UTC
[geode-examples] 01/01: GEODE-3789: rename a test data class
This is an automated email from the ASF dual-hosted git repository.
zhouxj pushed a commit to branch feature/GEODE-3789
in repository https://gitbox.apache.org/repos/asf/geode-examples.git
commit 7fd728ca2db346cb82ab22f18ab7659038f634f4
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Thu Oct 26 15:10:52 2017 -0700
GEODE-3789: rename a test data class
---
lucene/README.md | 12 ++++++------
lucene/scripts/start.gfsh | 2 +-
.../lucene/{ZipAndPhone.java => Contact.java} | 20 ++++++++++----------
.../apache/geode/examples/lucene/EmployeeData.java | 12 ++++++------
.../org/apache/geode/examples/lucene/Example.java | 21 ++++++++++-----------
5 files changed, 33 insertions(+), 34 deletions(-)
diff --git a/lucene/README.md b/lucene/README.md
index 2044a2a..a9f7991 100644
--- a/lucene/README.md
+++ b/lucene/README.md
@@ -73,15 +73,15 @@ will also be retrieved from the region and printed to the console.
// Do a compound search on last name and email using analyzerIndex
gfsh>search lucene --name=analyzerIndex --region=example-region --queryStrings="lastName:hall~ AND email:Kris.Call@example.com" --defaultField=lastName
- // Do a compound search on nested object with both 5035330001 AND 5036430001 in either home or office.
- // Note: 5035330001 is one of his home phone, 5036430001 is one of his office phone.
- gfsh>search lucene --name=nestedObjectIndex --region=/example-region --queryString="5035330001 AND 5036430001" --defaultField=zipAndPhoneBook.phones
+ // Do a compound search on nested object with both 5035330001 AND 5036430001 in contacts
+ // Note: 5035330001 is phone number of one of his contacts, 5036430001 is hpne number of his another contact, since they are both his contact, it will lead to him.
+ gfsh>search lucene --name=nestedObjectIndex --region=/example-region --queryString="5035330001 AND 5036430001" --defaultField=contacts.phoneNumbers
- // If query on 5035330001 AND 5036430002, it will not find the person, because the 2 phone numbers belong to different person's entry.
- gfsh>search lucene --name=nestedObjectIndex --region=/example-region --queryString="5035330001 AND 5036430002" --defaultField=zipAndPhoneBook.phones
+ // If query on 5035330001 AND 5036430002, it will not find the person, because the 2 phone numbers belong to different people's contacts.
+ gfsh>search lucene --name=nestedObjectIndex --region=/example-region --queryString="5035330001 AND 5036430002" --defaultField=contacts.phoneNumbers
// If query on 5035330001 OR 5036430002, it will find 2 people's entries
- gfsh>search lucene --name=nestedObjectIndex --region=/example-region --queryString="5035330001 OR 5036430002" --defaultField=zipAndPhoneBook.phones
+ gfsh>search lucene --name=nestedObjectIndex --region=/example-region --queryString="5035330001 OR 5036430002" --defaultField=contacts.phoneNumbers
3. Examine the Lucene index statistics
diff --git a/lucene/scripts/start.gfsh b/lucene/scripts/start.gfsh
index ab25abf..b3d17bd 100644
--- a/lucene/scripts/start.gfsh
+++ b/lucene/scripts/start.gfsh
@@ -26,7 +26,7 @@ create lucene index --name=simpleIndex --region=example-region --field=firstName
create lucene index --name=analyzerIndex --region=example-region --field=lastName,email --analyzer=DEFAULT,org.apache.lucene.analysis.core.KeywordAnalyzer
## nestedObjectIndex will index on nested objects or collection objects
-create lucene index --name=nestedObjectIndex --region=example-region --field=zipAndPhoneBook.phones --serializer=org.apache.geode.cache.lucene.FlatFormatSerializer
+create lucene index --name=nestedObjectIndex --region=example-region --field=contacts.phoneNumbers --serializer=org.apache.geode.cache.lucene.FlatFormatSerializer
create region --name=example-region --type=PARTITION --enable-statistics=true
diff --git a/lucene/src/main/java/org/apache/geode/examples/lucene/ZipAndPhone.java b/lucene/src/main/java/org/apache/geode/examples/lucene/Contact.java
similarity index 72%
rename from lucene/src/main/java/org/apache/geode/examples/lucene/ZipAndPhone.java
rename to lucene/src/main/java/org/apache/geode/examples/lucene/Contact.java
index 4aa5b04..7d53d87 100644
--- a/lucene/src/main/java/org/apache/geode/examples/lucene/ZipAndPhone.java
+++ b/lucene/src/main/java/org/apache/geode/examples/lucene/Contact.java
@@ -17,25 +17,25 @@ package org.apache.geode.examples.lucene;
import java.io.Serializable;
import java.util.Arrays;
-public class ZipAndPhone implements Serializable {
- private int zip;
- private String[] phones;
+public class Contact implements Serializable {
+ private String name;
+ private String[] phoneNumbers;
- ZipAndPhone(int zip, String[] phones) {
- this.zip = zip;
- this.phones = phones;
+ Contact(String name, String[] phoneNumbers) {
+ this.name = name;
+ this.phoneNumbers = phoneNumbers;
}
- public int getZip() {
- return this.zip;
+ public String getName() {
+ return this.name;
}
public String[] getPhones() {
- return this.phones;
+ return this.phoneNumbers;
}
@Override
public String toString() {
- return "(zip=" + zip + ", phones=" + Arrays.toString(phones) + ")";
+ return "(name=" + name + ", phones=" + Arrays.toString(phoneNumbers) + ")";
}
}
diff --git a/lucene/src/main/java/org/apache/geode/examples/lucene/EmployeeData.java b/lucene/src/main/java/org/apache/geode/examples/lucene/EmployeeData.java
index 27893a9..d759eb3 100644
--- a/lucene/src/main/java/org/apache/geode/examples/lucene/EmployeeData.java
+++ b/lucene/src/main/java/org/apache/geode/examples/lucene/EmployeeData.java
@@ -26,17 +26,17 @@ public class EmployeeData implements Serializable {
private String email;
private int salary;
private int hoursPerWeek;
- private Collection<ZipAndPhone> zipAndPhoneBook;
+ private Collection<Contact> contacts;
public EmployeeData(String firstName, String lastName, int emplNumber, String email, int salary,
- int hoursPerWeek, Collection<ZipAndPhone> zipAndPhoneBook) {
+ int hoursPerWeek, Collection<Contact> zipAndPhoneBook) {
this.firstName = firstName;
this.lastName = lastName;
this.emplNumber = emplNumber;
this.email = email;
this.salary = salary;
this.hoursPerWeek = hoursPerWeek;
- this.zipAndPhoneBook = zipAndPhoneBook;
+ this.contacts = zipAndPhoneBook;
}
public String getFirstName() {
@@ -63,14 +63,14 @@ public class EmployeeData implements Serializable {
return hoursPerWeek;
}
- public Collection<ZipAndPhone> getZipAndPhones() {
- return this.zipAndPhoneBook;
+ public Collection<Contact> getZipAndPhones() {
+ return this.contacts;
}
@Override
public String toString() {
return "EmployeeData [firstName=" + firstName + ", lastName=" + lastName + ", emplNumber="
+ emplNumber + ", email= " + email + ", salary=" + salary + ", hoursPerWeek=" + hoursPerWeek
- + ", zipAndPhoneBook=" + zipAndPhoneBook + "]";
+ + ", zipAndPhoneBook=" + contacts + "]";
}
}
diff --git a/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java b/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java
index c26cd5e..020a6e0 100644
--- a/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java
+++ b/lucene/src/main/java/org/apache/geode/examples/lucene/Example.java
@@ -64,9 +64,9 @@ public class Example {
private static void queryNestedObject(ClientCache cache) throws LuceneQueryException {
LuceneService lucene = LuceneServiceProvider.get(cache);
LuceneQuery<Integer, EmployeeData> query = lucene.createLuceneQueryFactory().create(
- NESTEDOBJECT_INDEX, EXAMPLE_REGION, "5035330001 AND 5036430001", "zipAndPhoneBook.phones");
- System.out.println(
- "Employees with both phone number 5035330001 and 5036330001 either in office or home: "
+ NESTEDOBJECT_INDEX, EXAMPLE_REGION, "5035330001 AND 5036430001", "contacts.phoneNumbers");
+ System.out
+ .println("Employees with phone number 5035330001 and 5036430001 in his different contacts: "
+ query.findValues());
}
@@ -74,6 +74,7 @@ public class Example {
// insert values into the region
String[] firstNames = "Alex,Bertie,Kris,Dale,Frankie,Jamie,Morgan,Pat,Ricky,Taylor".split(",");
String[] lastNames = "Able,Bell,Call,Driver,Forth,Jive,Minnow,Puts,Reliable,Tack".split(",");
+ String[] contactNames = "Jack,John,Tom,William,Nick,Jason,Daniel,Sue,Mary,Mark".split(",");
int salaries[] = new int[] {60000, 80000, 75000, 90000, 100000};
int hours[] = new int[] {40, 40, 40, 30, 20};
int emplNumber = 10000;
@@ -85,17 +86,15 @@ public class Example {
int salary = salaries[index % 5];
int hoursPerWeek = hours[index % 5];
- // create a home zipAndPhone with zip=9700x, phones=503533000x, 503633000x;
- // an office zipAndPhone with zip=9800x, phones=503543000x, 503643000x
- ArrayList<ZipAndPhone> zipAndPhoneBook = new ArrayList();
- ZipAndPhone home = new ZipAndPhone(97000 + index,
+ ArrayList<Contact> contacts = new ArrayList();
+ Contact contact1 = new Contact(contactNames[index] + " Jr",
new String[] {"50353" + (30000 + index), "50363" + (30000 + index)});
- ZipAndPhone office = new ZipAndPhone(98000 + index,
+ Contact contact2 = new Contact(contactNames[index],
new String[] {"50354" + (30000 + index), "50364" + (30000 + index)});
- zipAndPhoneBook.add(home);
- zipAndPhoneBook.add(office);
+ contacts.add(contact1);
+ contacts.add(contact2);
EmployeeData val = new EmployeeData(firstNames[index], lastNames[index], emplNumber, email,
- salary, hoursPerWeek, zipAndPhoneBook);
+ salary, hoursPerWeek, contacts);
region.put(key, val);
}
}
--
To stop receiving notification emails like this one, please contact
"commits@geode.apache.org" <co...@geode.apache.org>.