Alfresco API 到 运行 分面搜索

Alfresco API to run faceted search

我正在使用 Alfresco 社区 5.x 版本,我想知道是否有 REST 或任何其他远程 alfresco api 能够 运行 多面搜索。
我已经看到一些 Restful API 到 administer/manage 多面搜索的某些方面,即:http://docs.alfresco.com/community5.0/references/RESTful-Facet.html
但是没有 public API 到 运行 分面搜索。

我确实注意到 alfresco share 针对 运行 其分面搜索针对核心 alfresco 服务触发了以下命令;但找不到任何与此相关的 notes/docs -

http://alfresco.mycompany.com/alfresco/s/slingshot/search
?facetFields={http://www.alfresco.org/model/content/1.0}creator,
{http://www.alfresco.org/model/content/1.0}content.mimetype,
{http://www.alfresco.org/model/content/1.0}created,
{http://www.alfresco.org/model/content/1.0}content.size,
{http://www.alfresco.org/model/content/1.0}modifier,
{http://www.alfresco.org/model/content/1.0}modified
&filters=
&term=wal
&tag=
&startIndex=0
&sort=
&site=
&rootNode=alfresco://company/home
&repo=false
&query=
&pageSize=25
&maxResults=0
&noCache=1455504682131
&spellcheck=true&

我们在自定义内部应用程序中与 Alfresco 进行了基于 API 的集成,但不使用 Alfresco Share。 我不确定我是否应该使用上面的 url 。 对此有何建议?

谢谢!

Alfresco 版本:5.0.d

您可以使用默认搜索网页脚本:

webscripts\org\alfresco\slingshot\search\search.get.js

如果您查看代码:

   var params =
   {
      siteId: args.site,
      containerId: args.container,
      repo: (args.repo !== null) ? (args.repo == "true") : false,
      term: args.term,
      tag: args.tag,
      query: args.query,
      rootNode: args.rootNode,
      sort: args.sort,
      maxResults: (args.maxResults !== null) ? parseInt(args.maxResults, 10) : DEFAULT_MAX_RESULTS,
      pageSize: (args.pageSize !== null) ? parseInt(args.pageSize, 10) : DEFAULT_PAGE_SIZE,
      startIndex: (args.startIndex !== null) ? parseInt(args.startIndex, 10) : 0,
      facetFields: args.facetFields,
      filters: args.filters,
      spell: (args.spellcheck !== null) ? (args.spellcheck == "true") : false
   };

因此,如果您提供正确的论据和要查找的方面,那么 Alfresco 将 return 正确的方面结果。

我终于想出了如何实施分面搜索并将其集成到自定义 UI 中。这同样适用于共享。

  1. 在模型管理器中创建模型(无连字符)
    • 索引属性:
      • 字符串:整个匹配的值列表
      • 日期、号码:增强搜索
  2. 为每种类型定义布局设计 - w/o 这至少不能更改共享中的类型。
  3. 在 share/search 经理中为您感兴趣的字段创建 filters/facets
  4. 添加自定义 *context.xml 以使用自定义 FacetQueryProvider 实现定义 bean。将其注入 facet.solrFacetHelper bean
  5. 自定义 FacetQueryProvider 例如DollarAmountDisplayHandler 基本上提供基于 *context.xml 中的美元金额桶 bean 的方面查询,然后将这些查询传递给 solr。
  6. 压缩 FacetQueryProvider 实现并复制到 tomcat/lib 目录。

自定义 solr-facets-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
<bean id="facet.dateFacetFields" class="org.springframework.beans.factory.config.SetFactoryBean">
    <property name="sourceSet">
        <set>
            <value>@{http://www.alfresco.org/model/content/1.0}created</value>
            <value>@{http://www.alfresco.org/model/content/1.0}modified</value>
            <value>@{http://www.mycomp.com/model/hono/1.0}invoiceDate</value>
        </set>
    </property>
</bean>


<bean id="facet.dollarAmountBuckets" class="org.springframework.beans.factory.config.MapFactoryBean">
    <property name="sourceMap">
        <map>
            <entry key="[0 TO 1000]" value="[=10=]-K" />
            <entry key="[1000 TO 10000]" value="K-K" />
            <entry key="[10000 TO 100000]" value="K-0K" />
            <entry key="[100000 TO MAX]" value="Above.0K" />
        </map>
    </property>
</bean>

<bean id="facet.dollarAmountDisplayHandler" class="com.mycomp.edm.alfresco.extensions.search.solr.facets.handlers.DollarAmountDisplayHandler" parent="baseFacetLabelDisplayHandler" >
    <constructor-arg index="0">
        <set>
            <value>@{http://www.mycomp.com/model/hono/1.0}invoiceAmount</value>
        </set>
    </constructor-arg>
    <constructor-arg index="1">
        <ref bean="facet.dollarAmountBuckets" />
    </constructor-arg>
</bean>

<bean id="facet.solrFacetHelper" class="org.alfresco.repo.search.impl.solr.facet.SolrFacetHelper" >
    <constructor-arg>
        <list>
            <ref bean="facet.contentSizeBucketsDisplayHandler" />
            <ref bean="facet.dateBucketsDisplayHandler" />
            <ref bean="facet.dollarAmountDisplayHandler" />
        </list>
    </constructor-arg>
    <property name="specialFacetIds">
        <set>
            <value>SITE</value>
            <value>TAG</value>
            <value>ANCESTOR</value>
            <value>PARENT</value>
            <value>ASPECT</value>
            <value>TYPE</value>
            <value>OWNER</value>
        </set>
    </property>
</bean>

</beans>

型号:

<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.alfresco.org/model/dictionary/1.0" name="hon:hono">
<description>hono model</description>
<author>amit</author>
<imports>
    <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
    <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
</imports>
<namespaces>
    <namespace uri="http://www.mycomp.com/model/hono/1.0" prefix="hon"/>
</namespaces>
<data-types/>
<constraints/>
<types>
    <type name="hon:invoice">
        <title>Invoice</title>
        <description>invoice model</description>
        <parent>cm:content</parent>
        <properties>
            <property name="hon:invoiceNumber">
                <title>Invoice Number</title>
                <type>d:int</type>
                <mandatory>false</mandatory>
                <index enabled="true">
                    <tokenised>TRUE</tokenised>
                    <facetable>true</facetable>
                </index>
            </property>
            <property name="hon:invoiceAmount">
                <title>Invoice Amount</title>
                <type>d:int</type>
                <mandatory>false</mandatory>
                <index enabled="true">
                    <tokenised>TRUE</tokenised>
                    <facetable>true</facetable>
                </index>
            </property>
            <property name="hon:invoiceDate">
                <title>Invoice Date</title>
                <type>d:date</type>
                <mandatory>false</mandatory>
                <index enabled="true">
                    <tokenised>TRUE</tokenised>
                    <facetable>true</facetable>
                </index>
            </property>
            <property name="hon:organizationName">
                <title>Organization Name</title>
                <type>d:text</type>
                <mandatory>false</mandatory>
                <index enabled="true">
                    <tokenised>FALSE</tokenised>
                    <facetable>true</facetable>
                </index>
            </property>
            <property name="hon:customerName">
                <title>Customer Name</title>
                <type>d:text</type>
                <mandatory>false</mandatory>
                <index enabled="true">
                    <tokenised>FALSE</tokenised>
                    <facetable>true</facetable>
                </index>
            </property>
        </properties>
        <associations/>
        <overrides/>
        <mandatory-aspects/>
    </type>
</types>
<aspects/>
</model>

分面查询提供程序

package com.mycomp.edm.alfresco.extensions.search.solr.facets.handlers;

import org.alfresco.repo.search.impl.solr.facet.FacetQueryProvider;
import org.alfresco.repo.search.impl.solr.facet.SolrFacetConfigException;
import org.alfresco.repo.search.impl.solr.facet.handler.AbstractFacetLabelDisplayHandler;
import org.alfresco.repo.search.impl.solr.facet.handler.FacetLabel;
import org.springframework.extensions.surf.util.ParameterCheck;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Amit on 2/24/16.
 */
public class DollarAmountDisplayHandler extends AbstractFacetLabelDisplayHandler implements FacetQueryProvider {

    private static final Pattern SIZE_RANGE_PATTERN = Pattern.compile("(\[\d+\sTO\s(\d+|MAX)\])");

    private final Map<String, FacetLabel> facetLabelMap;
    private final Map<String, List<String>> facetQueriesMap;

    public DollarAmountDisplayHandler(Set<String> facetQueryFields, LinkedHashMap<String, String> dollarValueBucketMap)
    {
        System.out.println("instantiating bean DollarAmountDisplayHandler");
        ParameterCheck.mandatory("facetQueryFields", facetQueryFields);
        ParameterCheck.mandatory("dollarValueBucketMap", dollarValueBucketMap);

        this.supportedFieldFacets = Collections.unmodifiableSet(facetQueryFields);

        facetLabelMap = new HashMap<>(dollarValueBucketMap.size());
        Map<String, List<String>> facetQueries = new LinkedHashMap<>(facetQueryFields.size());

        for (String facetQueryField : facetQueryFields)
        {
            List<String> queries = new ArrayList<>();
            int index = 0;
            for (Map.Entry<String, String> bucket : dollarValueBucketMap.entrySet())
            {
                String sizeRange = bucket.getKey().trim();
                Matcher matcher = SIZE_RANGE_PATTERN.matcher(sizeRange);
                if (!matcher.find())
                {
                    throw new SolrFacetConfigException(
                            "Invalid dollar value range. Example of a valid size range is: [0 TO 1000]");
                }
                // build the facet query. e.g. {http://www.mycomp.com/model/hono/1.0}invoiceAmount:[0 TO 1000]
                String facetQuery = facetQueryField + ':' + sizeRange;
                queries.add(facetQuery);

                // indexOf('[') => 1
                String sizeRangeQuery = sizeRange.substring(1, sizeRange.length() - 1);
                sizeRangeQuery = sizeRangeQuery.replaceFirst("\sTO\s", "\"..\"");
                facetLabelMap.put(facetQuery, new FacetLabel(sizeRangeQuery, bucket.getValue(), index++));
            }
            facetQueries.put(facetQueryField, queries);
        }
        this.facetQueriesMap = Collections.unmodifiableMap(facetQueries);
        System.out.println("Bean DollarAmountDisplayHandler instantiated");

    }

    @Override
    public FacetLabel getDisplayLabel(String value)
    {
        FacetLabel facetLabel = facetLabelMap.get(value);
        return (facetLabel == null) ? new FacetLabel(value, value, -1) : facetLabel;
    }

    @Override
    public Map<String, List<String>> getFacetQueries()
    {
        return this.facetQueriesMap;
    }
}