Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
added changes to solr schema allowing for case insensitive searching …
Browse files Browse the repository at this point in the history
…across a number of fields. Still need to implement intelligent white space analyzers. Added additional fields as well as get/set functionality, as well as initialization from ldap with successful saving into Solr
  • Loading branch information
chrim committed Nov 19, 2010
1 parent 6bed40c commit 3b3d3b1
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 50 deletions.
53 changes: 34 additions & 19 deletions schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,18 +421,28 @@

<field name="uid" type="string" indexed="true" stored="true" required="true" />
<field name="otype" type="string" indexed="true" stored="true" required="true" />
<field name="firstName" type="string" indexed="true" stored="true" />
<field name="lastName" type="string" indexed="true" stored="true"/>
<field name="title" type="string" indexed="true" stored="true"/>
<field name="fullName" type="string" indexed="true" stored="true"/>
<field name="state" type="string" indexed="true" stored="true" />
<field name="location" type="string" indexed="true" stored="true"/>
<field name="department" type="string" indexed="true" stored="true" />
<field name="phone" type="string" indexed="true" stored="true"/>
<field name="email" type="string" indexed="true" stored="true"/>
<field name="firstName" type="textgen" indexed="true" stored="true" />
<field name="lastName" type="textgen" indexed="true" stored="true"/>
<field name="title" type="textgen" indexed="true" stored="true"/>
<field name="fullName" type="textgen" indexed="true" stored="true"/>
<field name="state" type="textgen" indexed="true" stored="true" />
<field name="location" type="textgen" indexed="true" stored="true"/>
<field name="department" type="textgen" indexed="true" stored="true" />
<field name="phone" type="textgen" indexed="true" stored="true"/>
<field name="email" type="textgen" indexed="true" stored="true"/>
<field name="skills" type="textgen" indexed="true" stored="true"/>
<field name="interests" type="textgen" indexed="true" stored="true"/>
<field name="bio" type="textgen" indexed="true" stored="true"/>
<field name="facebook" type="textgen" indexed="false" stored="true"/>
<field name="linkedin" type="textgen" indexed="false" stored="true"/>
<field name="twitter" type="textgen" indexed="false" stored="true"/>
<field name="irc" type="textgen" indexed="true" stored="true"/>
<field name="picture" type="text" indexed="false" stored="true"/>
<field name="email2" type="textgen" indexed="true" stored="true"/>
<field name="phone2" type="textgen" indexed="true" stored="true"/>
<field name="permissions" type="string" indexed="false" stored="true"/>
<field name="user_credential" type="string" indexed="false" stored="true" />

<!-- <field name="id" type="string" indexed="true" stored="true" required="true" />
<field name="sku" type="textTight" indexed="true" stored="true" omitNorms="true"/>
<field name="name" type="textgen" indexed="true" stored="true"/>
Expand Down Expand Up @@ -531,22 +541,27 @@
<uniqueKey>uid</uniqueKey>

<!-- field for the QueryParser to use when an explicit fieldname is absent -->
<defaultSearchField>fullName</defaultSearchField>
<defaultSearchField>text</defaultSearchField>

<!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="OR"/>

<!-- copyField commands copy one field to another at the time a document
is added to the index. It's used either to index the same field differently,
or to add multiple fields to the same field for easier/faster searching. -->
<!--
<copyField source="cat" dest="text"/>
<copyField source="name" dest="text"/>
<copyField source="manu" dest="text"/>
<copyField source="features" dest="text"/>
<copyField source="includes" dest="text"/>
<copyField source="manu" dest="manu_exact"/>
-->

<copyField source="fullName" dest="text"/>
<copyField source="phone" dest="text"/>
<copyField source="title" dest="text"/>
<copyField source="location" dest="text"/>
<copyField source="department" dest="text"/>
<copyField source="email" dest="text"/>
<copyField source="skills" dest="text"/>
<copyField source="interests" dest="text"/>
<copyField source="irc" dest="text"/>
<copyField source="email2" dest="text"/>
<copyField source="phone2" dest="text"/>

