Package org.apache.lucene.document

Examples of org.apache.lucene.document.Document


  /**
   * Generate a lucene document from the data stored in this document
   * @return
   */
  public Document getLuceneDocument() {
    Document document = new Document();
    document.add( createField(TITLE_FIELD_NAME,getTitle(), Field.Index.ANALYZED,4) );
    document.add( createField(DESCRIPTION_FIELD_NAME,getDescription(), Field.Index.ANALYZED,2) );
    document.add( createField(CONTENT_FIELD_NAME,getContent(), Field.Index.ANALYZED, 0.5f ) );
    document.add(new Field(RESOURCEURL_FIELD_NAME,getResourceUrl(), Field.Store.YES, Field.Index.NOT_ANALYZED) );//SET to ANALYZED
    document.add(new Field(DOCUMENTTYPE_FIELD_NAME,getDocumentType(), Field.Store.YES, Field.Index.NOT_ANALYZED) );
    if(getCssIcon() != null)
      document.add(new Field(CSS_ICON,getCssIcon(), Field.Store.YES, Field.Index.NOT_ANALYZED) );
    document.add(new Field(FILETYPE_FIELD_NAME,getFileType(), Field.Store.YES, Field.Index.NOT_ANALYZED) );
    document.add( createField(AUTHOR_FIELD_NAME,getAuthor(), Field.Index.ANALYZED, 2) );
      try {
        if(getCreatedDate() != null) {
          document.add(new Field(CREATED_FIELD_NAME,DateTools.dateToString(getCreatedDate(), DateTools.Resolution.DAY), Field.Store.YES, Field.Index.ANALYZED) );
        }
      }catch (Exception ex) {
        // No createdDate set => does not add field
      }
      try {
        if(getLastChange() != null) {
        document.add(new Field(CHANGED_FIELD_NAME,DateTools.dateToString(getLastChange(), DateTools.Resolution.DAY), Field.Store.YES, Field.Index.ANALYZED) );
        }
      }catch (Exception ex) {
        // No changedDate set => does not add field
      }
      try {
        if(getTimestamp() != null) {
        document.add(new Field(TIME_STAMP_NAME,DateTools.dateToString(getTimestamp(), DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.NO) );
        }
      }catch (Exception ex) {
        // No changedDate set => does not add field
      }
      // Add various metadata
      if (metadata != null) {
        for (Entry<String, List<String>> metaDataEntry : metadata.entrySet()) {
          String key = metaDataEntry.getKey();
          List<String> values = metaDataEntry.getValue();
          for (String value : values) {
            //FIXME:FG: tokenized or not? which priority
            document.add( createField(key, value, Field.Index.ANALYZED, 2) );
          }
        }
      }
      document.add(new Field(PARENT_CONTEXT_TYPE_FIELD_NAME,getParentContextType(), Field.Store.YES, Field.Index.ANALYZED) );
      document.add(new Field(PARENT_CONTEXT_NAME_FIELD_NAME,getParentContextName(), Field.Store.YES, Field.Index.ANALYZED) );
      return document;
  }
View Full Code Here


    Hits hits = searcher.search(query);
    nrOfHits = hits.length();
    logger.info("Query returned " + nrOfHits + " hits.");
    List<ItemResult> results = new ArrayList<ItemResult>();
    for (int i = 0; i < hits.length() && i < maxResults; i++) {
      Document doc = hits.doc(i);
      long channelId = Long.parseLong(doc.get(ItemFieldConstants.CHANNEL_ID));
      ChannelIF channel = channels.getById(channelId);
      if (channel == null) {
        throw new UnretrievableException("channel " + channelId);
      }
      // TODO: could this be done in another fashion or using a context?
      long itemId = Long.parseLong(doc.get(ItemFieldConstants.ITEM_ID));
      ItemIF item = channel.getItem(itemId);
      if (item == null) {
        throw new UnretrievableException("item " + itemId);
      }
      results.add(new ItemResult(item, hits.score(i)));
View Full Code Here

      // Used as base-set for a NOT-Query
      inverse = new Field("true", "yes", Field.Store.NO,
          Field.Index.ANALYZED);
      inverse.setOmitTermFreqAndPositions(true);

      document = new Document();
      document.add(fulltext);
      document.add(inverse);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
View Full Code Here

   *   <li><code>id</code>--containing the identifier of
   *       the item as a unindexed field (for later retrieval).
   * </ul>
   */
  public static Document makeDocument(ItemIF item) {
    Document doc = new Document();
    doc.add(Field.Text(TITLE, item.getTitle()));
    doc.add(Field.Text(DESCRIPTION, item.getDescription()));
    doc.add(Field.Text(TITLE_AND_DESC, item.getTitle() + " " +
                       item.getDescription()));
    // Keyword field is not tokenized for not breaking the date
    if (item.getFound() != null) {
      doc.add(Field.Keyword(DATE_FOUND,
                            DateField.dateToString(item.getFound())));
    }
    // Unindexed field for later retrieval of the item
    doc.add(Field.UnIndexed(ITEM_ID, Long.toString(item.getId())));
    // Unindexed field for later retrieval of the channel
    if (item.getChannel() != null) {
      doc.add(Field.UnIndexed(CHANNEL_ID,
                              Long.toString(item.getChannel().getId())));
    }
    return doc;
  }
View Full Code Here

        for (int i=0; i < files.length; i++) {
          File file = files[i];
          if (!file.exists() || file.isDirectory()) continue; // ignore
          bytes += file.length();
          String text = toString(new FileInputStream(file), null);
          Document doc = createDocument(text);
          System.out.println("\n*********** FILE=" + file);
         
          for (int q=0; q < queries.length; q++) {
            try {
              Query query = parseQuery(queries[q]);
View Full Code Here

    lines.toArray(result);
    return result;
  }
 
  private Document createDocument(String content) {
    Document doc = new Document();
    doc.add(new Field(FIELD_NAME, content, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS));
    return doc;
  }
View Full Code Here

  public static void addDocument(IndexWriter oIWrt,ContactRecord contact)
    throws ClassNotFoundException, IOException, IllegalArgumentException,
             NoSuchFieldException, IllegalAccessException, InstantiationException,
             NullPointerException {

    Document oDoc = new Document();
    oDoc.add (new Field("workarea" , contact.getWorkarea(), Field.Store.YES, Field.Index.UN_TOKENIZED));
    oDoc.add (new Field("guid"     , contact.getGui() , Field.Store.YES, Field.Index.UN_TOKENIZED));
    oDoc.add (new Field("author"   , contact.getAuthor() , Field.Store.YES, Field.Index.UN_TOKENIZED));
    oDoc.add (new Field("value"    , contact.getValue(), Field.Store.YES, Field.Index.TOKENIZED));
    oIWrt.addDocument(oDoc);
  } // addBug
View Full Code Here

      // ***************************************************************

      if (sTitle==null) sTitle = "untitled";
    }

    Document oDoc = new Document();

    oDoc.add (new Field("subpath", sRelativePath, Field.Store.YES, Field.Index.UN_TOKENIZED));
    oDoc.add (new Field("name", sName, Field.Store.YES, Field.Index.UN_TOKENIZED));
    oDoc.add (new Field("title", sTitle, Field.Store.YES, Field.Index.TOKENIZED));
    oDoc.add (new Field("text" , Util.substitute(oMatcher, oTagPattern, new StringSubstitution(""), sHTMLText, Util.SUBSTITUTE_ALL), Field.Store.NO, Field.Index.TOKENIZED));

    return oDoc;
  } // makeHTMLDocument
View Full Code Here

    int iBuffer;
    char[] aBuffer;
    String sBuffer;
    String sText;
    Document oDoc;

    sBasePath += sSeparator;

    for (int f=0; f<iFiles; f++) {
View Full Code Here

        ScoreDoc[] oTopDoc = oTopSet.scoreDocs;
        int iDocCount = oTopDoc.length;
        if (DebugFile.trace) DebugFile.writeln("doc count is "+String.valueOf(iDocCount));
        aRetArr = new MailRecord[iDocCount];
        for (int d=0; d<iDocCount; d++) {
          Document oDoc = oSearch.doc(oTopDoc[d].doc);
          String[] aAbstract = Gadgets.split(oSearch.doc(oTopDoc[d].doc).get("abstract"), '¨');
          aRetArr[d] = new MailRecord(aAbstract[0], aAbstract[1], aAbstract[2],
                                      aAbstract[3], aAbstract[4], aAbstract[5],
                                      oDoc.get("container"));
        } // next
      } else {
        aRetArr = null;
      }
    } else {
      if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQry.toString()+")");
      Hits oHitSet = oSearch.search(oQry);
      int iHitCount = oHitSet.length();
      if (DebugFile.trace) DebugFile.writeln("hit count is "+String.valueOf(iHitCount));
      if (iHitCount>0) {
        aRetArr = new MailRecord[iHitCount];
        for (int h=0; h<iHitCount; h++) {
          Document oDoc = oHitSet.doc(h);
          if (DebugFile.trace) DebugFile.writeln("found "+oDoc.get("guid")+" "+oDoc.get("title")+" created by "+" "+oDoc.get("author")+" at date "+oDoc.get("created"));
          String[] aAbstract = Gadgets.split(oDoc.get("abstract"), '¨');
          aRetArr[h] = new MailRecord(aAbstract[0], aAbstract[1], aAbstract[2],
                                      aAbstract[3], aAbstract[4], aAbstract[5],
                                      oDoc.get("container"));
        } // next
      } else {
        aRetArr = null;
      }
    } // fi (iLimit>0)
View Full Code Here

TOP

Related Classes of org.apache.lucene.document.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.