You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by si...@apache.org on 2012/03/21 10:38:19 UTC

svn commit: r1303327 [2/3] - in /incubator/stanbol/branches/0.9.0-incubating/contenthub: ./ ldpath/src/main/java/org/apache/stanbol/contenthub/ldpath/solr/ search/featured/src/main/java/org/apache/stanbol/contenthub/search/featured/ search/related/src/...

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource.java Wed Mar 21 09:38:18 2012
@@ -52,9 +52,11 @@ import org.apache.stanbol.contenthub.sea
 import org.apache.stanbol.contenthub.servicesapi.Constants;
 import org.apache.stanbol.contenthub.servicesapi.ldpath.SemanticIndexManager;
 import org.apache.stanbol.contenthub.servicesapi.search.SearchException;
+import org.apache.stanbol.contenthub.servicesapi.search.featured.FacetResult;
 import org.apache.stanbol.contenthub.servicesapi.search.featured.FeaturedSearch;
 import org.apache.stanbol.contenthub.servicesapi.search.featured.SearchResult;
 import org.apache.stanbol.contenthub.servicesapi.search.related.RelatedKeywordSearchManager;
+import org.apache.stanbol.contenthub.servicesapi.store.vocabulary.SolrVocabulary;
 import org.apache.stanbol.contenthub.web.util.JSONUtils;
 import org.apache.stanbol.contenthub.web.util.RestUtil;
 import org.osgi.framework.InvalidSyntaxException;
