Exemple #1
0
  @RequestMapping("/search/{categoryId}")
  public String list(@PathVariable String categoryId, ModelMap model)
      throws SolrServerException, ParseException {
    SolrQuery query = new SolrQuery();

    query.setQuery("categoryId:" + categoryId);
    query.setRows(20);
    SolrDocumentList docs = solrServer.query(query).getResults();
    List<Article> articles = new ArrayList<Article>();
    for (SolrDocument solrDocument : docs) {
      Article article = new Article();
      article.setTitle(String.valueOf(solrDocument.getFieldValue("title")));
      article.setContent(String.valueOf(solrDocument.getFieldValue("content")));

      /** solr时间格式转换的坑,具体可参考 http://chengqianl.iteye.com/blog/1340385 */
      article.setCreateDate(
          new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
              .parse(String.valueOf(solrDocument.getFieldValue("createDate"))));
      articles.add(article);
    }

    model.addAttribute("articles", articles);

    return "/client/article/list";
  }
  @Test
  public void basicFullTextQuery() throws Exception {
    String table = "basicFullTextQuery";
    SolrServer server =
        TestTableCreator.newTable(table)
            .withRowCount(1)
            .withRecordsPerRow(2)
            .withRecordColumns("fam.value", "fam.mvf", "fam.mvf")
            .create();

    SolrQuery query = new SolrQuery("value0-0");

    QueryResponse response = server.query(query);

    assertEquals("We should get our doc back.", 1l, response.getResults().getNumFound());

    SolrDocument docResult = response.getResults().get(0);

    assertEquals("0", docResult.getFieldValue("recordid"));
    assertEquals("value0-0", docResult.getFieldValue("fam.value"));

    Collection<Object> mvfVals = docResult.getFieldValues("fam.mvf");

    assertTrue(
        "We should get all our values back[" + mvfVals + "]",
        CollectionUtils.isEqualCollection(mvfVals, Lists.newArrayList("value0-0", "value0-0")));

    removeTable(table);
  }
  protected FL_Link buildResultFromDocument(SolrDocument sd) {

    FL_Link.Builder linkBuilder = FL_Link.newBuilder();

    FL_PropertyDescriptors linkDescriptors = _applicationConfiguration.getLinkDescriptors();
    FL_PropertyDescriptors entityDescriptors = _applicationConfiguration.getEntityDescriptors();

    final String type = getTypeFromDocument(sd, linkDescriptors);

    Boolean isMultitype = (entityDescriptors.getTypes().size() > 1);

    String uid =
        sd.getFieldValue(
                PropertyDescriptorHelper.mapKey(
                    FL_RequiredPropertyKey.ID.name(), linkDescriptors.getProperties(), type))
            .toString();

    Object oSource =
        sd.getFieldValue(
            PropertyDescriptorHelper.mapKey(
                FL_RequiredPropertyKey.FROM.name(), linkDescriptors.getProperties(), type));
    String sSource =
        oSource instanceof String
            ? (String) oSource
            : oSource instanceof Integer ? Integer.toString((Integer) oSource) : null;

    linkBuilder.setProvenance(null);
    linkBuilder.setUncertainty(null);
    linkBuilder.setType(type);

    List<FL_Property> props = getPropertiesFromDocument(sd, type, linkDescriptors.getProperties());

    linkBuilder.setProperties(props);

    linkBuilder.setLinkTypes(null);

    linkBuilder.setUid(_namespaceHandler.globalFromLocalEntityId(InfluentId.LINK, type, uid));

    String sourceUID = null;
    if (sSource != null) {
      InfluentId infId;
      if (isMultitype) {
        infId = InfluentId.fromTypedId(InfluentId.ACCOUNT, sSource);
      } else {
        infId =
            InfluentId.fromNativeId(
                InfluentId.ACCOUNT, entityDescriptors.getTypes().get(0).getKey(), sSource);
      }
      sourceUID = infId.toString();
    }

    linkBuilder.setSource(sourceUID);
    linkBuilder.setTarget(getTarget(sd));

    return linkBuilder.build();
  }
