2016-02-18 31 views
3

我使用Alfresco社区5.x版本,我想知道是否有REST或任何其他远程alfresco apis能够运行分面搜索。
我已经看到了一些RESTful API中管理/管理面搜索即一些方面:http://docs.alfresco.com/community5.0/references/RESTful-Facet.html
但是没有公共的API来运行一个面搜索。Alfresco 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& 

我们有一个基于API与露天我们定制的内部应用程序的集成,不使用露天分享。 我不确定我是否应该使用上述url或不。 对此有何建议?

谢谢!

Alfresco的版本:5.0.d

回答

0

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

  1. 创建模型管理器模型(无连字符)
    • 索引属性:
      • 字符串:值整场比赛
      • 日期,编号列表:增强的搜索
  2. 对于每种类型定义布局设计 - W/O这至少不会改变分享类型。
  3. 在共享/搜索管理器中为您感兴趣的字段创建过滤器/构面
  4. 添加自定义* context.xml以使用您的自定义FacetQueryProvider实现定义一个bean。将其注入facet.solrFacetHelper bean
  5. 自定义FacetQueryProvider例如DollarAmountDisplayHandler基本上提供了基于* context.xml中的美元数额buckets bean的方面查询,然后将这些数据传递给solr。
  6. 加载FacetQueryProvider实现并复制到tomcat/lib目录。

定制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; 
    } 
} 
3

您可以使用默认的搜索webscript:

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将返回正确的分面结果。

+0

谢谢!我会检查出来的。你认为它的公共webscripts的一部分,还是内部共享? – Amit

+0

这是分享,但没关系。每个回购webscript公开可用。 –