@@ -64,8 +66,8 @@ import org.slf4j.LoggerFactory;
 import com.sun.jersey.api.view.Viewable;
 
 /**
- * This class is the web resource which provides RESTful and HTTP interfaces for {@link FeaturedSearch}
- * services.
+ * This class is the web resource which provides RESTful and HTTP interfaces for
+ * {@link FeaturedSearch} services.
  * 
  * @author anil.sinaci
  * @author suat
@@ -74,251 +76,302 @@ import com.sun.jersey.api.view.Viewable;
 @Path("/contenthub/{index}/search/featured")
 public class FeaturedSearchResource extends BaseStanbolResource {
 
-    private final static Logger log = LoggerFactory.getLogger(FeaturedSearchResource.class);
+	private final static Logger log = LoggerFactory
+			.getLogger(FeaturedSearchResource.class);
 
-    private TcManager tcManager;
+	private TcManager tcManager;
 
-    private FeaturedSearch featuredSearch;
+	private FeaturedSearch featuredSearch;
 
-    private String indexName;
+	private String indexName;
 
-    /**
-     * 
-     * @param context
-     * @param indexName
-     *            Name of the LDPath program (name of the Solr core/index) to be used while storing this
-     *            content item. LDPath programs can be managed through {@link SemanticIndexManagerResource} or
-     *            {@link SemanticIndexManager}
-     * @throws IOException
-     * @throws InvalidSyntaxException
-     */
-    public FeaturedSearchResource(@Context ServletContext context,
-                                  @PathParam(value = "index") String indexName) throws IOException,
-                                                                               InvalidSyntaxException {
-        this.indexName = indexName;
-        this.featuredSearch = ContextHelper.getServiceFromContext(FeaturedSearch.class, context);
-        this.tcManager = ContextHelper.getServiceFromContext(TcManager.class, context);
-    }
-    
-    @OPTIONS
-    public Response handleCorsPreflight(@Context HttpHeaders headers) {
-        ResponseBuilder res = Response.ok();
-        enableCORS(servletContext, res, headers);
-        return res.build();
-    }
-
-    /**
-     * HTTP GET method to make a featured search over Contenthub.
-     * 
-     * @param queryTerm
-     *            A keyword a statement or a set of keywords which can be regarded as the query term.
-     * @param solrQuery
-     *            Solr query string. This is the string format which is accepted by a Solr server. For
-     *            example, {@code q="john doe"&fl=score} is a valid value for this parameter. If this
-     *            parameter exists, search is performed based on this solrQuery and any queryTerms are
-     *            neglected.
-     * @param jsonCons
-     *            Constrainst in JSON format. These constraints are tranformed to corresponding Solr queries
-     *            to enable faceted search. Each constraint is a facet field and values of the constraints
-     *            maps to the values of the facet fields in Solr queries.
-     * @param graphURI
-     *            URI of the ontology in which related keywords will be searched by
-     *            {@link RelatedKeywordSearchManager#getRelatedKeywordsFromOntology(String, String)}
-     * @param offset
-     *            The offset of the document from which the resultant documents will start as the search
-     *            result. {@link offset} and {@link limit} parameters can be used to make a pagination
-     *            mechanism for search results.
-     * @param limit
-     *            Maximum number of resultant documents to be returned as the search result. {@link offset}
-     *            and {@link limit} parameters can be used to make a pagination mechanism for search results.
-     * @param fromStore
-     *            Special parameter for HTML view only.
-     * @param headers
-     *            HTTP headers
-     * @return HTML view or JSON representation of the search results or HTTP BAD REQUEST(400)
-     * @throws IllegalArgumentException
-     * @throws SearchException
-     * @throws InstantiationException
-     * @throws IllegalAccessException
-     * @throws SolrServerException
-     * @throws IOException
-     */
-    @GET
-    @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})
-    public final Response get(@QueryParam("queryTerm") String queryTerm,
-                              @QueryParam("solrQuery") String solrQuery,
-                              @QueryParam("constraints") String jsonCons,
-                              @QueryParam("graphURI") String graphURI,
-                              @QueryParam("offset") @DefaultValue("0") int offset,
-                              @QueryParam("limit") @DefaultValue("10") int limit,
-                              @QueryParam("fromStore") String fromStore,
-                              @Context HttpHeaders headers) throws IllegalArgumentException,
-                                                           SearchException,
-                                                           InstantiationException,
-                                                           IllegalAccessException,
-                                                           SolrServerException,
-                                                           IOException {
-        MediaType acceptedHeader = RestUtil.getAcceptedMediaType(headers);
-
-        this.queryTerm = queryTerm = RestUtil.nullify(queryTerm);
-        solrQuery = RestUtil.nullify(solrQuery);
-        graphURI = RestUtil.nullify(graphURI);
-        jsonCons = RestUtil.nullify(jsonCons);
-        this.offset = offset;
-        this.pageSize = limit;
-
-        if (acceptedHeader.isCompatible(MediaType.TEXT_HTML_TYPE)) {
-            if (fromStore != null) {
-                return Response.ok(new Viewable("index", this), MediaType.TEXT_HTML).build();
-            }
-            if (queryTerm == null && solrQuery == null) {
-                this.ontologies = new ArrayList<String>();
-                Set<UriRef> mGraphs = tcManager.listMGraphs();
-                Iterator<UriRef> it = mGraphs.iterator();
-                while (it.hasNext()) {
-                    graphURI = it.next().getUnicodeString();
-                    if (Constants.isGraphReserved(graphURI)) {
-                        continue;
-                    }
-                    this.ontologies.add(graphURI);
-                }
-                return Response.ok(new Viewable("index", this), MediaType.TEXT_HTML).build();
-            } else {
-                ResponseBuilder rb = performSearch(queryTerm, solrQuery, jsonCons, graphURI, offset, limit,
-                    MediaType.TEXT_HTML_TYPE);
-                addCORSOrigin(servletContext, rb, headers);
-                return rb.build();
-            }
-        } else {
-            if (queryTerm == null && solrQuery == null) {
-                return Response.status(Status.BAD_REQUEST)
-                        .entity("Either 'queryTerm' or 'solrQuery' should be specified").build();
-            } else {
-                ResponseBuilder rb = performSearch(queryTerm, solrQuery, jsonCons, graphURI, offset, limit,
-                    MediaType.APPLICATION_JSON_TYPE);
-                addCORSOrigin(servletContext, rb, headers);
-                return rb.build();
-            }
-        }
-    }
-
-    private ResponseBuilder performSearch(String queryTerm,
-                                          String solrQuery,
-                                          String jsonCons,
-                                          String ontologyURI,
-                                          int offset,
-                                          int limit,
-                                          MediaType acceptedMediaType) throws SearchException {
-
-        if (solrQuery != null) {
-            this.searchResults = featuredSearch.search(new SolrQuery(solrQuery), ontologyURI, indexName);
-        } else if (queryTerm != null) {
-            Map<String,List<Object>> constraintsMap = JSONUtils.convertToMap(jsonCons);
-            this.chosenFacets = JSONUtils.convertToString(constraintsMap);
-            List<String> allAvailableFacetNames = featuredSearch.getFieldNames(indexName);
-            if (this.chosenFacets != null) {
-                SolrQuery sq = SolrQueryUtil.prepareFacetedSolrQuery(queryTerm, allAvailableFacetNames,
-                    constraintsMap);
-                sq.setStart(offset);
-                sq.setRows(limit + 1);
-                this.searchResults = featuredSearch.search(sq, ontologyURI, indexName);
-            } else {
-                SolrQuery sq = SolrQueryUtil.prepareDefaultSolrQuery(queryTerm, allAvailableFacetNames);
-                sq.setStart(offset);
-                sq.setRows(limit + 1);
-                this.searchResults = featuredSearch.search(sq, ontologyURI, indexName);
-            }
-        } else {
-            log.error("Should never reach here!!!!");
-        }
-
-        ResponseBuilder rb = null;
-        if (acceptedMediaType.isCompatible(MediaType.TEXT_HTML_TYPE)) {
-            // return HTML document
-            rb = Response.ok(new Viewable("result.ftl", this));
-            rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML + "; charset=utf-8");
-
-        } else {
-            // it is compatible with JSON (default) - return JSON
-            rb = Response.ok(this.searchResults);
-            rb.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON + "; charset=utf-8");
-        }
-        return rb;
-    }
-
-    /*
-     * Services to draw HTML view
-     */
-
-    // Data holders for HTML view
-    private List<String> ontologies = null;
-    private String queryTerm = null;
-    // private String solrQuery = null;
-    // private String ldProgram = null;
-    // private String graphURI = null;
-    private SearchResult searchResults = null;
-    private String chosenFacets = null;
-    private int offset = 0;
-    private int pageSize = 10;
-
-    // ///////////////////////////
-
-    /*
-     * Helper methods for HTML view
-     */
-
-    public Object getMoreRecentItems() {
-        if (offset >= pageSize) {
-            return new Object();
-        } else {
-            return null;
-        }
-    }
-
-    public Object getOlderItems() {
-        if (searchResults.getResultantDocuments().size() <= pageSize) {
-            return null;
-        } else {
-            return new Object();
-        }
-    }
-
-    public int getOffset() {
-        return this.offset;
-    }
-
-    public int getPageSize() {
-        return this.pageSize;
-    }
-
-    public Object getSearchResults() {
-        return this.searchResults;
-    }
-
-    public Object getResultantDocuments() {
-        if (searchResults.getResultantDocuments().size() > pageSize) {
-            return searchResults.getResultantDocuments().subList(0, pageSize);
-        } else {
-            return searchResults.getResultantDocuments();
-        }
-    }
-
-    public Object getOntologies() {
-        return this.ontologies;
-    }
-
-    public Object getQueryTerm() {
-        if (queryTerm != null) {
-            return queryTerm;
-        }
-        return "";
-    }
-
-    public String getChosenFacets() {
-        return this.chosenFacets;
-    }
-    
-    public String getIndexName() {
-    	return this.indexName;
-    }
+	/**
+	 * 
+	 * @param context
+	 * @param indexName
+	 *            Name of the LDPath program (name of the Solr core/index) to be
+	 *            used while storing this content item. LDPath programs can be
+	 *            managed through {@link SemanticIndexManagerResource} or
+	 *            {@link SemanticIndexManager}
+	 * @throws IOException
+	 * @throws InvalidSyntaxException
+	 */
+	public FeaturedSearchResource(@Context ServletContext context,
+			@PathParam(value = "index") String indexName) throws IOException,
+			InvalidSyntaxException {
+		this.indexName = indexName;
+		this.featuredSearch = ContextHelper.getServiceFromContext(
+				FeaturedSearch.class, context);
+		this.tcManager = ContextHelper.getServiceFromContext(TcManager.class,
+				context);
+	}
+
+	@OPTIONS
+	public Response handleCorsPreflight(@Context HttpHeaders headers) {
+		ResponseBuilder res = Response.ok();
+		enableCORS(servletContext, res, headers);
+		return res.build();
+	}
+
+	/**
+	 * HTTP GET method to make a featured search over Contenthub.
+	 * 
+	 * @param queryTerm
+	 *            A keyword a statement or a set of keywords which can be
+	 *            regarded as the query term.
+	 * @param solrQuery
+	 *            Solr query string. This is the string format which is accepted
+	 *            by a Solr server. For example, {@code q="john doe"&fl=score}
+	 *            is a valid value for this parameter. If this parameter exists,
+	 *            search is performed based on this solrQuery and any queryTerms
+	 *            are neglected.
+	 * @param jsonCons
+	 *            Constrainst in JSON format. These constraints are tranformed
+	 *            to corresponding Solr queries to enable faceted search. Each
+	 *            constraint is a facet field and values of the constraints maps
+	 *            to the values of the facet fields in Solr queries.
+	 * @param graphURI
+	 *            URI of the ontology in which related keywords will be searched
+	 *            by
+	 *            {@link RelatedKeywordSearchManager#getRelatedKeywordsFromOntology(String, String)}
+	 * @param offset
+	 *            The offset of the document from which the resultant documents
+	 *            will start as the search result. {@link offset} and
+	 *            {@link limit} parameters can be used to make a pagination
+	 *            mechanism for search results.
+	 * @param limit
+	 *            Maximum number of resultant documents to be returned as the
+	 *            search result. {@link offset} and {@link limit} parameters can
+	 *            be used to make a pagination mechanism for search results.
+	 * @param fromStore
+	 *            Special parameter for HTML view only.
+	 * @param headers
+	 *            HTTP headers
+	 * @return HTML view or JSON representation of the search results or HTTP
+	 *         BAD REQUEST(400)
+	 * @throws IllegalArgumentException
+	 * @throws SearchException
+	 * @throws InstantiationException
+	 * @throws IllegalAccessException
+	 * @throws SolrServerException
+	 * @throws IOException
+	 */
+	@GET
+	@Produces({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
+	public final Response get(@QueryParam("queryTerm") String queryTerm,
+			@QueryParam("solrQuery") String solrQuery,
+			@QueryParam("constraints") String jsonCons,
+			@QueryParam("graphURI") String graphURI,
+			@QueryParam("offset") @DefaultValue("0") int offset,
+			@QueryParam("limit") @DefaultValue("10") int limit,
+			@QueryParam("fromStore") String fromStore,
+			@Context HttpHeaders headers) throws IllegalArgumentException,
+			SearchException, InstantiationException, IllegalAccessException,
+			SolrServerException, IOException {
+		MediaType acceptedHeader = RestUtil.getAcceptedMediaType(headers);
+
+		this.queryTerm = queryTerm = RestUtil.nullify(queryTerm);
+		solrQuery = RestUtil.nullify(solrQuery);
+		graphURI = RestUtil.nullify(graphURI);
+		jsonCons = RestUtil.nullify(jsonCons);
+		this.offset = offset;
+		this.pageSize = limit;
+
+		if (acceptedHeader.isCompatible(MediaType.TEXT_HTML_TYPE)) {
+			if (fromStore != null) {
+				return Response.ok(new Viewable("index", this),
+						MediaType.TEXT_HTML).build();
+			}
+			if (queryTerm == null && solrQuery == null) {
+				this.ontologies = new ArrayList<String>();
+				Set<UriRef> mGraphs = tcManager.listMGraphs();
+				Iterator<UriRef> it = mGraphs.iterator();
+				while (it.hasNext()) {
+					graphURI = it.next().getUnicodeString();
+					if (Constants.isGraphReserved(graphURI)) {
+						continue;
+					}
+					this.ontologies.add(graphURI);
+				}
+				return Response.ok(new Viewable("index", this),
+						MediaType.TEXT_HTML).build();
+			} else {
+				ResponseBuilder rb = performSearch(queryTerm, solrQuery,
+						jsonCons, graphURI, offset, limit,
+						MediaType.TEXT_HTML_TYPE);
+				addCORSOrigin(servletContext, rb, headers);
+				return rb.build();
+			}
+		} else {
+			if (queryTerm == null && solrQuery == null) {
+				return Response
+						.status(Status.BAD_REQUEST)
+						.entity("Either 'queryTerm' or 'solrQuery' should be specified")
+						.build();
+			} else {
+				ResponseBuilder rb = performSearch(queryTerm, solrQuery,
+						jsonCons, graphURI, offset, limit,
+						MediaType.APPLICATION_JSON_TYPE);
+				addCORSOrigin(servletContext, rb, headers);
+				return rb.build();
+			}
+		}
+	}
+
+	private ResponseBuilder performSearch(String queryTerm, String solrQuery,
+			String jsonCons, String ontologyURI, int offset, int limit,
+			MediaType acceptedMediaType) throws SearchException {
+
+		if (solrQuery != null) {
+			this.searchResults = featuredSearch.search(
+					new SolrQuery(solrQuery), ontologyURI, indexName);
+		} else if (queryTerm != null) {
+			Map<String, List<Object>> constraintsMap = JSONUtils
+					.convertToMap(jsonCons);
+			this.chosenFacets = JSONUtils.convertToString(constraintsMap);
+
+			SolrQuery sq;
+			if (this.chosenFacets != null) {
+				List<FacetResult> allAvailableFacets = featuredSearch
+						.getAllFacetResults(indexName);
+				sq = SolrQueryUtil.prepareFacetedSolrQuery(queryTerm,
+						allAvailableFacets, constraintsMap);
+			} else {
+				sq = SolrQueryUtil.prepareDefaultSolrQuery(queryTerm);
+			}
+			sq.setStart(offset);
+			sq.setRows(limit + 1);
+			this.searchResults = featuredSearch.search(sq, ontologyURI,
+					indexName);
+		} else {
+			log.error("Should never reach here!!!!");
+			throw new SearchException(
+					"Either 'queryTerm' or 'solrQuery' paramater should be set");
+		}
+
+		ResponseBuilder rb = null;
+		if (acceptedMediaType.isCompatible(MediaType.TEXT_HTML_TYPE)) {
+			// return HTML document
+			/*
+			 * For HTML view, sort facets according to their names
+			 */
+			this.searchResults.setFacets(sortFacetResults(this.searchResults
+					.getFacets()));
+			rb = Response.ok(new Viewable("result.ftl", this));
+			rb.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML
+					+ "; charset=utf-8");
+
+		} else {
+			// it is compatible with JSON (default) - return JSON
+			rb = Response.ok(this.searchResults);
+			rb.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON
+					+ "; charset=utf-8");
+		}
+		return rb;
+	}
+
+	private List<FacetResult> sortFacetResults(List<FacetResult> facetResults) {
+		List<FacetResult> orderedFacets = new ArrayList<FacetResult>();
+		int annotatedFacetNum = 0;
+		for (FacetResult fr : facetResults) {
+			String facetName = fr.getFacetField().getName();
+			if (fr.getFacetField().getValues() == null) {
+				continue;
+			} else if (SolrVocabulary.SolrFieldName
+					.isAnnotatedEntityFacet(facetName)) {
+				orderedFacets.add(annotatedFacetNum, fr);
+				annotatedFacetNum++;
+			} else {
+				boolean inserted = false;
+				for (int j = annotatedFacetNum; j < orderedFacets.size(); j++) {
+					if (facetName.compareTo(orderedFacets.get(j)
+							.getFacetField().getName()) < 0) {
+						orderedFacets.add(j, fr);
+						inserted = true;
+						break;
+					}
+				}
+				if (inserted == false) {
+					orderedFacets.add(fr);
+				}
+			}
+		}
+		return orderedFacets;
+	}
+
+	/*
+	 * Services to draw HTML view
+	 */
+
+	// Data holders for HTML view
+	private List<String> ontologies = null;
+	private String queryTerm = null;
+	// private String solrQuery = null;
+	// private String ldProgram = null;
+	// private String graphURI = null;
+	private SearchResult searchResults = null;
+	private String chosenFacets = null;
+	private int offset = 0;
+	private int pageSize = 10;
+
+	// ///////////////////////////
+
+	/*
+	 * Helper methods for HTML view
+	 */
+
+	public Object getMoreRecentItems() {
+		if (offset >= pageSize) {
+			return new Object();
+		} else {
+			return null;
+		}
+	}
+
+	public Object getOlderItems() {
+		if (searchResults.getDocuments().size() <= pageSize) {
+			return null;
+		} else {
+			return new Object();
+		}
+	}
+
+	public int getOffset() {
+		return this.offset;
+	}
+
+	public int getPageSize() {
+		return this.pageSize;
+	}
+
+	public Object getSearchResults() {
+		return this.searchResults;
+	}
+
+	public Object getDocuments() {
+		if (searchResults.getDocuments().size() > pageSize) {
+			return searchResults.getDocuments().subList(0, pageSize);
+		} else {
+			return searchResults.getDocuments();
+		}
+	}
+
+	public Object getOntologies() {
+		return this.ontologies;
+	}
+
+	public Object getQueryTerm() {
+		if (queryTerm != null) {
+			return queryTerm;
+		}
+		return "";
+	}
+
+	public String getChosenFacets() {
+		return this.chosenFacets;
+	}
+
+	public String getIndexName() {
+		return this.indexName;
+	}
 }

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resources/StoreResource.java Wed Mar 21 09:38:18 2012
@@ -608,15 +608,6 @@ public class StoreResource extends BaseS
                 // feedback
             }
         } else if (file != null) {
-            /*
-             * MimeUtil2 mimeUtil = new MimeUtil2(); mimeUtil.registerMimeDetector
-             * ("eu.medsea.mimeutil.detector.ExtensionMimeDetector"); mimeUtil.registerMimeDetector
-             * ("eu.medsea.mimeutil.detector.MagicMimeMimeDetector"); Collection<?> mimeTypes =
-             * mimeUtil.getMimeTypes(file); mt = MediaType
-             * .valueOf(MimeUtil2.getMostSpecificMimeType(mimeTypes).toString ());
-             * mimeUtil.unregisterMimeDetector( "eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
-             * mimeUtil.unregisterMimeDetector ("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
-             */
             mt = body.getMediaType();
             data = FileUtils.readFileToByteArray(file);
             if (title == null || title.isEmpty()) {

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/util/JSONUtils.java Wed Mar 21 09:38:18 2012
@@ -194,7 +194,7 @@ public class JSONUtils {
     public static String createJSONString(SearchResult searchResult) throws JSONException {
         JSONObject jObj = new JSONObject();
         if (searchResult != null) {
-            jObj.put("documents", toJSON(searchResult.getResultantDocuments()));
+            jObj.put("documents", toJSON(searchResult.getDocuments()));
             jObj.put("facets", toJSON(searchResult.getFacets()));
             jObj.put("relatedkeywords", toJSON(searchResult.getRelatedKeywords()));
         }

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/facetResultMacro.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/facetResultMacro.ftl?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/facetResultMacro.ftl (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/facetResultMacro.ftl Wed Mar 21 09:38:18 2012
@@ -15,78 +15,75 @@
   limitations under the License.
 -->
 <#escape x as x?html>
-<#macro facetResultMacro facetField consLink>
-	<#assign limit=4 />
-	<#if facetField?exists>
-		<#if facetField.values?exists && facetField.values?size != 0>
-      <#assign consLinkEscaped = consLink/>
+<#macro facetResultMacro facetResult>
+  <#assign limit=4 />
+  <#assign facetField=facetResult.facetField />
+  <#assign facetHtmlName=facetResult.htmlName />
+  <#assign facetID=facetHtmlName?replace(':','_') />
+  
+  <#if facetField?exists>
+    <#if facetField.values?exists && facetField.values?size != 0>
       <#assign facetNameEscaped = facetField.name?url("UTF-8")?js_string/>
+      <#if facetField.name == "stanbolreserved_creationdate">
+        ${facetHtmlName}
+        <br/>
+        <#assign orderedList = facetField.values?sort_by("name") />
+        <p>
+          <input id="dateFrom" class="facetText" type="text" value="${orderedList[0].name?substring(0,10)}" readonly="true"/> 
+          to <input id="dateTo" class="facetText" type="text" value="${orderedList[orderedList?size-1].name?substring(0,10)}" readonly="true"/>
+          <a href="javascript:getResults('stanbolreserved_creationdate','','date')"><input type="button" value=">" /></a>
+        </p>
+      <#else>
+        ${facetHtmlName}
+        <#assign type = facetResult.type />
+        <#if type=="int" || type=="float" || type=="long" || type=="double">
+          <p>
+          <input id="${facetHtmlName}TextMin" class="facetText" type="text"/> 
+            to <input id="${facetHtmlName}TextMax" class="facetText" type="text"/>
+          <a href="javascript:getResults('${facetNameEscaped}','','range')"><input type="button" value=">" /></a>
+          </p>
+        </#if>
+        <ul id="${facetHtmlName}list"> 
+          <#assign x=0 />
+          <#list facetField.values as count>
+            <#assign countNameEscaped = count.name?url("UTF-8")?js_string/>
+            <#if x = limit><#break/></#if>
+            <li><a href="javascript:getResults('${facetNameEscaped}','${countNameEscaped}','addFacet')">${count.name} ( ${count.count} )</a></li>
+            <#assign x=x+1 />
+          </#list>
+        </ul>       
+        <#if facetField.values?size &gt; limit>
+          <a id="${facetID}" href="">more</a><br>
+        </#if>
+      </#if>
+    </#if>
+  <#else>
+    <p>No results found<p>
+  </#if>
+  <hr />
+  <script type=text/javascript>
+  
+      function init() {
+          $("#dateFrom").datepicker({ dateFormat: 'yy-mm-dd' });
+          $("#dateTo").datepicker({ dateFormat: 'yy-mm-dd' });
       
-			<#if facetField.name == "stanbolreserved_creationdate">
-				<#assign facetHtmlName=facetField.htmlName />
-				${facetHtmlName}
-				<br/>
-				<#assign orderedList = facetField.values?sort_by("name") />
-				<ul><li>
-					<input id="dateFrom" class="facetText" type="text" value="${orderedList[0].name?substring(0,10)}" readonly="true"/> 
-					to <input id="dateTo" class="facetText" type="text" value="${orderedList[orderedList?size-1].name?substring(0,10)}" readonly="true"/>
-					<a href="javascript:getResults('${consLinkEscaped}','stanbolreserved_creationdate','','date')"><input type="button" value=">" /></a>
-				</li></ul>
-			<#else>
-				<#assign facetHtmlName=facetField.htmlName />
-				${facetHtmlName}
-				<ul id="${facetHtmlName}list">
-					<#if facetField.name?ends_with("_l")>
-						<li>
-							<input id="${facetHtmlName}TextMin" class="facetText" type="text"/> 
-							to <input id="${facetHtmlName}TextMax" class="facetText" type="text"/>
-							<a href="javascript:getResults('${consLinkEscaped}','${facetNameEscaped}','','range')"><input type="button" value=">" /></a>
-						</li>
-					</#if>
-					
-					<#assign x=0 />
-					<#list facetField.values as count>
-						<#assign countNameEscaped = count.name?url("UTF-8")?js_string/>
-						<#if x = limit><#break/></#if>
-						<li><a href="javascript:getResults('${consLinkEscaped}','${facetNameEscaped}','${countNameEscaped}','addFacet')">${count.name} ( ${count.count} )</a></li>
-						<#assign x=x+1 />
-					</#list>
-				</ul>						
-				<#if facetField.values?size &gt; limit>
-					<a id="${facetHtmlName?replace(':','_')}" href="">more</a><br>
-				</#if>
-			</#if>
-		</#if>
-	<#else>
-		<p>No results found<p>
-	</#if>
-	<script type=text/javascript>
-	
-	
-	
-	function init() {
-			$("#dateFrom").datepicker({ dateFormat: 'yy-mm-dd' });
-			$("#dateTo").datepicker({ dateFormat: 'yy-mm-dd' });
-	
-	   $("#${facetHtmlName?replace(':','_')}", this).click(function(e) {
-	     // disable regular form click
-	     e.preventDefault();
-	     if(document.getElementById("${facetHtmlName?replace(':','_')}").innerHTML == "more")
-	     {
-	     	 var a="<#list facetField.values as count><#assign consLinkEscaped = consLink?url("UTF-8")?js_string/><#assign countNameEscaped = count.name?url("UTF-8")?js_string/><#assign facetNameEscaped = facetField.name?url("UTF-8")?js_string/><li><a href=javascript:getResults('${consLinkEscaped}','${facetNameEscaped}','${countNameEscaped}','addFacet')>${count.name} ( ${count.count} )</a></li></#list>";
-	       document.getElementById("${facetHtmlName}list").innerHTML=a;
-	       document.getElementById("${facetHtmlName?replace(':','_')}").innerHTML = "less";
-  		 }
-  		 else
-  		 {
-  		 	 var a="<#assign x=0 /><#list facetField.values as count><#if x = limit><#break/></#if><li><a href=javascript:getResults('${consLinkEscaped}','${facetNameEscaped}','${countNameEscaped}','addFacet')>${count.name} ( ${count.count} )</a></li><#assign x=x+1 /></#list>";
-  		 	 document.getElementById("${facetHtmlName}list").innerHTML=a;
-  		 	 document.getElementById("${facetHtmlName?replace(':','_')}").innerHTML = "more";		 	
-  		 }    
-     });
-	 }
-
-	 $(document).ready(init);
-</script>
+          $("#${facetID}", this).click(function(e) {
+              // disable regular form click
+              e.preventDefault();
+              if(document.getElementById("${facetID}").innerHTML == "more") {
+                  var a="<#list facetField.values as count><#assign countNameEscaped = count.name?url("UTF-8")?js_string/><#assign facetNameEscaped = facetField.name?url("UTF-8")?js_string/><li><a href=javascript:getResults('${facetNameEscaped}','${countNameEscaped}','addFacet')>${count.name} ( ${count.count} )</a></li></#list>";
+                  document.getElementById("${facetHtmlName}list").innerHTML=a;
+                  document.getElementById("${facetID}").innerHTML = "less";
+              }
+              else {
+                  var a="<#assign x=0 /><#list facetField.values as count><#if x = limit><#break/></#if><li><a href=javascript:getResults('${facetNameEscaped}','${countNameEscaped}','addFacet')>${count.name} ( ${count.count} )</a></li><#assign x=x+1 /></#list>";
+                  document.getElementById("${facetHtmlName}list").innerHTML=a;
+                  document.getElementById("${facetID}").innerHTML = "more";     
+              }    
+          });
+      }
+  
+      $(document).ready(init);
+  </script>
 </#macro>
 </#escape>
\ No newline at end of file

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/relatedKeywordMacro.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/relatedKeywordMacro.ftl?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/relatedKeywordMacro.ftl (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/imports/relatedKeywordMacro.ftl Wed Mar 21 09:38:18 2012
@@ -15,43 +15,40 @@
   limitations under the License.
 -->
 <#macro relatedKeywordMacro relatedKeywordId relatedKeywordList source>
-	<#assign limit = 4/>
-	<#assign normalizedSourceName = source?replace("*","_")?replace(" ", "_")?replace("'", "_")>
-		Related ${source} Keywords
-		<ul id="${relatedKeywordId}${normalizedSourceName}list" class="spadded">
-			<#assign x = 0/>
-			<#list relatedKeywordList as related>
-				<#assign relatedName = related.keyword?replace(' ','_')>
-				<#if x == limit><#break/></#if>
-				<li><a href=javascript:getResults(null,null,"${relatedName}","explore")>${relatedName?replace('_',' ')}</a></li>
-				<#assign x = x + 1>
-			</#list>
-		</ul>
-		<#if relatedKeywordList?size &gt; limit>
-			<a id="${relatedKeywordId}${normalizedSourceName}button" href="">more</a><br>
-		</#if>
-		<br/>
-		
-	<script language="javascript">
-		function moreLessButtonHandler() {
-		   $("#${relatedKeywordId}${normalizedSourceName}button", this).click(function(e) {
-		     // disable regular form click
-		     e.preventDefault();
-		     if(document.getElementById("${relatedKeywordId}${normalizedSourceName}button").innerHTML == "more")
-		     {
-  		     var a="<#list relatedKeywordList as related><#assign relatedName = related.keyword?replace(' ','_')><li><a href=javascript:getResults(null,null,'${relatedName}','explore')>${relatedName?replace('_', ' ')}</a></li></#list>";
-  		     document.getElementById("${relatedKeywordId}${normalizedSourceName}list").innerHTML=a;
-  		     $(this).attr({ 'innerHTML': 'less' });
-  			 }
-  			 else
-  			 {
-    			 var a="<#assign x=0><#list relatedKeywordList as related><#assign relatedName = related.keyword?replace('_',' ')><#if x == limit><#break/></#if><li><a href=javascript:getResults(null,null,'${relatedName}','explore')>${relatedName?replace('_', ' ')}</a></li><#assign x=x+1 /></#list>";
-    			 document.getElementById("${relatedKeywordId}${normalizedSourceName}list").innerHTML=a;
-    			 $(this).attr({ 'innerHTML': 'more' });		 	
-  			 }    
-		   });
-		 }		 
-		 
-		 $(document).ready(moreLessButtonHandler);
-	</script>
+  <#assign limit = 4/>
+  <#assign normalizedSourceName = source?replace("*","_")?replace(" ", "_")?replace("'", "_")>
+  Related ${source} Keywords
+  <ul id="${relatedKeywordId}${normalizedSourceName}list" class="spadded">
+    <#assign x = 0/>
+    <#list relatedKeywordList as related>
+      <#assign relatedName = related.keyword?replace(' ','_')>
+      <#if x == limit><#break/></#if>
+      <li><a href=javascript:getResults(null,"${relatedName}","explore")>${relatedName?replace('_',' ')}</a></li>
+      <#assign x = x + 1>
+    </#list>
+  </ul>
+  <#if relatedKeywordList?size &gt; limit>
+    <a id="${relatedKeywordId}${normalizedSourceName}button" href="">more</a><br>
+  </#if>
+  <br/>
+    
+  <script language="javascript">
+      function moreLessButtonHandler() {
+          $("#${relatedKeywordId}${normalizedSourceName}button", this).click(function(e){
+              // disable regular form click
+              e.preventDefault();
+              if(document.getElementById("${relatedKeywordId}${normalizedSourceName}button").innerHTML == "more") {
+                  var a="<#list relatedKeywordList as related><#assign relatedName = related.keyword?replace(' ','_')><li><a href=javascript:getResults(null,'${relatedName}','explore')>${relatedName?replace('_', ' ')}</a></li></#list>";
+                  document.getElementById("${relatedKeywordId}${normalizedSourceName}list").innerHTML=a;
+                  $(this).attr({ 'innerHTML': 'less' });
+              } else{
+                  var a="<#assign x=0><#list relatedKeywordList as related><#assign relatedName = related.keyword?replace('_',' ')><#if x == limit><#break/></#if><li><a href=javascript:getResults(null,'${relatedName}','explore')>${relatedName?replace('_', ' ')}</a></li><#assign x=x+1 /></#list>";
+                  document.getElementById("${relatedKeywordId}${normalizedSourceName}list").innerHTML=a;
+                  $(this).attr({ 'innerHTML': 'more' });       
+              }    
+          });
+       }     
+       
+       $(document).ready(moreLessButtonHandler);
+  </script>
 </#macro>
\ No newline at end of file

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/index.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/index.ftl?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/index.ftl (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/index.ftl Wed Mar 21 09:38:18 2012
@@ -17,304 +17,305 @@
 <#import "/imports/common.ftl" as common>
 <#escape x as x?html>
 <@common.page title="Search" hasrestapi=false>
-	<div id="search">
-	<#-- this feildset was normally in a form, ajax is used to do the post, dont need to use fom -->
-		<fieldset>
-			<legend>Keyword Based Search</legend>
-			
-			<p>
-				Select an index: <div id="indexDiv"><#--this div will be populated by ajax--></div>
-			</p>
-			<p>
-				Keywords: <input id="keywordIn" class="autoCompleteText" <#-- onkeyup="javascript:completePattern();" --> name="topic" type="text" onkeydown="if (event.keyCode == 13) document.getElementById('submitIn').click()"/><br/>
-			</p>
-			<p>
-				<!-- Ontology selection combobox-->
-				<#if it.ontologies?exists && it.ontologies?size != 0>
-				Graph: <select  id="graphIn" name="max" type="text" value="5">
-					<option value="choose_ontology">Choose an ontology</option>
-					<#list it.ontologies as ont>
-						<option value="${ont}">${ont}</option>
-					</#list>
-					</select>
-				<#else>
-					<p><i>No graphs to search.<i><p> 
-				</#if>
-			</p>
-			<p>
-				<input id="submitIn" type="button" value="Search" onclick="getResults(null,null,null,'first');"></input>
-			</p>
-			<img id="busyIcon" class="invisible centerImage" src="${it.staticRootUrl}/contenthub/images/ajax-loader.gif"/>
-		</fieldset>
-	</div>	
-	
-	<div id="resultContainer" class="invisible">
-		<div class="invisible" id="previousSuggestionButton"></div>
-		<div>
-			<!-- To be populated with ajax without xml :)-->
-		</div>
-	</div>
-	
-	<!-- to be populated by the list of suggested keywords to be able to get back in search -->
-	<div id="suggestedKeywordList" class="invisible">{"keywords":[]}</div>	
-	<!-- FIXME put a textarea so jQuery-ui tabs does not expand through footer -->
-	<textarea type="text" disabled="true" style="border-color: #fff; background: white; height:100px; max-height:100px; width:100%; max-width:100%"></textarea>
-	
-	<script language="javascript">
-	
-		function init() {
-			
-			//accordion
-			$(".keywords").accordion({collapsible: true});
-			//if a GET gets a parameters, then does the search with that parameter
-			var keywords = "${it.queryTerm}";
-			if(keywords != null && keywords.length != 0) {
-				$("#keywordIn").val(keywords);
-				getResults(null,null,null,'first');
-			}
-			
-	        $.get("${it.publicBaseUri}contenthub/ldpath", function(indexes) {
-	            innerStr = "<select id='indexSelect' onChange='javascript:redirectIndex();'>" + "<option value='contenthub'>contenthub</option>"
-	            for(var index in indexes) {
-	                innerStr += "<option value=" + index + ">" + index + "</option>";
-	            }
-	            innerStr += "</select>";
-	            $("#indexDiv").html(innerStr);
-	            $("#indexSelect").val("${it.indexName}");
-	        });
-		}
-		
-		$(document).ready(init);
-	 
-		function hideDiv(){
-			$('#facets').hide("slow");
-		}
-		function showDiv(){
-			$('#facets').show("slow");
-		}
-		
-		function redirectIndex(){
-			var index = $("#indexSelect").val();
-			window.location.replace("${it.publicBaseUri}contenthub/" + index + "/search/featured");
-		}
+  <div id="search">
+  <#-- this feildset was normally in a form, ajax is used to do the post, dont need to use fom -->
+    <fieldset>
+      <legend>Keyword Based Search</legend>
+      
+      <p>
+        Select an index: <div id="indexDiv"><#--this div will be populated by ajax--></div>
+      </p>
+      <p>
+        Keywords: <input id="keywordIn" class="autoCompleteText" <#-- onkeyup="javascript:completePattern();" --> name="topic" type="text" onkeydown="if (event.keyCode == 13) document.getElementById('submitIn').click()"/><br/>
+      </p>
+      <p>
+        <!-- Ontology selection combobox-->
+        <#if it.ontologies?exists && it.ontologies?size != 0>
+          Graph: 
+          <select  id="graphIn" name="max" type="text" value="5">
+            <option value="choose_ontology">Choose an ontology</option>
+            <#list it.ontologies as ont>
+              <option value="${ont}">${ont}</option>
+            </#list>
+          </select>
+        <#else>
+          <p><i>No graphs to search.<i><p> 
+        </#if>
+      </p>
+      <p>
+        <input id="submitIn" type="button" value="Search" onclick="getResults(null,null,'first');"></input>
+      </p>
+      <img id="busyIcon" class="invisible centerImage" src="${it.staticRootUrl}/contenthub/images/ajax-loader.gif"/>
+    </fieldset>
+  </div>  
+  
+  <div id="resultContainer" class="invisible">
+    <div class="invisible" id="previousSuggestionButton"></div>
+    <div>
+      <!-- To be populated with ajax without xml :)-->
+    </div>
+  </div>
+  
+  <!-- to be populated by the list of suggested keywords to be able to get back in search -->
+  <input type="hidden" id="suggestedKeywordList" value=""/>  
+  <!-- FIXME put a textarea so jQuery-ui tabs does not expand through footer -->
+  <textarea type="text" disabled="true" style="border-color: #fff; background: white; height:100px; max-height:100px; width:100%; max-width:100%"></textarea>
+  
+  <script language="javascript">
+  
+      function init() {
+        
+          //accordion
+          $(".keywords").accordion({collapsible: true});
+          //if a GET gets a parameters, then does the search with that parameter
+          var keywords = "${it.queryTerm}";
+          if(keywords != null && keywords.length != 0) {
+              $("#keywordIn").val(keywords);
+              getResults(null,null,'first');
+          }
+          
+          $.get("${it.publicBaseUri}contenthub/ldpath", function(indexes) {
+              innerStr = "<select id='indexSelect' onChange='javascript:redirectIndex();'>" + "<option value='contenthub'>contenthub</option>"
+              for(var index in indexes) {
+                  innerStr += "<option value=" + index + ">" + index + "</option>";
+              }
+              innerStr += "</select>";
+              $("#indexDiv").html(innerStr);
+              $("#indexSelect").val("${it.indexName}");
+          });
+      }
     
-		function completePattern(){
-			var pattern = $("#keywordIn").val();
-			$.get("${it.publicBaseUri}contenthub/${it.indexName}/search/related/autocomplete?pattern="+pattern, function(data) {
-				var jsonSource = JSON.parse(data);
-				$(".autoCompleteText").autocomplete({
-					source: jsonSource['completedKeywords']
-				});					
-			});
-		}
-
-		function getResults(jsonCons,facetName,facetValue,operation,voffset,vpageSize){
-		  if(operation == "deleteFacet") {
-		    facetName = decodeURIComponent(facetName);
-		    facetValue = decodeURIComponent(facetValue);
-		  }
-			//clears the content of div because it'll be filled by explorer posts
-			var keywordToSearch = $("#keywordIn").val();
-			
-			if(typeof(jsonCons) == "undefined") {
-				jsonCons = "{}";
-				var suggestedList = JSON.parse('{"keywords" : []}');
-				suggestedList['keywords'].push($("#keywordIn").val());
-				$("#suggestedKeywordList").text(JSON.stringify(suggestedList));
-			}
-			var JSONObject = JSON.parse(jsonCons);
-			if(typeof(facetName) != "undefined" || typeof(facetValue != "undefined")) {
-							
-				if(operation == "addFacet") {
-					if(JSONObject[facetName] != null)
-					{
-						if(JSONObject[facetName].indexOf(facetValue) == -1) {
-							JSONObject[facetName].push(facetValue);
-						}
-					} else {
-						JSONObject[facetName] = new Array();
-						JSONObject[facetName].push(facetValue);
-					}
-				}
-				
-				else if(operation == "deleteFacet") {
-				  
-					var  values = JSONObject[facetName];	
-					var length=0;
-					var index;
-					for(var value in values) {			
-						if(typeof(JSONObject[facetName][value]) != "undefined") {
-							length++;
-							if(JSONObject[facetName][value] == facetValue) {
-								index = value;
-							}
-						}
-					}			
-					
-					if(length == 1) {
-						delete JSONObject[facetName];
-					} else {
-						delete JSONObject[facetName][index];
-					}
-				}
-				
-			}
-			if(operation == "explore")
-			{
-				
-				$("#keywordIn").val(facetValue);
-				var suggestedList = JSON.parse(document.getElementById("suggestedKeywordList").innerHTML);
-				
-				var previousString = "";
-				for(i = 0; i  < suggestedList['keywords'].length ; i++)
-				{
-					if(i != 0)
-					{
-						previousString += " > ";
-					}
-					previousString += "<a href=javascript:getResults(null,null,'" + suggestedList['keywords'][i] + "','previousSuggestion')> " + suggestedList['keywords'][i] + "</a>";
-				}
-				$("#previousSuggestionButton").html(previousString);
-				//adds the last entered word to list and saves it in a hidden division
-				suggestedList['keywords'].push(facetValue);
-				
-				//decides when to show back division
-				if(suggestedList['keywords'].length > 1)
-				{
-					$("#previousSuggestionButton").removeClass('invisible');
-				}
-				else
-				{
-					$("#previousSuggestionButton").addClass('invisible');
-				}
-				$("#suggestedKeywordList").text(JSON.stringify(suggestedList));
-			}
-			
-			//if back button is pressed, previous suggestion is searched again and suggestionList is fixed
-			else if(operation == "previousSuggestion")
-			{
-				var suggestedList = (JSON.parse(document.getElementById("suggestedKeywordList").innerHTML));
-				var length = suggestedList['keywords'].length;
-				var index = suggestedList['keywords'].indexOf(facetValue);
-				
-				suggestedList['keywords'] = suggestedList['keywords'].slice(0,index);				
-				
-				$("#suggestedKeywordList").text(JSON.stringify(suggestedList));
-				getResults(null,null,facetValue,"explore");
-			}
-			else if(operation == "date"){
-			
-				var JSONObject = JSON.parse(jsonCons);
-				var facetValue = "[" + document.getElementById("dateFrom").value + "T00:00:00Z TO " + 
-										document.getElementById("dateTo").value + "T23:59:59Z]";
-				JSONObject[facetName] = new Array();
-				JSONObject[facetName].push(facetValue);
-			}
-			else if(operation == "range"){
-			  var facetHtmlName = getHtmlName(facetName);
-				var JSONObject = JSON.parse(jsonCons);
-				var facetValue = "[" + document.getElementById(facetHtmlName+"TextMin").value + " TO " + 
-										           document.getElementById(facetHtmlName+"TextMax").value + "]";
-									
-				JSONObject[facetName] = new Array();
-				JSONObject[facetName].push(facetValue);
-			}
-			
-			//make text area invisible
-			$("#searchResult").fadeOut(100);
-			$("#resultContainer").fadeOut(100);
-			//show busy icon
-			$("#busyIcon").removeClass("invisible");
+      $(document).ready(init);
+   
+      function hideDiv() {
+          $('#facets').hide("slow");
+      }
+      
+      function showDiv() {
+          $('#facets').show("slow");
+      }
+    
+      function redirectIndex() {
+          var index = $("#indexSelect").val();
+          window.location.replace("${it.publicBaseUri}contenthub/" + index + "/search/featured");
+      }
+    
+      function completePattern() {
+          var pattern = $("#keywordIn").val();
+          $.get("${it.publicBaseUri}contenthub/${it.indexName}/search/related/autocomplete?pattern="+pattern, function(data) {
+              var jsonSource = JSON.parse(data);
+              $(".autoCompleteText").autocomplete({
+                  source: jsonSource['completedKeywords']
+              });         
+          });
+      }
 
-			var graph_selected = "";
-			var graphInCombo = document.getElementById('graphIn');
-			if (graphInCombo != null) {
-				var selectedIndex = graphInCombo.selectedIndex;
-				if(selectedIndex != 0) {
-					graph_selected = $("#graphIn option:selected").val();
-				}
-			}
-			
-      $.ajax({
-        url : "${it.publicBaseUri}contenthub/${it.indexName}/search/featured",
-        type : "GET",
-        async: true,
-        data: {queryTerm: $("#keywordIn").val(), graph: graph_selected, constraints: JSON.stringify(JSONObject), offset: voffset, limit:vpageSize},
-        dataType: "html",
-        cache: false,
-        success: function(result) {
-          $("#busyIcon").addClass("invisible");
-          $("#search").addClass("invisible");
+      function getResults(facetName,facetValue,operation,voffset,vpageSize) {
+        
+          //clears the content of div because it'll be filled by explorer posts
+          var keywordToSearch = $("#keywordIn").val();
+          
+          jsonCons = $("#chosenFacetsHidden").attr("value");
+          if(typeof(jsonCons) == "undefined") {
+              jsonCons = "{}";
+          }
+        
+          jsonSug = $("#suggestedKeywordList").attr("value");
+          if(jsonSug != "undefined" && jsonSug == "") {
+              var suggestedList = JSON.parse('{"keywords" : []}');
+              suggestedList['keywords'].push($("#keywordIn").val());
+              $("#suggestedKeywordList").val(JSON.stringify(suggestedList));
+          }
+       
+          var JSONObject = JSON.parse(jsonCons);
+          if(typeof(facetName) != "undefined" || typeof(facetValue != "undefined")) {
+              
+              if(operation == "addFacet") {
+                  if(JSONObject[facetName] != null) {
+                      if(JSONObject[facetName].indexOf(facetValue) == -1) {
+                          JSONObject[facetName].push(facetValue);
+                      }
+                  } else {
+                      JSONObject[facetName] = new Array();
+                      JSONObject[facetName].push(facetValue);
+                  }
+              }
+        
+              else if(operation == "deleteFacet") {
+          
+                  facetName = decodeURIComponent(facetName);
+                  facetValue = decodeURIComponent(facetValue);
+                  var  values = JSONObject[facetName];  
+                  var length=0;
+                  var index;
+                  for(var value in values) {      
+                      if(typeof(JSONObject[facetName][value]) != "undefined") {
+                          length++;
+                          if(JSONObject[facetName][value] == facetValue) {
+                              index = value;
+                          }
+                      }
+                  }     
+          
+                  if(length == 1) {
+                      delete JSONObject[facetName];
+                  } else {
+                      delete JSONObject[facetName][index];
+                  }
+              }
+          }
+          if(operation == "explore") {
+            
+              $("#keywordIn").val(facetValue);
+              var suggestedList = JSON.parse($("#suggestedKeywordList").val());
             
-          $("#resultContainer > div:nth-child(2)").replaceWith(result.substr(result.indexOf("</div>")));
-          $(".keywords").accordion({collapsible: true, autoHeight: false });
-          $(".keywords").removeClass("ui-widget");
-          $(".resources > div").tabs({fx: { height: 'toggle', opacity: 'toggle' } });
-          $("#resultContainer").fadeIn("slow");
-           
-          //collapsible content
-          $(".collapseItem").click(function(e){
-            e.preventDefault();
-            $(this).next(".collapseContent").slideToggle(500);
-          }); 
+              var previousString = "";
+              for(i = 0; i  < suggestedList['keywords'].length ; i++) {
+                  if(i != 0) {
+                      previousString += " > ";
+                  }
+                  previousString += "<a href=javascript:getResults(null,'" + suggestedList['keywords'][i] + "','previousSuggestion')> " + suggestedList['keywords'][i] + "</a>";
+              }
+              $("#previousSuggestionButton").html(previousString);
+              //adds the last entered word to list and saves it in a hidden division
+              suggestedList['keywords'].push(facetValue);
+            
+              //decides when to show back division
+              if(suggestedList['keywords'].length > 1) {
+                  $("#previousSuggestionButton").removeClass('invisible');
+              }
+              else{
+                  $("#previousSuggestionButton").addClass('invisible');
+              }
+              $("#suggestedKeywordList").val(JSON.stringify(suggestedList));
+          }
+      
+          //if back button is pressed, previous suggestion is searched again and suggestionList is fixed
+          else if(operation == "previousSuggestion") {
+              var suggestedList = JSON.parse($("#suggestedKeywordList").val());
+              var length = suggestedList['keywords'].length;
+              var index = suggestedList['keywords'].indexOf(facetValue);
+              
+              suggestedList['keywords'] = suggestedList['keywords'].slice(0,index);       
+              
+              $("#suggestedKeywordList").val(JSON.stringify(suggestedList));
+              getResults(null,facetValue,"explore");
+          }
+          else if(operation == "date") {
           
-          setChosenFacet(JSONObject);
-        },
-        error: function(result) {
-          $("#busyIcon").addClass("invisible");
-          alert(result.status + ' ' + result.statusText);
-        }
-      });
-		}
-		function setChosenFacet(JSONObject)	{
-			var resultString = "";
-			var chosenCons = $("#chosenFacetsHidden").attr("value");
-							
-			if(JSONObject != null) {
-				for(var p in JSONObject) {
-					if(JSONObject.hasOwnProperty(p)) {
-						for(var value in p) {
-							if(p.hasOwnProperty(value) && typeof(JSONObject[p][value]) != "undefined") {
-								var escapedFacetName = escape(encodeURIComponent(p.toString()));
-								var escapedFacetValue = escape(encodeURIComponent(JSONObject[p][value]));
-								var uriEncodedChosenConstraints = chosenCons;
-								var facetHtmlName = getHtmlName(p.toString());
-								var href = "<a href=javascript:getResults('"; 
-								href += 	uriEncodedChosenConstraints + "','";
-								href +=		escapedFacetName + "','" + escapedFacetValue + "','deleteFacet') title='Remove'>";
-								href +=     "<img src='${it.staticRootUrl}/contenthub/images/delete_icon_16.png'></a>";
-								href +=		facetHtmlName + " : " + 
-											((isReserved(p)) ? JSONObject[p][value].substring(1,11)+" to "+JSONObject[p][value].substring(25,35) : 
-											JSONObject[p][value]) + "<br/>";
-								resultString += href;
-							}
-						}
-					}
-				}
-			}
-			var a = document.getElementById('chosenFacets');
-			if(a != null) {
-				a.innerHTML = resultString;
-			}
-		}
-				
-		function isReserved(str){
-			return str.indexOf("stanbolreserved_") == 0; 
-		}
-		
-    function getHtmlName(name){
-      if(isReserved(name)){
-        return name.substring(name.indexOf("_")+1);
+              var JSONObject = JSON.parse(jsonCons);
+              var facetValue = "[" + document.getElementById("dateFrom").value + "T00:00:00Z TO " + 
+                          document.getElementById("dateTo").value + "T23:59:59Z]";
+              JSONObject[facetName] = new Array();
+              JSONObject[facetName].push(facetValue);
+          }
+          else if(operation == "range") {
+              var facetHtmlName = getHtmlName(facetName);
+              var JSONObject = JSON.parse(jsonCons);
+              var facetValue = "[" + document.getElementById(facetHtmlName+"TextMin").value + " TO " + 
+                                     document.getElementById(facetHtmlName+"TextMax").value + "]";
+                        
+              JSONObject[facetName] = new Array();
+              JSONObject[facetName].push(facetValue);
+          }
+      
+          //make text area invisible
+          $("#searchResult").fadeOut(100);
+          $("#resultContainer").fadeOut(100);
+          //show busy icon
+          $("#busyIcon").removeClass("invisible");
+
+          var graph_selected = "";
+          var graphInCombo = document.getElementById('graphIn');
+          if(graphInCombo != null) {
+              var selectedIndex = graphInCombo.selectedIndex;
+              if(selectedIndex != 0) {
+                  graph_selected = $("#graphIn option:selected").val();
+              }
+          }
+      
+          $.ajax({
+              url : "${it.publicBaseUri}contenthub/${it.indexName}/search/featured",
+              type : "GET",
+              async: true,
+              data: {queryTerm: $("#keywordIn").val(), graph: graph_selected, constraints: JSON.stringify(JSONObject), offset: voffset, limit:vpageSize},
+              dataType: "html",
+              cache: false,
+              success: function(result) {
+                  $("#busyIcon").addClass("invisible");
+                  $("#search").addClass("invisible");
+                    
+                  $("#resultContainer > div:nth-child(2)").html(result);
+                  $(".keywords").accordion({collapsible: true, autoHeight: false });
+                  $(".keywords").removeClass("ui-widget");
+                  $(".resources > div").tabs({fx: { height: 'toggle', opacity: 'toggle' } });
+                  $("#resultContainer").fadeIn("slow");
+                   
+                  //collapsible content
+                  $(".collapseItem").click(function(e) {
+                      e.preventDefault();
+                      $(this).next(".collapseContent").slideToggle(500);
+                  }); 
+                  
+                  setChosenFacet(JSONObject);
+              },
+              error: function(result) {
+                  $("#busyIcon").addClass("invisible");
+                  alert(result.status + ' ' + result.statusText);
+              }
+          });
       }
-      lastUnderscore = name.lastIndexOf("_");
-      if (lastUnderscore >= 0) {
-        underScoreExtension = name.substring(lastUnderscore);
-        if (underScoreExtension == "_t" || underScoreExtension == "_l" || underScoreExtension == "_d" || underScoreExtension == "_dt") {
-          return name.substring(0, lastUnderscore);
-        }
+      
+      function setChosenFacet(JSONObject) {
+          var resultString = "";
+          var chosenCons = $("#chosenFacetsHidden").attr("value");
+              
+          if(JSONObject != null) {
+              for(var p in JSONObject) {
+                  if(JSONObject.hasOwnProperty(p)) {
+                      for(var value in p) {
+                          if(p.hasOwnProperty(value) && typeof(JSONObject[p][value]) != "undefined") {
+                              var escapedFacetName = escape(encodeURIComponent(p.toString()));
+                              var escapedFacetValue = escape(encodeURIComponent(JSONObject[p][value]));
+                              chosenCons = escape(chosenCons);
+                              var facetHtmlName = getHtmlName(p.toString());
+                              var href = "<a href=javascript:getResults(\""; 
+                              href +=   escapedFacetName + "\",\"" + escapedFacetValue + "\",\"deleteFacet\") title='Remove'>";
+                              href +=     "<img src='${it.staticRootUrl}/contenthub/images/delete_icon_16.png'></a>";
+                              href +=   facetHtmlName + " : " + 
+                                    ((isReserved(p)) ? JSONObject[p][value].substring(1,11)+" to "+JSONObject[p][value].substring(25,35) : 
+                                    JSONObject[p][value]) + "<br/>";
+                              resultString += href;
+                          }
+                      }
+                  }
+              }
+          }
+          
+          var a = document.getElementById('chosenFacets');
+          if(a != null) {
+              a.innerHTML = resultString;
+          }
+      }
+        
+      function isReserved(str) {
+          return str.indexOf("stanbolreserved_") == 0; 
+      }
+    
+      function getHtmlName(name) {
+          if(isReserved(name)) {
+              return name.substring(name.indexOf("_")+1);
+          }
+          lastUnderscore = name.lastIndexOf("_");
+          if (lastUnderscore >= 0) {
+              underScoreExtension = name.substring(lastUnderscore);
+              if (underScoreExtension == "_t" || underScoreExtension == "_l" || underScoreExtension == "_d" || underScoreExtension == "_dt") {
+                  return name.substring(0, lastUnderscore);
+              }
+          }
+          return name;
       }
-      return name;
-    }
-	</script>
+      
+  </script>
 </...@common.page>
 </#escape>

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/result.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/result.ftl?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/result.ftl (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/FeaturedSearchResource/result.ftl Wed Mar 21 09:38:18 2012
@@ -20,14 +20,11 @@
 <#escape x as x?html>
 <#-- limit for the more less button -->
 <#assign limit=4>
-<div id="text">
-</div>
+<div id="text"></div>
 
 <div id="result" class="result">
-<a href="${it.publicBaseUri}contenthub/${it.indexName}/search/featured">Back to Search</a></br>
-
+  <a href="${it.publicBaseUri}contenthub/${it.indexName}/search/featured">Back to Search</a></br>
   <div class="leftContainer">
-  
     <div class="keywords">
       <#list it.searchResults.relatedKeywords?keys as queryTermToken>
         <#assign queryTerm = queryTermToken?replace("*","_")?replace(" ", "_")?replace("'", "_")>
@@ -50,7 +47,7 @@
       <#if it.chosenFacets?exists && it.chosenFacets != "{}">
         <fieldset>
           <div id="chosenFacets"></div>
-          <div id="chosenFacetsHidden" class="invisible" value="${it.chosenFacets?url("UTF-8")?js_string}"/>
+          <input type="hidden" id="chosenFacetsHidden" value="${it.chosenFacets}"/>
         </fieldset>
       </#if>
     </div>
@@ -60,12 +57,8 @@
       <#if it.searchResults.facets?exists && it.searchResults.facets?size != 0>
         <fieldset>
           <#list it.searchResults.facets as facet>
-            <#if facet.values?exists>
-              <#if it.chosenFacets?exists>
-                <@facetResultMacro.facetResultMacro facetField=facet consLink=it.chosenFacets?url("UTF-8")?js_string/>
-              <#else>
-                <@facetResultMacro.facetResultMacro facetField=facet consLink="{}"/>
-              </#if>
+            <#if facet.facetField?exists>
+                <@facetResultMacro.facetResultMacro facetResult=facet/>
             </#if>
           </#list>
         </fieldset>
@@ -80,10 +73,10 @@
       <legend><h3>Results for ${it.queryTerm}:</h3></legend>
       <div>
         <ul class="spadded">
-          <#if it.searchResults.resultantDocuments?size == 0>
+          <#if it.searchResults.documents?size == 0>
           Your search did not match any documents
           <#else>
-            <#list it.resultantDocuments as docRes>
+            <#list it.documents as docRes>
               <div class="bordered-bottom">
                 <li class="lined"><a href="${it.publicBaseUri}contenthub/${it.indexName}/store/page/${docRes.localId}">${docRes.title}</a></li>
               </div>  
@@ -93,12 +86,11 @@
       </div>
     </fieldset>
     <ul class="previousNext">
-      <#assign consLinkEscaped = it.chosenFacets?url("UTF-8")?js_string/>
       <#if it.moreRecentItems?exists>
-        <li class="moreRecent"><a id="previousLink" href="javascript:getResults('${consLinkEscaped}', null, null, 'first', ${it.offset - it.pageSize}, ${it.pageSize})">Previous</a></li>
+        <li class="moreRecent"><a id="previousLink" href="javascript:getResults(null, null, 'first', ${it.offset - it.pageSize}, ${it.pageSize})">Previous</a></li>
       </#if>
       <#if it.olderItems?exists>
-        <li class="older"><a id="nextLink" href="javascript:getResults('${consLinkEscaped}', null, null, 'first', ${it.offset + it.pageSize}, ${it.pageSize})">Next</a></li>
+        <li class="older"><a id="nextLink" href="javascript:getResults(null, null, 'first', ${it.offset + it.pageSize}, ${it.pageSize})">Next</a></li>
       </#if>
     </ul>
   </div>

Modified: incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/SemanticIndexManagerResource/index.ftl
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/SemanticIndexManagerResource/index.ftl?rev=1303327&r1=1303326&r2=1303327&view=diff
==============================================================================
--- incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/SemanticIndexManagerResource/index.ftl (original)
+++ incubator/stanbol/branches/0.9.0-incubating/contenthub/web/src/main/resources/org/apache/stanbol/contenthub/web/templates/org/apache/stanbol/contenthub/web/resources/SemanticIndexManagerResource/index.ftl Wed Mar 21 09:38:18 2012
@@ -51,43 +51,43 @@
   </fieldset>
   
   <script language="javascript">
-    function submitProgram(){
-      var programName = $.trim($("#programNameText").val());
-      var ldPathProgram = $.trim($("#ldPathProgramTextArea").val());
-      
-      if(programName == "" || ldPathProgram == ""){
-        alert("You should enter an LD Program Name and LD Path Program");
-        return false;
+      function submitProgram() {
+          var programName = $.trim($("#programNameText").val());
+          var ldPathProgram = $.trim($("#ldPathProgramTextArea").val());
+          
+          if(programName == "" || ldPathProgram == "") {
+              alert("You should enter an LD Program Name and LD Path Program");
+              return false;
+          }
+          
+          $.ajax({
+              url: "${it.publicBaseUri}contenthub/ldpath/program",
+              type: "POST",
+              data: { name: programName, program: ldPathProgram },
+              success: function() {
+                  $("#submittedPrograms").load("${it.publicBaseUri}contenthub/ldpath #submittedPrograms>table");
+                  $("#programNameText").attr("value", "");
+                  $("#ldPathProgramTextArea").attr("value", "");
+              },
+              error: function(jqXHR, textStatus, errorThrown) {
+                  alert(jqXHR.status + " " + errorThrown);
+              }
+          });
       }
       
-      $.ajax({
-        url: "${it.publicBaseUri}contenthub/ldpath/program",
-        type: "POST",
-        data: { name: programName, program: ldPathProgram },
-        success: function() {
-          $("#submittedPrograms").load("${it.publicBaseUri}contenthub/ldpath #submittedPrograms>table");
-          $("#programNameText").attr("value", "");
-          $("#ldPathProgramTextArea").attr("value", "");
-        },
-        error: function(jqXHR, textStatus, errorThrown) {
-          alert(jqXHR.status + " " + errorThrown);
-        }
-      });
-    }
-    
-    function deleteProgram(programName){
-      $.ajax({
-        url: "${it.publicBaseUri}contenthub/ldpath/program/"+programName,
-        type: "DELETE",
-        async: true,
-        success: function() {
-          $("#submittedPrograms").load("${it.publicBaseUri}contenthub/ldpath #submittedPrograms>table");
-        },
-        error: function(result) {
-          alert(result.status);
-        }
-      });
-    }
+      function deleteProgram(programName) {
+          $.ajax({
+            url: "${it.publicBaseUri}contenthub/ldpath/program/"+programName,
+            type: "DELETE",
+            async: true,
+            success: function() {
+                $("#submittedPrograms").load("${it.publicBaseUri}contenthub/ldpath #submittedPrograms>table");
+            },
+            error: function(result) {
+                alert(result.status);
+            }
+          });
+      }
   </script>
   
 </...@common.page>