[seam-commits] Seam SVN: r7497 - in trunk/examples/wiki: src/main/org/jboss/seam/wiki/core/search and 3 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Sun Mar 2 07:56:32 EST 2008


Author: christian.bauer at jboss.com
Date: 2008-03-02 07:56:31 -0500 (Sun, 02 Mar 2008)
New Revision: 7497

Modified:
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiNode.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearch.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearchSupport.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/Searchable.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/SearchableType.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchRegistry.java
   trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchableProperty.java
   trunk/examples/wiki/view/search_d.xhtml
Log:
Added createdBy/lastModifiedBy to indexed and searchable fields

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/User.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -18,6 +18,7 @@
 @Entity
 @Table(name = "USERS")
 @org.hibernate.annotations.BatchSize(size = 20)
+ at org.hibernate.search.annotations.Indexed
 public class User implements Serializable {
 
     public static final String GUEST_USERNAME = "guest";
@@ -26,6 +27,7 @@
     @Id
     @GeneratedValue(generator = "wikiSequenceGenerator")
     @Column(name = "USER_ID")
+    @org.hibernate.search.annotations.DocumentId(name = "userId")
     private Long id = null;
 
     @Version
@@ -57,6 +59,10 @@
         regex="[a-zA-Z]?[a-zA-Z0-9]+",
         message="#{messages['lacewiki.entity.UsernameMustStartWithALetterAndOnlyContainLetters']}"
     )
+    @org.hibernate.search.annotations.Field(
+        index = org.hibernate.search.annotations.Index.UN_TOKENIZED,
+        store = org.hibernate.search.annotations.Store.YES
+    )
     private String username; // Unique and immutable
 
     @Column(name = "PASSWORDHASH", length = 255, nullable = false)
@@ -102,6 +108,10 @@
     @org.hibernate.annotations.ForeignKey(name = "FK_USER_USER_PROFILE_ID")
     private UserProfile profile = new UserProfile();
 
+    @OneToMany(fetch = FetchType.LAZY, mappedBy="createdBy")
+    @org.hibernate.search.annotations.ContainedIn
+    private Set<WikiNode> createdNodes; // Just for Lucene index updates of username @Field
+
     @Transient
     private long ratingPoints = 0;
 

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiNode.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiNode.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/model/WikiNode.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -70,6 +70,8 @@
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "CREATED_BY_USER_ID", nullable = false)
     @org.hibernate.annotations.ForeignKey(name = "FK_WIKI_NODE_CREATED_BY_USER_ID")
+    @org.hibernate.search.annotations.IndexedEmbedded(prefix = "createdBy_")
+    @Searchable(description = "Created By", type = SearchableType.STRING, embeddedProperty = "username")
     protected User createdBy;
 
     @Column(name = "LAST_MODIFIED_ON", nullable = true)
@@ -78,12 +80,14 @@
         store = org.hibernate.search.annotations.Store.YES
     )
     @org.hibernate.search.annotations.DateBridge(resolution = org.hibernate.search.annotations.Resolution.DAY)
-    @Searchable(description = "Modified", type = SearchableType.PASTDATE)
+    @Searchable(description = "Last Modified", type = SearchableType.PASTDATE)
     protected Date lastModifiedOn;
 
     @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "LAST_MODIFIED_BY_USER_ID", nullable = true)
     @org.hibernate.annotations.ForeignKey(name = "FK_WIKI_NODE_LAST_MODIFIED_BY")
+    @org.hibernate.search.annotations.IndexedEmbedded(prefix = "lastModifiedBy_")
+    @Searchable(description = "Last Modified By", type = SearchableType.STRING, embeddedProperty = "username")
     protected User lastModifiedBy;
 
     @Column(name = "WRITE_ACCESS_LEVEL", nullable = false)

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearch.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearch.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearch.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -109,6 +109,10 @@
                         propertySearch.getTerms().put(SearchableProperty.TERM_MATCHEXACTPHRASE, getSimpleQueryMatchExactPhrase());
                         searchEntities.add(entry.getKey());
                     }
+                    // And also simple string queries get the term
+                    if (SearchableType.STRING.equals(propertySearch.getProperty().getType())) {
+                        propertySearch.getTerms().put(SearchableProperty.TERM_INCLUDE, getSimpleQuery());
+                    }
                 }
             }
 

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearchSupport.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearchSupport.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/WikiSearchSupport.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -37,7 +37,7 @@
                         return new SearchHit(
                             WikiDocument.class.getSimpleName(),
                             "icon.doc.gif",
-                            escapeBestFragments(query, new NullFragmenter(), doc.getName(), 0, 0),
+                            "(" + doc.getCreatedBy().getFullname() + ") " + escapeBestFragments(query, new NullFragmenter(), doc.getName(), 0, 0),
                             urlRenderer.renderURL(doc),
                             escapeBestFragments(query, new SimpleFragmenter(100), doc.getContent(), 5, 350)
                         );