<!-- Above, multiple source fields are copied to the [text] field.
Another way to map multiple source fields to the same
destination field is to use the dynamic field syntax.
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/gov/nysenate/opendirectory/ldap/Ldap.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,13 @@ public Person loadPerson(SearchResult record) throws NamingException {
person.setUid(getAttribute(attributes,"uid"));
person.setLocation(getAttribute(attributes,"l"));

TreeSet<String> cred_default = new TreeSet<String>();
cred_default.add("public");

person.setPermissions(Person.getDefaultPermissions());
person.setCredentials(cred_default);

String fullName = getAttribute(attributes,"displayname");
if (fullName!=null)
fullName = fullName.split("/")[0];

person.setFullName(fullName);

//Other person variables are set in SolrSession.java in AddPerson()
return person;
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/gov/nysenate/opendirectory/ldap/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ public static void main(String[] args) throws NamingException, SolrServerExcepti
SolrSession test_session = new SolrSession(Person.getAdmin(), test_solr);
Person result = new Person();
result = test_session.loadPersonByName("Jared\\ Williams");
TreeSet<String> temp = new TreeSet<String>();
temp.add("private");
TreeSet<String> skills= new TreeSet<String>();
skills.add("java");
skills.add("programming");

//result.getPermissions().get("uid").remove("private");
// //result.
//result.setSkills(skills);

//System.out.println(result.getPermissions().get("uid"));
//test_solr.delete("Jared\\ Williams");

System.out.println("deleted");

//test_session.savePerson(result);
test_session.savePerson(result);

// result = test_session.loadPersonByName("Jared\\ Williams");
result = test_session.loadPersonByName("Jared\\ Williams");

System.out.println(result.getLastName());
System.out.println(result.getLocation());
Expand All @@ -73,7 +75,7 @@ public static void main(String[] args) throws NamingException, SolrServerExcepti
System.out.println(result.getFullName());
System.out.println(result.getFirstName());
System.out.println(result.getPermissions());

System.out.println(result.getSkills());

/*SolrQuery query = new SolrQuery();
query.setQuery("id:codetes*");
Expand Down
97 changes: 84 additions & 13 deletions src/main/java/gov/nysenate/opendirectory/models/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,30 @@ public Person() {}
private TreeSet<String> credentials;
private HashMap<String,TreeSet<String>> permissions;

@Field
private TreeSet<String> skills;
private TreeSet<String> interests;

private String firstName;
@Field
private String lastName;
@Field
private String title;
@Field
private String uid;
@Field
private String fullName;
@Field
private String state;
@Field
private String location;
@Field
private String department;
@Field
private String phone;
@Field
private String email;


//additional Contact info
private String bio;
private String picture;
private String email2;
private String phone2;
private String twitter;
private String facebook;
private String linkedin;
private String IRC;

public String getFirstName() {
return firstName;
}
Expand Down Expand Up @@ -75,7 +77,36 @@ public HashMap<String, TreeSet<String>> getPermissions() {
public TreeSet<String> getCredentials(){
return credentials;
}

public String getBio(){
return bio;
}
public String getPic(){
return picture;
}
public String getLinkedin() {
return linkedin;
}
public String getFacebook() {
return facebook;
}
public String getTwitter() {
return twitter;
}
public String getPhone2() {
return phone2;
}
public String getEmail2() {
return email2;
}
public TreeSet<String> getInterests() {
return interests;
}
public TreeSet<String> getSkills() {
return skills;
}
public String getIRC() {
return IRC;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
Expand Down Expand Up @@ -113,7 +144,37 @@ public void setPermissions (HashMap<String, TreeSet<String>> permissions){
public void setCredentials (TreeSet<String> credentials){
this.credentials = credentials;
}

public void setBio(String bio){
this.bio = bio;
}
public void setPic(String picture){
this.picture = picture;
}
public void setSkills(TreeSet<String> skills) {
this.skills = skills;
}
public void setInterests(TreeSet<String> interests) {
this.interests = interests;
}
public void setEmail2(String email2) {
this.email2 = email2;
}
public void setPhone2(String phone2) {
this.phone2 = phone2;
}
public void setTwitter(String twitter) {
this.twitter = twitter;
}
public void setFacebook(String facebook) {
this.facebook = facebook;
}
public void setLinkedin(String linkedin) {
this.linkedin = linkedin;
}
public void setIRC(String iRC) {
IRC = iRC;
}

public String toString() {
StringBuilder out = new StringBuilder();
out.append(fullName+"("+uid+")");
Expand Down Expand Up @@ -252,6 +313,16 @@ public static HashMap<String,TreeSet<String>> getDefaultPermissions() {
permissions.put("fullName", cred_default);
permissions.put("lastName", cred_default);
permissions.put("location", cred_default);
permissions.put("bio", cred_default);
permissions.put("picture", cred_default);
permissions.put("email2", cred_default);
permissions.put("phone2", cred_default);
permissions.put("twitter", cred_default);
permissions.put("facebook", cred_default);
permissions.put("linkedin", cred_default);
permissions.put("irc", cred_default);
permissions.put("skills", cred_default);
permissions.put("interests", cred_default);


return permissions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ public Person loadPerson(SolrDocument profile) {
}
}
}

String fieldname = (String)fields.item(c).getAttributes().item(1).getNodeValue();
if(fieldname.equals("user_credential")) {

if(fieldname.equals("user_credential") || fieldname.equals("skills") || fieldname.equals("interests")) {
if(approved)
person.setCredentials(Credentials((String)profile.getFieldValue("user_credential")));
person.setCredentials(Credentials((String)profile.getFieldValue(fieldname)));
else
person.setCredentials(null);
} else if(fieldname.equals("permissions")){
Expand Down
52 changes: 48 additions & 4 deletions src/main/java/gov/nysenate/opendirectory/solr/SolrSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,38 @@ public ArrayList<Person> loadPeople() {
private void addPerson(Person person) throws SolrServerException, IOException {
SolrInputDocument solr_person = new SolrInputDocument();

//If this person is just being pulled in from LDAP and is going to be added into Solr
if(person.getPermissions()==null)
{
//Initialize the rest of the person variables
TreeSet<String> cred_default = new TreeSet<String>();
cred_default.add("public");

person.setPermissions(Person.getDefaultPermissions());
person.setCredentials(cred_default);

person.setBio("");
person.setEmail2("");
person.setPhone2("");
person.setTwitter("");
person.setFacebook("");
person.setLinkedin("");
person.setIRC("");
person.setSkills(null);
person.setInterests(null);
}

String permissions = Permissions(person.getPermissions());
String credentials = person.getCredentials().toString().substring(1, person.getCredentials().toString().length()-1);

String skills="";
String interests="";

if(person.getSkills()!=null)
skills = person.getSkills().toString().substring(1, person.getSkills().toString().length()-1);

if(person.getInterests()!=null)
interests = person.getInterests().toString().substring(1, person.getInterests().toString().length()-1);

solr_person.addField("otype", "person", 1.0f);
solr_person.addField("firstName", person.getFirstName(), 1.0f);
solr_person.addField("lastName", person.getLastName(), 1.0f);
Expand All @@ -106,9 +135,23 @@ private void addPerson(Person person) throws SolrServerException, IOException {
solr_person.addField("department", person.getDepartment(), 1.0f);
solr_person.addField("phone", person.getPhone(), 1.0f);
solr_person.addField("email", person.getEmail(), 1.0f);

solr_person.addField("permissions", permissions);
solr_person.addField("user_credential", credentials);



//additional contact info
solr_person.addField("bio", person.getBio(), 1.0f);
solr_person.addField("picture", person.getPic(), 1.0f);
solr_person.addField("email2", person.getEmail2(), 1.0f);
solr_person.addField("phone2", person.getPhone2(), 1.0f);
solr_person.addField("twitter", person.getTwitter(), 1.0f);
solr_person.addField("facebook", person.getFacebook(), 1.0f);
solr_person.addField("linkedin", person.getLinkedin(), 1.0f);
solr_person.addField("irc", person.getIRC(), 1.0f);
solr_person.addField("skills", skills, 1.0f);
solr_person.addField("interests", interests,1.0f);

solr.server.add(solr_person);
}

Expand All @@ -123,8 +166,9 @@ public void savePeople(Collection<Person> people) throws SolrServerException, I
}
solr.server.commit();
}

/* To be figured out... need to figure out annotations with Graylin

/* FOR DYNAMIC FIELDS
* To be figured out... need to figure out annotations with Graylin
* public AnnotatedField getAnnotatedField(Field field) {
org.apache.solr.client.solrj.beans.Field lf = field.getAnnotation(org.apache.solr.client.solrj.beans.Field.class);
if(lf != null) {
Expand Down

0 comments on commit 3b3d3b1

Please sign in to comment.