Package org.apache.lucene.document

Examples of org.apache.lucene.document.Field


   */
  protected Field createEnumField(int fieldConstant, Enum<?> value, Store store) {
    if (value == null)
      return null;

    return new Field(String.valueOf(fieldConstant), String.valueOf(value.ordinal()), store, Index.UN_TOKENIZED);
  }
View Full Code Here


  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

      return document;
  }


  private Field createField(String fieldName, String content, Field.Index fieldIndex, float wight) {
    Field field = new Field(fieldName,content, Field.Store.YES, fieldIndex);
    field.setBoost(wight);
    return field;
  }
View Full Code Here

                  Integer.MAX_VALUE))
              .setOpenMode(OpenMode.CREATE));
      queryParser = new QueryParser(Version.LUCENE_31, "text", analyzer);
      queryParser.setDefaultOperator(QueryParser.AND_OPERATOR);

      fulltext = new Field("text", "", Field.Store.NO,
          Field.Index.ANALYZED);
      fulltext.setOmitTermFreqAndPositions(true);

      // 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);
View Full Code Here

    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

 
  private MemoryIndex createMemoryIndex(Document doc) {
    MemoryIndex index = new MemoryIndex();
    Enumeration iter = doc.fields();
    while (iter.hasMoreElements()) {
      Field field = (Field) iter.nextElement();
      index.addField(field.name(), field.stringValue(), analyzer);
    }
    return index;
  }
View Full Code Here

    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

    Directory ramDir = new RAMDirectory();
    try {
      IndexWriter writer = new IndexWriter(ramDir, /*new StandardAnalyzer()/*/XFactory.getWriterAnalyzer());
      Document doc = new Document();
      Field fd = new Field(FIELD_NAME, CONTENT, Field.Store.YES, Field.Index.TOKENIZED,Field.TermVector.WITH_POSITIONS_OFFSETS);
      doc.add(fd);
      writer.addDocument(doc);
      writer.optimize();
      writer.close();
     
View Full Code Here

    //接下来是标准的Lucene建立索引和检索的代码
    Directory ramDir = new RAMDirectory();
    IndexWriter writer = new IndexWriter(ramDir, analyzer, MaxFieldLength.UNLIMITED);
    Document doc = new Document();
    Field fd = new Field(FIELD_NAME, content, Field.Store.YES,
        Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS);
    doc.add(fd);
    writer.addDocument(doc);
    writer.optimize();
    writer.close();
View Full Code Here

TOP

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

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.