@@ -52,7 +52,7 @@
                         return new SearchHit(
                             WikiComment.class.getSimpleName(),
                             "icon.user.gif",
-                            "(" + comment.getFromUserName() + ") "
+                            "(" + (comment.getCreatedBy() != null ? comment.getCreatedBy().getFullname() : comment.getFromUserName()) + ") "
                                 + escapeBestFragments(query, new NullFragmenter(), comment.getSubject(), 0, 0),
                             urlRenderer.renderURL(comment),
                             escapeBestFragments(query, new SimpleFragmenter(100), comment.getContent(), 5, 350)

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/Searchable.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/Searchable.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/Searchable.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -24,4 +24,5 @@
 public @interface Searchable {
     String description();
     SearchableType type() default SearchableType.PHRASE;
+    String embeddedProperty() default "";
 }

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/SearchableType.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/SearchableType.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/annotations/SearchableType.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -8,5 +8,5 @@
  * @author Christian Bauer
  */
 public enum SearchableType {
-    PHRASE, PASTDATE, NUMRANGE
+    PHRASE, STRING, PASTDATE, NUMRANGE
 }

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchRegistry.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchRegistry.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchRegistry.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -110,6 +110,24 @@
             searchableEntity.getProperties().add(property);
         }
 
+        // @Searchable and embedded indexed getters
+        for (Method method : getGetters(entityClass, Searchable.class, org.hibernate.search.annotations.IndexedEmbedded.class)) {
+
+            String prefix = method.getAnnotation(org.hibernate.search.annotations.IndexedEmbedded.class).prefix();
+            propertyName = prefix + method.getAnnotation(Searchable.class).embeddedProperty();
+            if (propertyName.length() == 0)
+                throw new RuntimeException("@IndexedEmbedded requires @Searchable(embeddedProperty) name on entity " + entityClass.getName());
+            propertyDescription = method.getAnnotation(Searchable.class).description();
+            type = method.getAnnotation(Searchable.class).type();
+
+            SearchableProperty property = new SearchablePropertySingle(
+                    propertyName,
+                    propertyDescription,
+                    type
+            );
+            searchableEntity.getProperties().add(property);
+        }
+
         // @Searchable fields
         for (Field field : getFields(entityClass, Searchable.class, org.hibernate.search.annotations.Field.class)) {
             indexFieldName = field.getAnnotation(org.hibernate.search.annotations.Field.class).name();
@@ -126,6 +144,24 @@
 
         }
 
+        // @Searchable and embedded indexed fields
+        for (Field field : getFields(entityClass, Searchable.class, org.hibernate.search.annotations.IndexedEmbedded.class)) {
+            String prefix = field.getAnnotation(org.hibernate.search.annotations.IndexedEmbedded.class).prefix();
+            propertyName = prefix + field.getAnnotation(Searchable.class).embeddedProperty();
+            if (propertyName.length() == 0)
+                throw new RuntimeException("@IndexedEmbedded requires @Searchable(embeddedProperty) name on entity " + entityClass.getName());
+            propertyDescription = field.getAnnotation(Searchable.class).description();
+            type = field.getAnnotation(Searchable.class).type();
+
+            SearchableProperty property = new SearchablePropertySingle(
+                    propertyName,
+                    propertyDescription,
+                    type
+            );
+            searchableEntity.getProperties().add(property);
+
+        }
+
         return searchableEntity;
     }
 

Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchableProperty.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchableProperty.java	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/search/metamodel/SearchableProperty.java	2008-03-02 12:56:31 UTC (rev 7497)
@@ -102,7 +102,16 @@
 
                 query = buildRangeQuery(fieldName, df.format(startDate.getTime()), df.format(today.getTime()));
             }
+        } else if (getType().equals(SearchableType.STRING)) {
+
+            String includeString = (String)search.getTerms().get(TERM_INCLUDE);
+            if (includeString != null && includeString.length() >0) {
+                log.debug("building include term query for field: " + fieldName);
+                query = buildTermQuery(fieldName, includeString);
+            }
         }
+
+
         return query;
     }
 

Modified: trunk/examples/wiki/view/search_d.xhtml
===================================================================
--- trunk/examples/wiki/view/search_d.xhtml	2008-02-29 12:50:52 UTC (rev 7496)
+++ trunk/examples/wiki/view/search_d.xhtml	2008-03-02 12:56:31 UTC (rev 7497)
@@ -125,6 +125,10 @@
                                 </h:selectOneMenu>
                             </s:div>
 
+                            <h:panelGrid columns="5" rendered="#{search.property.type == 'STRING'}">
+                                <h:inputText value="#{search.terms['include']}" size="32" tabindex="1"/>
+                            </h:panelGrid>
+
                         </h:column>
 
                     </h:dataTable>




More information about the seam-commits mailing list