mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Added the following community contribution from Ray Gauss II "Add configuration to allow basic search to be changed to search X, Y, Z attributes by default."
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5649 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -123,6 +123,9 @@ public final class SearchContext implements Serializable
|
|||||||
/** content mimetype to restrict search against */
|
/** content mimetype to restrict search against */
|
||||||
private String mimeType = null;
|
private String mimeType = null;
|
||||||
|
|
||||||
|
/** any extra simple query attributes to add to the search */
|
||||||
|
protected List<QName> simpleSearchAdditionalAttrs = new ArrayList<QName>(4);
|
||||||
|
|
||||||
/** any extra query attributes to add to the search */
|
/** any extra query attributes to add to the search */
|
||||||
private Map<QName, String> queryAttributes = new HashMap<QName, String>(5, 1.0f);
|
private Map<QName, String> queryAttributes = new HashMap<QName, String>(5, 1.0f);
|
||||||
|
|
||||||
@@ -159,7 +162,17 @@ public final class SearchContext implements Serializable
|
|||||||
String text = this.text.trim();
|
String text = this.text.trim();
|
||||||
|
|
||||||
StringBuilder fullTextBuf = new StringBuilder(64);
|
StringBuilder fullTextBuf = new StringBuilder(64);
|
||||||
StringBuilder nameAttrBuf = new StringBuilder(64);
|
StringBuilder nameAttrBuf = new StringBuilder(128);
|
||||||
|
StringBuilder additionalAttrsBuf = new StringBuilder(128);
|
||||||
|
|
||||||
|
/*Map<QName, StringBuilder> simpleAdditionalAttrBufs = new HashMap<QName, StringBuilder>();
|
||||||
|
if (this.simpleSearchAdditionalAttrs != null)
|
||||||
|
{
|
||||||
|
for (QName qName : this.simpleSearchAdditionalAttrs)
|
||||||
|
{
|
||||||
|
simpleAdditionalAttrBufs.put(qName, new StringBuilder(64));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
if (text.length() != 0 && text.length() >= minimum)
|
if (text.length() != 0 && text.length() >= minimum)
|
||||||
{
|
{
|
||||||
@@ -181,9 +194,14 @@ public final class SearchContext implements Serializable
|
|||||||
{
|
{
|
||||||
fullTextBuf.append(OP_NOT);
|
fullTextBuf.append(OP_NOT);
|
||||||
nameAttrBuf.append(OP_NOT);
|
nameAttrBuf.append(OP_NOT);
|
||||||
|
additionalAttrsBuf.append(OP_NOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
processSearchTextAttribute(nameAttr, text, nameAttrBuf, fullTextBuf);
|
processSearchTextAttribute(nameAttr, text, nameAttrBuf, fullTextBuf);
|
||||||
|
for (QName qname : this.simpleSearchAdditionalAttrs)
|
||||||
|
{
|
||||||
|
processSearchAttribute(qname, text, additionalAttrsBuf, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -195,6 +213,11 @@ public final class SearchContext implements Serializable
|
|||||||
String quotedSafeText = '"' + QueryParser.escape(text.substring(1, text.length() - 1)) + '"';
|
String quotedSafeText = '"' + QueryParser.escape(text.substring(1, text.length() - 1)) + '"';
|
||||||
fullTextBuf.append("TEXT:").append(quotedSafeText);
|
fullTextBuf.append("TEXT:").append(quotedSafeText);
|
||||||
nameAttrBuf.append("@").append(nameAttr).append(":").append(quotedSafeText);
|
nameAttrBuf.append("@").append(nameAttr).append(":").append(quotedSafeText);
|
||||||
|
for (QName qname : this.simpleSearchAdditionalAttrs)
|
||||||
|
{
|
||||||
|
additionalAttrsBuf.append(" @").append(
|
||||||
|
Repository.escapeQName(qname)).append(":").append(quotedSafeText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -203,6 +226,7 @@ public final class SearchContext implements Serializable
|
|||||||
|
|
||||||
fullTextBuf.append('(');
|
fullTextBuf.append('(');
|
||||||
nameAttrBuf.append('(');
|
nameAttrBuf.append('(');
|
||||||
|
additionalAttrsBuf.append('(');
|
||||||
|
|
||||||
int termCount = 0;
|
int termCount = 0;
|
||||||
int tokenCount = t.countTokens();
|
int tokenCount = t.countTokens();
|
||||||
@@ -233,6 +257,7 @@ public final class SearchContext implements Serializable
|
|||||||
{
|
{
|
||||||
fullTextBuf.append("OR ");
|
fullTextBuf.append("OR ");
|
||||||
nameAttrBuf.append("OR ");
|
nameAttrBuf.append("OR ");
|
||||||
|
additionalAttrsBuf.append("OR ");
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepend NOT operator if supplied
|
// prepend NOT operator if supplied
|
||||||
@@ -240,24 +265,33 @@ public final class SearchContext implements Serializable
|
|||||||
{
|
{
|
||||||
fullTextBuf.append(OP_NOT);
|
fullTextBuf.append(OP_NOT);
|
||||||
nameAttrBuf.append(OP_NOT);
|
nameAttrBuf.append(OP_NOT);
|
||||||
|
additionalAttrsBuf.append(OP_NOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepend AND operator if supplied
|
// prepend AND operator if supplied
|
||||||
if (operatorAND)
|
if (operatorAND)
|
||||||
{
|
{
|
||||||
fullTextBuf.append(OP_AND);
|
fullTextBuf.append(OP_AND);
|
||||||
nameAttrBuf.append(OP_AND);
|
nameAttrBuf.append(OP_AND);
|
||||||
|
additionalAttrsBuf.append(OP_AND);
|
||||||
}
|
}
|
||||||
|
|
||||||
processSearchTextAttribute(nameAttr, term, nameAttrBuf, fullTextBuf);
|
processSearchTextAttribute(nameAttr, term, nameAttrBuf, fullTextBuf);
|
||||||
|
for (QName qname : this.simpleSearchAdditionalAttrs)
|
||||||
|
{
|
||||||
|
processSearchAttribute(qname, term, additionalAttrsBuf, false);
|
||||||
|
}
|
||||||
|
|
||||||
fullTextBuf.append(' ');
|
fullTextBuf.append(' ');
|
||||||
nameAttrBuf.append(' ');
|
nameAttrBuf.append(' ');
|
||||||
|
additionalAttrsBuf.append(' ');
|
||||||
|
|
||||||
termCount++;
|
termCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fullTextBuf.append(')');
|
fullTextBuf.append(')');
|
||||||
nameAttrBuf.append(')');
|
nameAttrBuf.append(')');
|
||||||
|
additionalAttrsBuf.append(')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,14 +422,16 @@ public final class SearchContext implements Serializable
|
|||||||
|
|
||||||
String fullTextQuery = fullTextBuf.toString();
|
String fullTextQuery = fullTextBuf.toString();
|
||||||
String nameAttrQuery = nameAttrBuf.toString();
|
String nameAttrQuery = nameAttrBuf.toString();
|
||||||
|
String additionalAttrsQuery = additionalAttrsBuf.toString();
|
||||||
|
|
||||||
if (text.length() != 0 && text.length() >= minimum)
|
if (text.length() != 0 && text.length() >= minimum)
|
||||||
{
|
{
|
||||||
// text query for name and/or full text specified
|
// text query for name and/or full text specified
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case SearchContext.SEARCH_ALL:
|
case SearchContext.SEARCH_ALL:
|
||||||
query = '(' + fileTypeQuery + " AND " + '(' + nameAttrQuery + ' ' + fullTextQuery + ')' + ')' + " OR " +
|
query = '(' + fileTypeQuery + " AND " + '(' + nameAttrQuery + ' ' + additionalAttrsQuery + ' ' + fullTextQuery + ')' + ')' + " OR " +
|
||||||
'(' + folderTypeQuery + " AND " + nameAttrQuery + ')';
|
'(' + folderTypeQuery + " AND " + nameAttrQuery + ' ' + additionalAttrsQuery + ')';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SearchContext.SEARCH_FILE_NAMES:
|
case SearchContext.SEARCH_FILE_NAMES:
|
||||||
@@ -472,6 +508,20 @@ public final class SearchContext implements Serializable
|
|||||||
* @param buf Buffer to append lucene terms to
|
* @param buf Buffer to append lucene terms to
|
||||||
*/
|
*/
|
||||||
private static void processSearchAttribute(QName qname, String value, StringBuilder buf)
|
private static void processSearchAttribute(QName qname, String value, StringBuilder buf)
|
||||||
|
{
|
||||||
|
processSearchAttribute(qname, value, buf, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the lucene search terms required for the specified attribute and append to a buffer.
|
||||||
|
* Supports text values with a wildcard '*' character as the prefix and/or the suffix.
|
||||||
|
*
|
||||||
|
* @param qname QName of the attribute
|
||||||
|
* @param value Non-null value of the attribute
|
||||||
|
* @param buf Buffer to append lucene terms to
|
||||||
|
* @param andOp If true apply the '+' AND operator as the prefix to the attribute term
|
||||||
|
*/
|
||||||
|
private static void processSearchAttribute(QName qname, String value, StringBuilder buf, boolean andOp)
|
||||||
{
|
{
|
||||||
if (value.indexOf(' ') == -1)
|
if (value.indexOf(' ') == -1)
|
||||||
{
|
{
|
||||||
@@ -510,14 +560,16 @@ public final class SearchContext implements Serializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.append(" +@").append(Repository.escapeQName(qname)).append(":")
|
if (andOp) buf.append('+');
|
||||||
.append(prefix).append(safeValue).append(suffix);
|
buf.append('@').append(Repository.escapeQName(qname)).append(":")
|
||||||
|
.append(prefix).append(safeValue).append(suffix).append(' ');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// phrase multi-word search
|
// phrase multi-word search
|
||||||
String safeValue = QueryParser.escape(value);
|
String safeValue = QueryParser.escape(value);
|
||||||
buf.append(" +@").append(Repository.escapeQName(qname)).append(":\"").append(safeValue).append('"');
|
if (andOp) buf.append('+');
|
||||||
|
buf.append('@').append(Repository.escapeQName(qname)).append(":\"").append(safeValue).append('"').append(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,6 +785,27 @@ public final class SearchContext implements Serializable
|
|||||||
this.mimeType = mimeType;
|
this.mimeType = mimeType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an additional attribute to search against for simple searches
|
||||||
|
*
|
||||||
|
* @param qname QName of the attribute to search against
|
||||||
|
* @param value Value of the attribute to use
|
||||||
|
*/
|
||||||
|
public void addSimpleAttributeQuery(QName qname)
|
||||||
|
{
|
||||||
|
this.simpleSearchAdditionalAttrs.add(qname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the additional attribute to search against for simple searches.
|
||||||
|
*
|
||||||
|
* @param attrs The list of attributes to search against
|
||||||
|
*/
|
||||||
|
public void setSimpleSearchAdditionalAttributes(List<QName> attrs)
|
||||||
|
{
|
||||||
|
this.simpleSearchAdditionalAttrs = attrs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an additional attribute to search against
|
* Add an additional attribute to search against
|
||||||
*
|
*
|
||||||
|
@@ -24,6 +24,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.web.config;
|
package org.alfresco.web.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
|
|
||||||
import org.alfresco.config.ConfigElement;
|
import org.alfresco.config.ConfigElement;
|
||||||
@@ -31,6 +33,7 @@ import org.alfresco.config.JNDIConstants;
|
|||||||
import org.alfresco.config.element.ConfigElementAdapter;
|
import org.alfresco.config.element.ConfigElementAdapter;
|
||||||
import org.alfresco.mbeans.VirtServerRegistry;
|
import org.alfresco.mbeans.VirtServerRegistry;
|
||||||
import org.alfresco.repo.cache.ExpiringValueCache;
|
import org.alfresco.repo.cache.ExpiringValueCache;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.web.bean.repository.Repository;
|
import org.alfresco.web.bean.repository.Repository;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -68,6 +71,7 @@ public class ClientConfigElement extends ConfigElementAdapter
|
|||||||
private boolean clipboardStatusVisible = true;
|
private boolean clipboardStatusVisible = true;
|
||||||
private boolean pasteAllAndClear = true;
|
private boolean pasteAllAndClear = true;
|
||||||
private boolean allowGuestConfig = false;
|
private boolean allowGuestConfig = false;
|
||||||
|
private List<QName> simpleSearchAdditionalAttributes = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
@@ -204,6 +208,12 @@ public class ClientConfigElement extends ConfigElementAdapter
|
|||||||
combinedElement.setAllowGuestConfig(newElement.getAllowGuestConfig());
|
combinedElement.setAllowGuestConfig(newElement.getAllowGuestConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newElement.getSimpleSearchAdditionalAttributes() != null &&
|
||||||
|
newElement.getSimpleSearchAdditionalAttributes().equals(combinedElement.getSimpleSearchAdditionalAttributes()) == false)
|
||||||
|
{
|
||||||
|
combinedElement.setSimpleSearchAdditionalAttributes(newElement.getSimpleSearchAdditionalAttributes());
|
||||||
|
}
|
||||||
|
|
||||||
return combinedElement;
|
return combinedElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,4 +557,20 @@ public class ClientConfigElement extends ConfigElementAdapter
|
|||||||
{
|
{
|
||||||
return this.allowGuestConfig;
|
return this.allowGuestConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the additional attributes to search on a simple search
|
||||||
|
*/
|
||||||
|
public List<QName> getSimpleSearchAdditionalAttributes()
|
||||||
|
{
|
||||||
|
return this.simpleSearchAdditionalAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param simpleSearchAdditionalAttributes The additional simple search attributes
|
||||||
|
*/
|
||||||
|
/*package*/ void setSimpleSearchAdditionalAttributes(List<QName> simpleSearchAdditionalAttributes)
|
||||||
|
{
|
||||||
|
this.simpleSearchAdditionalAttributes = simpleSearchAdditionalAttributes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,9 +24,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.web.config;
|
package org.alfresco.web.config;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.config.ConfigElement;
|
import org.alfresco.config.ConfigElement;
|
||||||
import org.alfresco.config.ConfigException;
|
import org.alfresco.config.ConfigException;
|
||||||
import org.alfresco.config.xml.elementreader.ConfigElementReader;
|
import org.alfresco.config.xml.elementreader.ConfigElementReader;
|
||||||
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,6 +59,8 @@ public class ClientElementReader implements ConfigElementReader
|
|||||||
public static final String ELEMENT_CLIPBOARDSTATUS = "clipboard-status-visible";
|
public static final String ELEMENT_CLIPBOARDSTATUS = "clipboard-status-visible";
|
||||||
public static final String ELEMENT_PASTEALLANDCLEAR = "paste-all-and-clear";
|
public static final String ELEMENT_PASTEALLANDCLEAR = "paste-all-and-clear";
|
||||||
public static final String ELEMENT_GUESTCONFIG = "allow-guest-config";
|
public static final String ELEMENT_GUESTCONFIG = "allow-guest-config";
|
||||||
|
public static final String ELEMENT_SIMPLESEARCHADDITIONALATTRS = "simple-search-additional-attributes";
|
||||||
|
public static final String ELEMENT_SIMPLESEARCHADDITIONALATTRSQNAME = "qname";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
* @see org.alfresco.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
|
||||||
@@ -160,7 +167,7 @@ public class ClientElementReader implements ConfigElementReader
|
|||||||
configElement.setLoginPage(loginPage.getTextTrim());
|
configElement.setLoginPage(loginPage.getTextTrim());
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the ajax enabled flag
|
// get the node summary popup enabled flag
|
||||||
Element ajaxEnabled = element.element(ELEMENT_NODESUMMARY_ENABLED);
|
Element ajaxEnabled = element.element(ELEMENT_NODESUMMARY_ENABLED);
|
||||||
if (ajaxEnabled != null)
|
if (ajaxEnabled != null)
|
||||||
{
|
{
|
||||||
@@ -204,6 +211,23 @@ public class ClientElementReader implements ConfigElementReader
|
|||||||
boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim());
|
boolean allow = Boolean.parseBoolean(guestConfigElement.getTextTrim());
|
||||||
configElement.setAllowGuestConfig(allow);
|
configElement.setAllowGuestConfig(allow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get the additional simple search attributes
|
||||||
|
Element simpleSearchAdditionalAttributesElement = element.element(ELEMENT_SIMPLESEARCHADDITIONALATTRS);
|
||||||
|
if (simpleSearchAdditionalAttributesElement != null)
|
||||||
|
{
|
||||||
|
List<Element> attrbElements =
|
||||||
|
simpleSearchAdditionalAttributesElement.elements(ELEMENT_SIMPLESEARCHADDITIONALATTRSQNAME);
|
||||||
|
if (attrbElements != null && attrbElements.size() != 0)
|
||||||
|
{
|
||||||
|
List<QName> simpleSearchAddtlAttrb = new ArrayList<QName>(4);
|
||||||
|
for (Element elem : attrbElements)
|
||||||
|
{
|
||||||
|
simpleSearchAddtlAttrb.add(QName.createQName(elem.getTextTrim()));
|
||||||
|
}
|
||||||
|
configElement.setSimpleSearchAdditionalAttributes(simpleSearchAddtlAttrb);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return configElement;
|
return configElement;
|
||||||
|
@@ -42,6 +42,7 @@ import org.alfresco.web.bean.SearchContext;
|
|||||||
import org.alfresco.web.ui.common.Utils;
|
import org.alfresco.web.ui.common.Utils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Kevin Roast
|
* @author Kevin Roast
|
||||||
*/
|
*/
|
||||||
@@ -151,6 +152,7 @@ public class UISimpleSearch extends UICommand
|
|||||||
context.setText(searchEvent.SearchText);
|
context.setText(searchEvent.SearchText);
|
||||||
context.setMode(searchEvent.SearchMode);
|
context.setMode(searchEvent.SearchMode);
|
||||||
context.setForceAndTerms(Application.getClientConfig(fc).getForceAndTerms());
|
context.setForceAndTerms(Application.getClientConfig(fc).getForceAndTerms());
|
||||||
|
context.setSimpleSearchAdditionalAttributes(Application.getClientConfig(fc).getSimpleSearchAdditionalAttributes());
|
||||||
this.search = context;
|
this.search = context;
|
||||||
|
|
||||||
super.broadcast(event);
|
super.broadcast(event);
|
||||||
|
Reference in New Issue
Block a user