コード例 #1
0
  @Override
  public Hits search(SearchContext searchContext) throws SearchException {
    Hits hits = super.search(searchContext);

    String[] queryTerms = hits.getQueryTerms();

    String keywords = searchContext.getKeywords();

    queryTerms = ArrayUtil.append(queryTerms, KnowledgeBaseUtil.parseKeywords(keywords));

    hits.setQueryTerms(queryTerms);

    return hits;
  }
コード例 #2
0
  public String search(
      HttpServletRequest request,
      long groupId,
      long userId,
      String keywords,
      int startPage,
      int itemsPerPage,
      String format)
      throws SearchException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      int start = (startPage * itemsPerPage) - itemsPerPage;
      int end = startPage * itemsPerPage;

      Hits results =
          CompanyLocalServiceUtil.search(themeDisplay.getCompanyId(), userId, keywords, start, end);

      String[] queryTerms = results.getQueryTerms();

      int total = results.getLength();

      Object[] values =
          addSearchResults(
              queryTerms,
              keywords,
              startPage,
              itemsPerPage,
              total,
              start,
              "Liferay Portal Search: " + keywords,
              SEARCH_PATH,
              format,
              themeDisplay);

      com.liferay.portal.kernel.xml.Document doc =
          (com.liferay.portal.kernel.xml.Document) values[0];
      Element root = (Element) values[1];

      for (int i = 0; i < results.getDocs().length; i++) {
        Document result = results.doc(i);

        String portletId = result.get(Field.PORTLET_ID);

        Portlet portlet =
            PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);

        if (portlet == null) {
          continue;
        }

        String portletTitle = PortalUtil.getPortletTitle(portletId, themeDisplay.getUser());

        long resultGroupId = GetterUtil.getLong(result.get(Field.GROUP_ID));

        String entryClassName = GetterUtil.getString(result.get(Field.ENTRY_CLASS_NAME));

        long entryClassPK = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK));

        String title = StringPool.BLANK;

        PortletURL portletURL = getPortletURL(request, portletId, resultGroupId);

        String url = portletURL.toString();

        Date modifedDate = result.getDate(Field.MODIFIED);

        String content = StringPool.BLANK;

        if (Validator.isNotNull(portlet.getIndexerClass())) {
          Indexer indexer = (Indexer) InstancePool.get(portlet.getIndexerClass());

          String snippet = results.snippet(i);

          Summary summary = indexer.getSummary(result, snippet, portletURL);

          title = summary.getTitle();
          url = portletURL.toString();
          content = summary.getContent();

          if (portlet.getPortletId().equals(PortletKeys.JOURNAL)) {
            url = getJournalURL(themeDisplay, resultGroupId, result);
          }
        }

        double score = results.score(i);

        addSearchResult(
            root,
            resultGroupId,
            entryClassName,
            entryClassPK,
            portletTitle + " " + CharPool.RAQUO + " " + title,
            url,
            modifedDate,
            content,
            score,
            format);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Return\n" + doc.asXML());
      }

      return doc.asXML();

    } catch (Exception e) {
      throw new SearchException(e);
    }
  }