用于运行分面搜索的Alfresco API

时间:2016-02-18 06:01:24

标签: rest alfresco solr4 faceted-search

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

我确实注意到露天的份额会对核心的露天服务发起以下攻击,以进行分面搜索;但是找不到与之相关的任何笔记/文档 -

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。 我不确定我是否应该使用上面的网址。 对此有何建议?

谢谢!

Alfresco版本:5.0.d

2 个答案:

答案 0 :(得分:3)

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

  

webscripts \有机\露天\弹弓\搜索\ 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将返回正确的分面结果。

答案 1 :(得分:0)

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

  1. 在模型管理器中创建模型(无连字符)
    • 索引属性:
      • 字符串:值匹配的列表
      • 日期,编号:增强搜索
  2. 对于每种类型,定义布局设计 - 如果你不能至少改变共享中的类型。
  3. 在共享/搜索管理器中为您感兴趣的字段
  4. 创建过滤器/方面
  5. 添加自定义* context.xml以使用自定义FacetQueryProvider实现定义bean。将其注入facet.solrFacetHelper bean
  6. 自定义FacetQueryProvider,例如DollarAmountDisplayHandler基本上提供基于* context.xml中的美元数量桶bean的facet查询,然后将这些查询传递给solr。
  7. 预备FacetQueryProvider实现并复制到tomcat / lib目录。
  8. 自定义-solr的刻面-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="$0-$1K" />
                <entry key="[1000 TO 10000]" value="$1K-$10K" />
                <entry key="[10000 TO 100000]" value="$10K-$100K" />
                <entry key="[100000 TO MAX]" value="Above.$100K" />
            </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;
        }
    }