org.apache.lucene.document.NumericField Java Examples

The following examples show how to use org.apache.lucene.document.NumericField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchService.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Document createDocument(MediaFile mediaFile) {
    Document doc = new Document();
    doc.add(new NumericField(FIELD_ID, Field.Store.YES, false).setIntValue(mediaFile.getId()));
    doc.add(new Field(FIELD_MEDIA_TYPE, mediaFile.getMediaType().name(), Field.Store.NO, Field.Index.ANALYZED_NO_NORMS));

    if (mediaFile.getTitle() != null) {
        doc.add(new Field(FIELD_TITLE, mediaFile.getTitle(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (mediaFile.getArtist() != null) {
        doc.add(new Field(FIELD_ARTIST, mediaFile.getArtist(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (mediaFile.getGenre() != null) {
        doc.add(new Field(FIELD_GENRE, normalizeGenre(mediaFile.getGenre()), Field.Store.NO, Field.Index.ANALYZED));
    }
    if (mediaFile.getYear() != null) {
        doc.add(new NumericField(FIELD_YEAR, Field.Store.NO, true).setIntValue(mediaFile.getYear()));
    }
    if (mediaFile.getFolder() != null) {
        doc.add(new Field(FIELD_FOLDER, mediaFile.getFolder(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
    }

    return doc;
}
 
Example #2
Source File: SearchService.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Document createDocument(MediaFile mediaFile) {
    Document doc = new Document();
    doc.add(new NumericField(FIELD_ID, Field.Store.YES, false).setIntValue(mediaFile.getId()));

    if (mediaFile.getArtist() != null) {
        doc.add(new Field(FIELD_ARTIST, mediaFile.getArtist(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (mediaFile.getAlbumName() != null) {
        doc.add(new Field(FIELD_ALBUM, mediaFile.getAlbumName(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (mediaFile.getFolder() != null) {
        doc.add(new Field(FIELD_FOLDER, mediaFile.getFolder(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
    }

    return doc;
}
 
Example #3
Source File: SearchService.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Document createDocument(Album album) {
    Document doc = new Document();
    doc.add(new NumericField(FIELD_ID, Field.Store.YES, false).setIntValue(album.getId()));

    if (album.getArtist() != null) {
        doc.add(new Field(FIELD_ARTIST, album.getArtist(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (album.getName() != null) {
        doc.add(new Field(FIELD_ALBUM, album.getName(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (album.getFolderId() != null) {
        doc.add(new NumericField(FIELD_FOLDER_ID, Field.Store.NO, true).setIntValue(album.getFolderId()));
    }

    return doc;
}
 
Example #4
Source File: LogSearch.java    From exhibitor with Apache License 2.0 6 votes vote down vote up
public SearchItem toResult(int documentId) throws IOException
{
    Document        document = searcher.doc(documentId);

    String          type = document.getFieldable(FieldNames.TYPE).stringValue();
    NumericField    date = (NumericField)document.getFieldable(FieldNames.DATE);
    Fieldable       path = document.getFieldable(FieldNames.PATH);
    NumericField    version = (NumericField)document.getFieldable(FieldNames.VERSION);
    return new SearchItem
    (
        Integer.parseInt(type),
        path.stringValue(),
        (version != null) ? version.getNumericValue().intValue() : -1,
        new Date(date.getNumericValue().longValue())
    );
}
 
Example #5
Source File: IndexBuilder.java    From exhibitor with Apache License 2.0 6 votes vote down vote up
private Document makeDocument(TxnHeader header, EntryTypes type, AtomicInteger count, AtomicLong from, AtomicLong to)
{
    count.incrementAndGet();
    if ( header.getTime() < from.get() )
    {
        from.set(header.getTime());
    }
    if ( header.getTime() > to.get() )
    {
        to.set(header.getTime());
    }

    NumericField dateField = new NumericField(FieldNames.DATE, Field.Store.YES, true);
    dateField.setLongValue(header.getTime());

    Document    document = new Document();
    document.add(new Field(FieldNames.TYPE, Integer.toString(type.getId()), Field.Store.YES, Field.Index.NOT_ANALYZED));
    document.add(dateField);
    return document;
}
 
Example #6
Source File: SearchService.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Document createDocument(MediaFile mediaFile) {
    Document doc = new Document();
    doc.add(new NumericField(FIELD_ID, Field.Store.YES, false).setIntValue(mediaFile.getId()));

    if (mediaFile.getArtist() != null) {
        doc.add(new Field(FIELD_ARTIST, mediaFile.getArtist(), Field.Store.YES, Field.Index.ANALYZED));
    }
    if (mediaFile.getFolder() != null) {
        doc.add(new Field(FIELD_FOLDER, mediaFile.getFolder(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS));
    }

    return doc;
}
 
Example #7
Source File: SearchService.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Document createDocument(Artist artist, MusicFolder musicFolder) {
    Document doc = new Document();
    doc.add(new NumericField(FIELD_ID, Field.Store.YES, false).setIntValue(artist.getId()));
    doc.add(new Field(FIELD_ARTIST, artist.getName(), Field.Store.YES, Field.Index.ANALYZED));
    doc.add(new NumericField(FIELD_FOLDER_ID, Field.Store.NO, true).setIntValue(musicFolder.getId()));

    return doc;
}
 
Example #8
Source File: AutoCompleter.java    From webdsl with Apache License 2.0 5 votes vote down vote up
private static Document createDocument(String text, int freq) {
  Document doc = new Document();
  // the word field is never queried on... its indexed so it can be quickly
  // checked for rebuild (and stored for retrieval). Doesn't need norms or TF/pos
  Field f = new Field(F_WORD, text, Field.Store.YES, Field.Index.NOT_ANALYZED);
  f.setOmitTermFreqAndPositions(true);
  f.setOmitNorms(true);
  doc.add(f); // orig term
  NumericField nf = new NumericField(F_FREQ).setIntValue(freq);
  doc.add(nf);
  addGram(text, doc);
  return doc;
}
 
Example #9
Source File: LuceneMessageSearchIndex.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * Index the {@link Flags} and add it to the {@link Document}
 */
private Document createFlagsDocument(MailboxMessage message) {
    Document doc = new Document();
    doc.add(new Field(ID_FIELD, "flags-" + message.getMailboxId().serialize() + "-" + Long.toString(message.getUid().asLong()), Store.YES, Index.NOT_ANALYZED));
    doc.add(new Field(MAILBOX_ID_FIELD, message.getMailboxId().serialize(), Store.YES, Index.NOT_ANALYZED));
    doc.add(new NumericField(UID_FIELD,Store.YES, true).setLongValue(message.getUid().asLong()));
    
    indexFlags(doc, message.createFlags());
    return doc;
}