You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2009/07/04 14:44:49 UTC
svn commit: r791116 - in /lenya/branches/BRANCH_2_0_X/src:
impl/java/org/apache/lenya/cms/metadata/
impl/test/org/apache/lenya/cms/metadata/ java/org/apache/lenya/cms/metadata/
modules/lucene/java/src/org/apache/cocoon/components/search/components/impl...
Author: andreas
Date: Sat Jul 4 12:44:48 2009
New Revision: 791116
URL: http://svn.apache.org/viewvc?rev=791116&view=rev
Log:
Added support for meta data index types.
Modified:
lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java
lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java
lenya/branches/BRANCH_2_0_X/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java
lenya/branches/BRANCH_2_0_X/src/java/org/apache/lenya/cms/metadata/Element.java
lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/cocoon/components/search/components/impl/IndexManagerImpl.java
lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/MetaDataFieldRegistry.java
lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/impl/MetaDataFieldRegistryImpl.java
Modified: lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java Sat Jul 4 12:44:48 2009
@@ -30,6 +30,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.lenya.cms.metadata.Element.IndexType;
/**
* Avalon-based element set.
@@ -38,20 +39,23 @@
ThreadSafe, Initializable, Serviceable {
private String namespaceUri;
- private Map elements = new HashMap();
+ private Map<String, Element> elements = new HashMap<String, Element>();
public void configure(Configuration config) throws ConfigurationException {
this.namespaceUri = config.getAttribute("name");
- Configuration[] attributeConfigs = config.getChildren("element");
- for (int i = 0; i < attributeConfigs.length; i++) {
- String name = attributeConfigs[i].getAttribute("name");
- boolean isMultiple = attributeConfigs[i].getAttributeAsBoolean("multiple", false);
- boolean isEditable = attributeConfigs[i].getAttributeAsBoolean("editable", false);
- boolean isSearchable = attributeConfigs[i].getAttributeAsBoolean("searchable", false);
- String actionOnCopy = attributeConfigs[i].getAttribute("onCopy", "copy");
+ for (Configuration elemConfig : config.getChildren("element")) {
+ String name = elemConfig.getAttribute("name");
+ boolean isMultiple = elemConfig.getAttributeAsBoolean("multiple", false);
+ boolean isEditable = elemConfig.getAttributeAsBoolean("editable", false);
+ boolean isSearchable = elemConfig.getAttributeAsBoolean("searchable", false);
+ String actionOnCopy = elemConfig.getAttribute("onCopy", "copy");
ElementImpl element = new ElementImpl(name, isMultiple, isEditable, isSearchable);
+
+ String indexTypeString = elemConfig.getAttribute("indexType", "text");
+ element.setIndexType(getIndexType(indexTypeString));
+
int action;
if (actionOnCopy.equalsIgnoreCase("copy")) {
action = Element.ONCOPY_COPY;
@@ -75,8 +79,23 @@
}
+ protected IndexType getIndexType(String indexTypeString) throws ConfigurationException {
+ if (indexTypeString.equals("text")) {
+ return IndexType.TEXT;
+ }
+ else if (indexTypeString.equals("keyword")) {
+ return IndexType.KEYWORD;
+ }
+ else if (indexTypeString.equals("date")) {
+ return IndexType.DATE;
+ }
+ else {
+ throw new ConfigurationException("Unsupported index type: '" + indexTypeString + "'");
+ }
+ }
+
public Element[] getElements() {
- Collection values = this.elements.values();
+ Collection<Element> values = this.elements.values();
return (Element[]) values.toArray(new Element[values.size()]);
}
Modified: lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/impl/java/org/apache/lenya/cms/metadata/ElementImpl.java Sat Jul 4 12:44:48 2009
@@ -17,6 +17,8 @@
*/
package org.apache.lenya.cms.metadata;
+import org.apache.lenya.util.Assert;
+
/**
* Element implementation.
*/
@@ -28,6 +30,7 @@
private boolean editable;
private int actionOnCopy;
private boolean searchable;
+ private IndexType indexType;
/**
* Ctor.
@@ -87,5 +90,14 @@
public boolean isSearchable() {
return this.searchable;
}
+
+ public void setIndexType(IndexType indexType) {
+ Assert.notNull("index type", indexType);
+ this.indexType = indexType;
+ }
+
+ public IndexType getIndexType() {
+ return this.indexType;
+ }
}
Modified: lenya/branches/BRANCH_2_0_X/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/impl/test/org/apache/lenya/cms/metadata/MetaDataTest.java Sat Jul 4 12:44:48 2009
@@ -155,6 +155,10 @@
return false;
}
+ public IndexType getIndexType() {
+ return IndexType.TEXT;
+ }
+
}
protected class TestElementSet implements ElementSet {
Modified: lenya/branches/BRANCH_2_0_X/src/java/org/apache/lenya/cms/metadata/Element.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/java/org/apache/lenya/cms/metadata/Element.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/java/org/apache/lenya/cms/metadata/Element.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/java/org/apache/lenya/cms/metadata/Element.java Sat Jul 4 12:44:48 2009
@@ -22,6 +22,10 @@
*/
public interface Element {
+ enum IndexType {
+ KEYWORD, TEXT, DATE
+ }
+
/**
* @return the name of the element.
*/
@@ -46,7 +50,7 @@
* Copy all values if the meta data are copied.
*/
int ONCOPY_COPY = 0;
-
+
/**
* Don't copy the values of this element if the meta data are copied.
*/
@@ -61,10 +65,12 @@
* @return The action to be taken when meta data are copied from one owner to another.
*/
int getActionOnCopy();
-
+
/**
* @return If this element shall be included in search queries.
*/
boolean isSearchable();
+
+ IndexType getIndexType();
}
Modified: lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/cocoon/components/search/components/impl/IndexManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/cocoon/components/search/components/impl/IndexManagerImpl.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/cocoon/components/search/components/impl/IndexManagerImpl.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/cocoon/components/search/components/impl/IndexManagerImpl.java Sat Jul 4 12:44:48 2009
@@ -43,14 +43,10 @@
import org.apache.excalibur.source.SourceResolver;
import org.apache.excalibur.source.SourceUtil;
import org.apache.lenya.cms.cocoon.components.context.ContextUtility;
-import org.apache.lenya.cms.metadata.Element;
-import org.apache.lenya.cms.metadata.ElementSet;
import org.apache.lenya.cms.metadata.MetaDataException;
-import org.apache.lenya.cms.metadata.MetaDataRegistry;
import org.apache.lenya.cms.publication.DocumentFactory;
import org.apache.lenya.cms.publication.DocumentUtil;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.cms.publication.PublicationManager;
import org.apache.lenya.modules.lucene.MetaDataFieldRegistry;
@@ -111,8 +107,7 @@
/**
* type of the field: "text, "keyword", "date" (see
*
- * @see org.apache.cocoon.components.search.fieldmodel.FieldDefinition
- * class)
+ * @see org.apache.cocoon.components.search.fieldmodel.FieldDefinition class)
*/
public static final String TYPE_ATTRIBUTE = "type";
@@ -132,8 +127,8 @@
public static final String INDEX_CONF_FILE = "search/lucene_index.xml";
/**
- * check the config file each time the getIndex is called to update if
- * necessary the configuration
+ * check the config file each time the getIndex is called to update if necessary the
+ * configuration
*/
// public static final String CHECK_ATTRIBUTE = "check";
/**
@@ -141,8 +136,7 @@
*/
// public static final String CONFIG_ATTRIBUTE = "config";
/**
- * Check or not the configuration file (automatic update if the file is
- * changed)
+ * Check or not the configuration file (automatic update if the file is changed)
*/
// private boolean check;
/**
@@ -198,7 +192,9 @@
/*
* (non-Javadoc)
*
- * @see org.apache.cocoon.components.search.components.IndexManager#addIndex(org.apache.cocoon.components.search.Index)
+ * @see
+ * org.apache.cocoon.components.search.components.IndexManager#addIndex(org.apache.cocoon.components
+ * .search.Index)
*/
public void addIndex(Index base) {
this.indexes().put(base.getID(), base);
@@ -263,7 +259,9 @@
/*
* (non-Javadoc)
*
- * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ * @see
+ * org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework
+ * .configuration.Configuration)
*/
public void configure(Configuration configuration) throws ConfigurationException {
this.indexerRole = configuration.getChild(INDEXER_ELEMENT).getAttribute(
@@ -317,12 +315,13 @@
IndexStructure docdecl = new IndexStructure();
addMetaDataFieldDefinitions(registry, docdecl);
-
+
FieldDefinition uuidDef = FieldDefinition.create("uuid", FieldDefinition.KEYWORD);
uuidDef.setStore(true);
docdecl.addFieldDef(uuidDef);
- FieldDefinition langDef = FieldDefinition.create("language", FieldDefinition.KEYWORD);
+ FieldDefinition langDef = FieldDefinition.create("language",
+ FieldDefinition.KEYWORD);
langDef.setStore(true);
docdecl.addFieldDef(langDef);
@@ -400,11 +399,8 @@
protected void addMetaDataFieldDefinitions(MetaDataFieldRegistry registry,
IndexStructure indexStructure) throws MetaDataException {
- String[] fieldNames = registry.getFieldNames();
- for (int i = 0; i < fieldNames.length; i++) {
- FieldDefinition fieldDef = FieldDefinition.create(fieldNames[i], FieldDefinition.TEXT);
- fieldDef.setStore(false);
- indexStructure.addFieldDef(fieldDef);
+ for (FieldDefinition def : registry.getFieldDefinitions()) {
+ indexStructure.addFieldDef(def);
}
}
@@ -435,6 +431,7 @@
/*
* (non-Javadoc)
+ *
* @see org.apache.cocoon.components.search.components.IndexManager#getIndex()
*/
public Index[] getIndex() {
@@ -443,7 +440,10 @@
/*
* (non-Javadoc)
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ *
+ * @see
+ * org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service
+ * .ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
Modified: lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/MetaDataFieldRegistry.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/MetaDataFieldRegistry.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/MetaDataFieldRegistry.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/MetaDataFieldRegistry.java Sat Jul 4 12:44:48 2009
@@ -16,6 +16,10 @@
*/
package org.apache.lenya.modules.lucene;
+import java.util.Set;
+
+import org.apache.cocoon.components.search.fieldmodel.FieldDefinition;
+
/**
* Map meta data elements to Lucene index fields.
*/
@@ -37,5 +41,7 @@
* @return All field names.
*/
String[] getFieldNames();
+
+ Set<FieldDefinition> getFieldDefinitions();
}
Modified: lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/impl/MetaDataFieldRegistryImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/impl/MetaDataFieldRegistryImpl.java?rev=791116&r1=791115&r2=791116&view=diff
==============================================================================
--- lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/impl/MetaDataFieldRegistryImpl.java (original)
+++ lenya/branches/BRANCH_2_0_X/src/modules/lucene/java/src/org/apache/lenya/modules/lucene/impl/MetaDataFieldRegistryImpl.java Sat Jul 4 12:44:48 2009
@@ -16,6 +16,7 @@
*/
package org.apache.lenya.modules.lucene.impl;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -26,6 +27,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.search.fieldmodel.FieldDefinition;
import org.apache.lenya.cms.metadata.Element;
import org.apache.lenya.cms.metadata.ElementSet;
import org.apache.lenya.cms.metadata.MetaDataRegistry;
@@ -99,4 +101,39 @@
return (String[]) fieldNames.toArray(new String[fieldNames.size()]);
}
+ public Set<FieldDefinition> getFieldDefinitions() {
+ final MetaDataRegistry registry = getRegistry();
+ final Set<FieldDefinition> fieldDefs = new HashSet<FieldDefinition>();
+ try {
+ final String[] namespaces = registry.getNamespaceUris();
+ for (int n = 0; n < namespaces.length; n++) {
+ final ElementSet elementSet = registry.getElementSet(namespaces[n]);
+ final Element[] elements = elementSet.getElements();
+ for (int e = 0; e < elements.length; e++) {
+ final String fieldName = getFieldName(namespaces[n], elements[e].getName());
+ final FieldDefinition fieldDef = FieldDefinition.create(fieldName,
+ getFieldType(elements[e].getIndexType()));
+ fieldDef.setStore(false);
+ fieldDefs.add(fieldDef);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return Collections.unmodifiableSet(fieldDefs);
+ }
+
+ protected int getFieldType(Element.IndexType indexType) {
+ switch (indexType) {
+ case TEXT:
+ return FieldDefinition.TEXT;
+ case KEYWORD:
+ return FieldDefinition.KEYWORD;
+ case DATE:
+ return FieldDefinition.DATE;
+ default:
+ throw new IllegalArgumentException("Unsupported index type: " + indexType);
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org