Exemple #4
0
  @RequestMapping("/search")
  public String search(ModelMap model) throws SolrServerException {
    SolrQuery query = new SolrQuery();

    /** 设置多条filterQuery语句有助于提高内存效率;组合查询条件设置单条filterQuery语句损耗内存多,但可以优化性能 可以采用 AND 或 OR 关键字 来设置查询与或 */
    query.setQuery("title:北京  OR content:北京");

    query.setRows(20);

    // 设置高亮
    query.setHighlight(true); // 开启高亮组件
    query.addHighlightField("title"); // 高亮字段
    query.addHighlightField("content"); // 高亮字段
    query.setHighlightSimplePre("<font color='red'>"); // 标记,高亮关键字前缀
    query.setHighlightSimplePost("</font>"); // 后缀
    query
        .setHighlight(true)
        .setHighlightSnippets(
            1); // 获取高亮分片数,一般搜索词可能分布在文章中的不同位置,其所在一定长度的语句即为一个片段,默认为1,但根据业务需要有时候需要多取出几个分片。 -
                // 此处设置决定下文中titleList, contentList中元素的个数
    query.setHighlightFragsize(150); // 每个分片的最大长度,默认为100。适当设置此值,如果太小,高亮的标题可能会显不全;设置太大,摘要可能会太长。

    QueryResponse response = solrServer.query(query);
    SolrDocumentList docs = response.getResults();

    // 获取所有高亮的字段
    Map<String, Map<String, List<String>>> highlightMap = response.getHighlighting();

    List<Article> articles = new ArrayList<Article>();
    for (SolrDocument solrDocument : docs) {
      Article article = new Article();

      List<String> titleList = highlightMap.get(solrDocument.getFieldValue("id")).get("title");
      List<String> contentList = highlightMap.get(solrDocument.getFieldValue("id")).get("content");

      // 获取并设置高亮的字段title
      if (titleList != null && titleList.size() > 0) {
        article.setTitle(titleList.get(0));
      }

      // 获取并设置高亮的字段content
      if (contentList != null && contentList.size() > 0) {
        article.setContent(contentList.get(0));
      }

      articles.add(article);
    }

    model.addAttribute("articles", articles);

    return "/client/article/list";
  }
  public SearchResponse search(SearchRequest request) {
    SolrQuery query = new SolrQuery();
    query.setRows(request.getLimit());
    query.setStart(request.getOffset() * request.getLimit());
    BooleanQuery aggregate = new BooleanQuery();
    if (!StringUtils.isBlank(request.getText())) {
      TermQuery termQuery = new TermQuery(new Term("", request.getText()));
      aggregate.add(termQuery, BooleanClause.Occur.SHOULD);
    }
    if (!StringUtils.isBlank(request.getEventId())) {
      aggregate.add(
          new TermQuery(new Term("eventid", request.getEventId())), BooleanClause.Occur.MUST);
    }
    query.setQuery(aggregate.toString());

    log.info("QUERY IS: " + query.toString());
    try {
      QueryResponse queryResponse = solrServer.query(query);
      log.info("RESPONSE FROM QUERY WAS: " + queryResponse);
      SolrDocumentList results = queryResponse.getResults();
      log.info("RESULTS WAS: " + results);
      ArrayList<SearchResponse.Hit> hits = new ArrayList<SearchResponse.Hit>();
      for (SolrDocument result : results) {
        hits.add(
            new SearchResponse.Hit(
                ObjectType.session, String.valueOf(result.getFieldValue("id")), null));
      }
      return new SearchResponse(results.getNumFound(), queryResponse.getElapsedTime(), hits);
    } catch (SolrServerException e) {
      e.printStackTrace();
    }
    return null;
  }
  /**
   * This method is used to index the bib info to holdings or items
   *
   * @param solrInputDocument - holdings or items solr input documents
   * @param sourceDocument -
   */
  protected void setBibInfoForHoldingsOrItems(
      SolrInputDocument solrInputDocument, SolrDocument sourceDocument) {
    if (sourceDocument != null) {
      solrInputDocument.setField(TITLE_SEARCH, sourceDocument.getFieldValues(TITLE_SEARCH));
      solrInputDocument.setField(TITLE_SORT, sourceDocument.getFieldValues(TITLE_SORT));
      solrInputDocument.setField(AUTHOR_SEARCH, sourceDocument.getFieldValues(AUTHOR_SEARCH));
      solrInputDocument.setField(
          PUBLICATIONPLACE_DISPLAY, sourceDocument.getFieldValues(PUBLICATIONPLACE_DISPLAY));
      solrInputDocument.setField(PUBLISHER_SEARCH, sourceDocument.getFieldValues(PUBLISHER_SEARCH));
      solrInputDocument.setField(PUBLISHER_SORT, sourceDocument.getFieldValue(PUBLISHER_SORT));
      solrInputDocument.setField(ISSN_SEARCH, sourceDocument.getFieldValues(ISSN_SEARCH));
      solrInputDocument.setField(ISBN_SEARCH, sourceDocument.getFieldValues(ISBN_SEARCH));
      solrInputDocument.setField(FORMAT_SEARCH, sourceDocument.getFieldValues(FORMAT_SEARCH));
      solrInputDocument.setField(LANGUAGE_SEARCH, sourceDocument.getFieldValues(LANGUAGE_SEARCH));
      solrInputDocument.setField(
          PUBLICATIONDATE_SEARCH, sourceDocument.getFieldValues(PUBLICATIONDATE_SEARCH));
      solrInputDocument.setField(MDF_035A, sourceDocument.getFieldValues(MDF_035A));

      solrInputDocument.setField(TITLE_DISPLAY, sourceDocument.getFieldValues(TITLE_DISPLAY));
      solrInputDocument.setField(AUTHOR_DISPLAY, sourceDocument.getFieldValues(AUTHOR_DISPLAY));
      solrInputDocument.setField(
          PUBLISHER_DISPLAY, sourceDocument.getFieldValues(PUBLISHER_DISPLAY));
      solrInputDocument.setField(ISSN_DISPLAY, sourceDocument.getFieldValues(ISSN_DISPLAY));
      solrInputDocument.setField(ISBN_DISPLAY, sourceDocument.getFieldValues(ISBN_DISPLAY));
      solrInputDocument.setField(FORMAT_DISPLAY, sourceDocument.getFieldValues(FORMAT_DISPLAY));
      solrInputDocument.setField(LANGUAGE_DISPLAY, sourceDocument.getFieldValues(LANGUAGE_DISPLAY));
      solrInputDocument.setField(
          PUBLICATIONDATE_DISPLAY, sourceDocument.getFieldValues(PUBLICATIONDATE_DISPLAY));
    }
  }
  private void returnFields(ResponseBuilder rb, ShardRequest sreq) {
    // Keep in mind that this could also be a shard in a multi-tiered system.
    // TODO: if a multi-tiered system, it seems like some requests
    // could/should bypass middlemen (like retrieving stored fields)
    // TODO: merge fsv to if requested

    if ((sreq.purpose & ShardRequest.PURPOSE_GET_FIELDS) != 0) {
      boolean returnScores = (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0;

      assert (sreq.responses.size() == 1);
      ShardResponse srsp = sreq.responses.get(0);
      SolrDocumentList docs =
          (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");

      String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();

      for (SolrDocument doc : docs) {
        Object id = doc.getFieldValue(keyFieldName);
        ShardDoc sdoc = rb.resultIds.get(id.toString());
        if (sdoc != null) {
          if (returnScores && sdoc.score != null) {
            doc.setField("score", sdoc.score);
          }
          rb._responseDocs.set(sdoc.positionInResponse, doc);
        }
      }
    }
  }
Exemple #8
0
 /**
  * @param d SolrDocument to convert
  * @return a SolrInputDocument with the same fields and values as the SolrDocument. All boosts are
  *     1.0f
  */
 public static SolrInputDocument toSolrInputDocument(SolrDocument d) {
   SolrInputDocument doc = new SolrInputDocument();
   for (String name : d.getFieldNames()) {
     doc.addField(name, d.getFieldValue(name), 1.0f);
   }
   return doc;
 }
 private List<RetrievalResult> retrieveDocuments(String query) {
   List<RetrievalResult> result = new ArrayList<RetrievalResult>();
   try {
     SolrDocumentList docs = wrapper.runQuery(query, hitListSize);
     for (SolrDocument doc : docs) {
       RetrievalResult r =
           new RetrievalResult(
               (String) doc.getFieldValue("id"), (Float) doc.getFieldValue("score"), query);
       result.add(r);
       System.out.println(doc.getFieldValue("id"));
     }
   } catch (Exception e) {
     System.err.println("Error retrieving documents from Solr: " + e);
   }
   return result;
 }
Exemple #10
0
 /**
  * Returns a mods document, which is embedded in escaped xml form in the originalMods field of
  * each solr document. This escaped string is unmarshalled (jaxb) into a loc.gov.mods.v3.ModsType
  * (and all child elements) and returned as an individual item or added to a search result set
  *
  * @param doc a SolrDocument from which to extract the mods record
  * @return the ModsType
  * @see ModsType
  */
 protected ModsType getModsType(SolrDocument doc) throws JAXBException {
   String modsString = (String) doc.getFieldValue("originalMods");
   Unmarshaller unmarshaller = JAXBHelper.context.createUnmarshaller();
   StringReader reader = new StringReader(modsString);
   ModsType modsType = (ModsType) ((JAXBElement) (unmarshaller.unmarshal(reader))).getValue();
   return modsType;
 }
  @Test
  public void fieldsRequestsShouldTurnIntoSelectors() throws Exception, TException {

    String table = "fieldsRequestsShouldTurnIntoSelectors";
    SolrServer server =
        TestTableCreator.newTable(table)
            .withRowCount(1)
            .withRecordsPerRow(2)
            .withRecordColumns("fam.value", "fam.mvf")
            .create();

    SolrQuery query = new SolrQuery("value0-0");
    query.setFields("fam.value");
    QueryResponse response = server.query(query);

    assertEquals(
        "We should get our doc back for a valid test.", 1l, response.getResults().getNumFound());

    SolrDocument docResult = response.getResults().get(0);

    assertEquals("value0-0", docResult.getFieldValue("fam.value"));
    assertNull(
        "We shouldn't get this one back since it wasnt in our fields.",
        docResult.getFieldValues("fam.mvf"));

    removeTable(table);
  }
  private static SeadEvent getEvent(SolrDocument doc) {
    SeadEvent event = new SeadEvent();

    event.setId(get(doc, EntityField.ID));

    Date date = (Date) doc.getFirstValue(EventField.DATE.solrName());

    if (date != null) {
      event.setDate(DateUtil.getThreadLocalDateFormat().format(date));
    }

    event.setDetail(getFirst(doc, EventField.DETAIL));
    event.setOutcome(getFirst(doc, EventField.OUTCOME));
    event.setEventType(getFirst(doc, EventField.TYPE));
    event.setTargets(getEntityRefSet(doc, EventField.TARGET));
    event.setAlternateIds(getResourceIdentifierSet(doc));

    SeadLogDetail logDetail = new SeadLogDetail();

    //   if (has(doc, DetailLogField.IPADDRESS)) {

    logDetail.setIpAddress(
        (String) doc.getFieldValue(SeadSolrField.DetailLogField.IPADDRESS.solrName()));
    //  }
    if (has(doc, SeadSolrField.DetailLogField.USERAGENT)) {

      logDetail.setUserAgent(
          (String) doc.getFieldValue(SeadSolrField.DetailLogField.USERAGENT.solrName()));
    }
    if (has(doc, SeadSolrField.DetailLogField.SUBJECT)) {

      logDetail.setSubject(
          (String) doc.getFieldValue(SeadSolrField.DetailLogField.SUBJECT.solrName()));
    }
    if (has(doc, SeadSolrField.DetailLogField.NODEIDENTIFIER)) {

      logDetail.setNodeIdentifier(
          (String) doc.getFieldValue(SeadSolrField.DetailLogField.NODEIDENTIFIER.solrName()));
    }

    event.setLogDetail(logDetail);

    return event;
  }
  @Override
  protected void execute(Search search, SearchKey key, SolrDocumentList documents)
      throws ActionException {
    Parameter param = em.find(Parameter.class, "SEARCH_REPO");
    String repo = param.getValue();
    File repoDir =
        new File(
            repo + File.separator + search.getConfig().getId() + File.separator + search.getId());
    repoDir.mkdirs();

    ImageRenderer imageRenderer = new ImageRenderer();
    Transcoder transcoder = new PDFTranscoder();
    for (SolrDocument doc : documents) {
      String docUrl = (String) doc.getFieldValue(URL.toString());
      String docTitle = (String) doc.getFieldValue(TITLE.toString());
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      File outputFile = new File(repoDir.getAbsolutePath() + File.separator + docTitle + ".pdf");
      try {
        imageRenderer.renderURL(docUrl, outputStream, ImageRenderer.Type.SVG);
      } catch (IOException | SAXException e) {
        log.error("SVG rendering problem", e);
        createErrorFile(docUrl, outputFile, e);
        continue;
      }
      byte[] svgBytes = outputStream.toByteArray();
      ByteArrayInputStream inputStream = new ByteArrayInputStream(svgBytes);
      TranscoderInput transcoderInput = new TranscoderInput(inputStream);
      TranscoderOutput transcoderOutput = null;
      try {
        transcoderOutput = new TranscoderOutput(new FileOutputStream(outputFile));
      } catch (FileNotFoundException e) {
        log.warn("this shouldn't happen!", e);
        createErrorFile(docUrl, outputFile, e);
        continue;
      }
      try {
        transcoder.transcode(transcoderInput, transcoderOutput);
      } catch (TranscoderException e) {
        log.warn("Transcoding problem", e);
        createErrorFile(docUrl, outputFile, e);
        continue;
      }
    }
  }
 private void assertOrder(QueryResponse rsp, String... docs) throws Exception {
   SolrDocumentList list = rsp.getResults();
   for (int i = 0; i < docs.length; i++) {
     SolrDocument doc = list.get(i);
     Object o = doc.getFieldValue("id");
     if (!docs[i].equals(o)) {
       throw new Exception("Order is not correct:" + o + "!=" + docs[i]);
     }
   }
 }
  public Float getFloat(String key, Float defaultValue) {
    Object obj = m_doc.getFieldValue(key);
    if (null != obj) {
      if (obj instanceof Float) {
        return (Float) obj;
      } else {
        s_logCategory.error("field " + key + " is not of type Float");
      }
    }

    return defaultValue;
  }
  public Date getDate(String key, Date defaultValue) {
    Object obj = m_doc.getFieldValue(key);
    if (null != obj) {
      if (obj instanceof Date) {
        return (Date) obj;
      } else {
        s_logCategory.error("field " + key + " is not of type Date");
      }
    }

    return defaultValue;
  }
  public Boolean getBoolean(String key, Boolean defaultValue) {
    Object obj = m_doc.getFieldValue(key);
    if (null != obj) {
      if (obj instanceof Boolean) {
        return (Boolean) obj;
      } else {
        s_logCategory.error("field " + key + " is not of type Boolean");
      }
    }

    return defaultValue;
  }
  public Integer getInt(String key, Integer defaultValue) {
    Object obj = m_doc.getFieldValue(key);
    if (null != obj) {
      if (obj instanceof Integer) {
        return (Integer) obj;
      } else {
        s_logCategory.error("field " + key + " is not of type Integer");
      }
    }

    return defaultValue;
  }
  public Long getLong(String key, Long defaultValue) {
    Object obj = m_doc.getFieldValue(key);
    if (null != obj) {
      if (obj instanceof Long) {
        return (Long) obj;
      } else {
        s_logCategory.error("field " + key + " is not of type Long");
      }
    }

    return defaultValue;
  }
 /** Prepend the server context path to the location of search result documents. */
 private void setSearchResultContext(NamedList<Object> values, String contextPath) {
   // find the search result documents in the search response
   SolrDocumentList documents = (SolrDocumentList) values.get("response"); // $NON-NLS-1$
   if (documents == null) return;
   for (SolrDocument doc : documents) {
     String location = (String) doc.getFieldValue(ProtocolConstants.KEY_LOCATION);
     if (location != null) {
       // prepend the context path and update the document
       location = contextPath + location;
       doc.setField(ProtocolConstants.KEY_LOCATION, location);
     }
   }
 }
  public String getString(String key, String defaultValue) {
    //        if("mailto".equals(key) || "mailcc".equals(key)){
    //            return flattenStringArray(key, " ", defaultValue);
    //        }
    Object obj = m_doc.getFieldValue(key);
    if (null != obj) {
      if (obj instanceof String) {
        return (String) obj;
      } else {
        s_logCategory.error("field " + key + " is not of type String");
      }
    }

    return defaultValue;
  }
Exemple #22
0
  protected void execute() throws Exception {

    SolrServer server = new HttpSolrServer("http://localhost:8983/solr");
    SolrQuery query = new SolrQuery("text:ipod");
    QueryResponse response = server.query(query);

    SolrDocumentList docList = response.getResults();
    System.out.println("件数:" + docList.size());
    for (SolrDocument doc : docList) {
      System.out.println("■");
      for (String fieldName : doc.getFieldNames()) {
        System.out.println(fieldName.toString() + ":" + doc.getFieldValue(fieldName.toString()));
      }
    }
  }
  // Build an FL_Link result from a list of SolrDocuments returned from a group command in a query
  protected FL_Link buildResultFromGroupedDocuments(SolrDocumentList dl) {

    // Build the initial result from the first document
    FL_Link link = buildResultFromDocument(dl.get(0));

    // Get the nodetype
    String targetField =
        PropertyDescriptorHelper.mapKey(
            FL_RequiredPropertyKey.TO.name(),
            _applicationConfiguration.getLinkDescriptors().getProperties(),
            link.getType());

    // Add the remaining document properties to the entity
    // Currently only the TO field is aggregated from grouping of one-to-many links
    for (int i = 1; i < dl.size(); i++) {
      SolrDocument sd = dl.get(i);
      String target = (String) sd.getFieldValue(targetField);

      FL_Property property = null;
      List<FL_Property> properties = link.getProperties();
      for (FL_Property prop : link.getProperties()) {
        if (prop.getKey().equals(FL_RequiredPropertyKey.TO.name())) {
          property = prop;
        }
      }

      if (property != null) {
        Object range = property.getRange();

        if (range instanceof FL_ListRange) {
          List<Object> values = ((FL_ListRange) range).getValues();
          values.add(target);
        } else if (range instanceof FL_SingletonRange) {
          List<Object> values = new ArrayList<Object>();
          values.add(((FL_SingletonRange) range).getValue());
          values.add(target);
          property.setRange(
              FL_ListRange.newBuilder().setType(FL_PropertyType.STRING).setValues(values).build());
        }

        link.setProperties(properties);
      }

      link.setTarget(link.getTarget() + "," + getTarget(sd));
    }

    return link;
  }
Exemple #24
0
  @Override
  public boolean next(LongWritable keyHolder, MapWritable valueHolder) throws IOException {
    SolrDocument doc = cursor.nextDocument();
    if (doc == null) {
      return false;
    }

    keyHolder.set(pos++);

    for (int i = 0; i < readColumns.length; i++) {
      String key = readColumns[i];
      Object vObj = doc.getFieldValue(key);
      Writable value = (vObj == null) ? NullWritable.get() : new Text(vObj.toString());
      valueHolder.put(new Text(key), value);
    }
    return true;
  }
  @Override
  public void writeSolrDocument(
      String name, SolrDocument doc, Set<String> returnFields, Map pseudoFields)
      throws IOException {
    writeMapOpener(-1); // no trivial way to determine map size
    // TODO: could easily figure out size for SolrDocument if needed...
    incLevel();

    boolean first = true;
    for (String fname : doc.getFieldNames()) {
      if (returnFields != null && !returnFields.contains(fname)) {
        continue;
      }
      if (first) {
        first = false;
      } else {
        writeMapSeparator();
      }

      indent();
      writeKey(fname, true);
      Object val = doc.getFieldValue(fname);

      if (val instanceof Collection) {
        writeVal(fname, val);
      } else {
        // if multivalued field, write single value as an array
        SchemaField sf = schema.getFieldOrNull(fname);
        if (sf != null && sf.multiValued()) {
          writeArrayOpener(-1); // no trivial way to determine array size
          writeVal(fname, val);
          writeArrayCloser();
        } else {
          writeVal(fname, val);
        }
      }

      if (pseudoFields != null && pseudoFields.size() > 0) {
        writeMap(null, pseudoFields, true, first);
      }
    }

    decLevel();
    writeMapCloser();
  }
Exemple #26
0
  public SearchItem(
      SolrDocument doc,
      UserDao userDao,
      MsgbaseDao msgbaseDao,
      LorCodeService lorCodeService,
      boolean secure) {
    msgid = (String) doc.getFieldValue("id");
    title = (String) doc.getFieldValue("title");
    topicTitle = (String) doc.getFieldValue("topic_title");
    int userid = (Integer) doc.getFieldValue("user_id");
    Date postdate_dt = (Date) doc.getFieldValue("postdate");
    postdate = new Timestamp(postdate_dt.getTime());
    topic = (Integer) doc.getFieldValue("topic_id");
    section = (String) doc.getFieldValue("section");

    if (!"wiki".equals(section)) {
      virtualWiki = null;
      MessageText messageText = msgbaseDao.getMessageText(Integer.valueOf(msgid));
      String rawMessage = messageText.getText();
      if (messageText.isLorcode()) {
        message = lorCodeService.parseComment(rawMessage, secure);
      } else {
        message = rawMessage;
      }
    } else {
      // Wiki id like <virtual_wiki>-<topic_id>
      String[] msgIds = msgid.split("-");
      if (msgIds.length != 2) {
        throw new RuntimeException("Invalid wiki ID");
      }

      String content = msgbaseDao.getMessageTextFromWiki(Integer.valueOf(msgIds[1]));
      String msg = StringUtil.escapeHtml(content.substring(0, Math.min(1300, content.length())));
      if (Math.min(1300, content.length()) == 1300) {
        message = msg + "...";
      } else {
        message = msg;
      }
      virtualWiki = msgIds[0];
    }
    try {
      user = userDao.getUserCached(userid);
    } catch (UserNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
Exemple #27
0
 private List<Item> parseSearchResults(final SolrDocumentList results) {
   final Iterator<SolrDocument> it = results.iterator();
   final List<Item> items = new ArrayList<Item>();
   while (it.hasNext()) {
     final SolrDocument document = it.next();
     final Map<String, Object> clonedValueMap = new HashMap<String, Object>();
     final Collection<String> fieldNames = document.getFieldNames();
     for (final String fieldName : fieldNames) {
       if (!ignorableFields.contains(fieldName)) {
         clonedValueMap.put(fieldName, document.getFieldValue(fieldName));
       }
     }
     final String json = JsonSerializer.serialize(clonedValueMap);
     if (json != null) {
       items.add(ItemParser.parseItem(json));
     }
   }
   return items;
 }
  private String getTarget(SolrDocument sd) {
    FL_PropertyDescriptors linkDescriptors = _applicationConfiguration.getLinkDescriptors();
    FL_PropertyDescriptors entityDescriptors = _applicationConfiguration.getEntityDescriptors();

    final String type = getTypeFromDocument(sd, linkDescriptors);

    Object oTarget =
        sd.getFieldValue(
            PropertyDescriptorHelper.mapKey(
                FL_RequiredPropertyKey.TO.name(), linkDescriptors.getProperties(), type));
    String sTarget =
        oTarget instanceof String
            ? (String) oTarget
            : oTarget instanceof Integer ? Integer.toString((Integer) oTarget) : null;

    Boolean isMultitype = (entityDescriptors.getTypes().size() > 1);

    String targetUID = "";
    for (String individualTarget : sTarget.split("\\s*,\\s*")) {
      String individualTargetUID = null;
      if (individualTarget != null) {
        char toClass = InfluentId.ACCOUNT;
        String toType;
        if (isMultitype) {
          InfluentId infId = InfluentId.fromTypedId(toClass, individualTarget);
          toType = infId.getIdType();
          individualTarget = infId.getNativeId();
        } else {
          toType = entityDescriptors.getTypes().get(0).getKey();
        }
        individualTargetUID =
            _namespaceHandler.globalFromLocalEntityId(toClass, toType, individualTarget);
      }
      if (individualTargetUID != null) {
        targetUID += individualTargetUID + ",";
      }
    }
    targetUID = targetUID.substring(0, targetUID.length() - 1);

    return targetUID;
  }
  @Test
  public void weShouldBeAbleToPageResults()
      throws SolrServerException, IOException, BlurException, TException {
    String table = "weShouldBeAbleToPageResults";
    SolrServer server = createServerAndTableWithSimpleTestDoc(table);

    SolrQuery query = new SolrQuery("123");
    query.setFields("fam.value");
    QueryResponse response = server.query(query);

    assertEquals(
        "We should get our doc back for a valid test.", 1l, response.getResults().getNumFound());

    SolrDocument docResult = response.getResults().get(0);

    assertEquals("123", docResult.getFieldValue("fam.value"));
    assertNull(
        "We shouldn't get this one back since it wasnt in our fields.",
        docResult.getFieldValues("fam.mvf"));

    removeTable(table);
  }
  /**
   * *
   *
   * @param query
   * @param pageCount
   * @param rows
   * @returns the list of discussion question
   */
  public Object[] fetchDiscussionData(String query, int pageCount, int rows) {
    try {

      SolrServer server = Adder.getSolrServer(serverurlConstants.ADD_DISSCUSSION_QUESTION_URL);
      ModifiableSolrParams params = new ModifiableSolrParams();
      params.set("q", query);
      params.set("sort", "AnswerCount desc,LastRepliedDate desc,Rating desc");
      params.set("start", "" + pageCount);
      params.set("version", "2.2");
      params.set("wt", "json");
      params.set("indent", "on");
      params.set("rows", rows);

      QueryResponse response = server.query(params, SolrRequest.METHOD.POST);

      List<DiscussionQuestion> questions = new ArrayList<DiscussionQuestion>();
      for (SolrDocument updatesDoc : response.getResults()) {
        DiscussionQuestion discussionQuestion = new DiscussionQuestion();
        discussionQuestion.setID(updatesDoc.getFieldValue("ID").toString());
        discussionQuestion.setCreatedUserID(updatesDoc.getFieldValue("CreatedUserID").toString());
        discussionQuestion.setQuestionText(updatesDoc.getFieldValue("QuestionText").toString());
        discussionQuestion.setCreatedDate(updatesDoc.getFieldValue("CreatedDate").toString());
        discussionQuestion.setTags(updatesDoc.getFieldValue("Tags").toString());
        discussionQuestion.setRating(updatesDoc.getFieldValue("Rating").toString());
        discussionQuestion.setCreatedUserDisplayName(
            updatesDoc.getFieldValue("CreatedUserDisplayName").toString());
        discussionQuestion.setCreatedUserScreenName(
            updatesDoc.getFieldValue("CreatedUserScreenName").toString());
        discussionQuestion.setCategoryName(updatesDoc.getFieldValue("CategoryName").toString());
        discussionQuestion.setAnswerCount(updatesDoc.getFieldValue("AnswerCount").toString());
        discussionQuestion.setCreatedUserType(
            updatesDoc.getFieldValue("CreatedUserType").toString());
        // Date dateString = (Date) updatesDoc.getFieldValue("LastRepliedDate");
        // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        discussionQuestion.setLastRepliedDate(
            updatesDoc.getFieldValue("LastRepliedDate").toString());
        questions.add(discussionQuestion);
      }
      Object[] resultArr = new Object[2];
      String numFound = response.getResults().getNumFound() + "";
      resultArr[0] = questions;
      resultArr[1] = numFound;

      return resultArr;
    } catch (SolrServerException e) {
      throw new DataAccessResourceFailureException(e.getMessage(), e);
    }
  }