List of usage examples for org.apache.lucene.document StoredField StoredField
public StoredField(String name, double value)
From source file:io.datalayer.lucene.helper.AosUtil.java
License:Apache License
public void numberTimestamp() { Document doc = new Document(); doc.add(new StoredField("timestamp", new Date().getTime())); doc.add(new StoredField("day", (int) (new Date().getTime() / 24 / 3600))); Date date = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(date);/*from ww w . ja v a 2s. c o m*/ doc.add(new StoredField("dayOfMonth", cal.get(Calendar.DAY_OF_MONTH))); }
From source file:io.datalayer.lucene.helper.AosUtil.java
License:Apache License
public void dateField() { Document doc = new Document(); doc.add(new StoredField("indexDate", DateTools.dateToString(new Date(), DateTools.Resolution.DAY))); }
From source file:io.datalayer.lucene.helper.AosUtil.java
License:Apache License
public void numericField() throws Exception { Document doc = new Document(); StoredField price = new StoredField("price", 19.99); doc.add(price);/*from w w w . j a va 2 s. co m*/ StoredField timestamp = new StoredField("timestamp", new Date().getTime()); doc.add(timestamp); Date b = new Date(); String v = DateTools.dateToString(b, DateTools.Resolution.DAY); StoredField birthday = new StoredField("birthday", v); doc.add(birthday); }
From source file:io.datalayer.lucene.helper.AosUtil.java
License:Apache License
public void indexAuthors() throws Exception { String[] authors = new String[] { "lisa", "tom" }; Document doc = new Document(); for (String author : authors) { doc.add(new StoredField("author", author)); }/* w ww.j a v a 2s.co m*/ }
From source file:io.datalayer.lucene.index.LuceneIndexTest.java
License:Apache License
private static Document getDocument(String rootDir, File file) throws IOException, ParseException { Properties props = new Properties(); props.load(new FileInputStream(file)); Document doc = new Document(); // category comes from relative path below the base directory String category = file.getParent().substring(rootDir.length()); category = category.replace(File.separatorChar, '/'); String isbn = props.getProperty("isbn"); String title = props.getProperty("title"); String author = props.getProperty("author"); String url = props.getProperty("url"); String subject = props.getProperty("subject"); String pubmonth = props.getProperty("pubmonth"); LOGGER.info(title + "\n" + author + "\n" + subject + "\n" + pubmonth + "\n" + category + "\n---------"); doc.add(new StoredField("isbn", isbn)); doc.add(new StoredField("category", category)); doc.add(new Field("title", title, AosFieldType.INDEXED_STORED_TERMVECTORS)); doc.add(new Field("title2", title.toLowerCase(), AosFieldType.INDEXED_STORED_TERMVECTORS)); // split multiple authors into unique field instances String[] authors = author.split(","); for (String a : authors) { doc.add(new Field("author", a, AosFieldType.INDEXED_STORED_TERMVECTORS)); }//from www . j av a2s . c o m doc.add(new StoredField("url", url)); doc.add(new Field("subject", subject, AosFieldType.INDEXED_STOREDNOT_TERMVECTORS)); doc.add(new StoredField("pubmonth", Integer.parseInt(pubmonth))); Date d = DateTools.stringToDate(pubmonth); doc.add(new StoredField("pubmonthAsDay", (int) (d.getTime() / (1000 * 3600 * 24)))); for (String text : new String[] { title, subject, author, category }) { doc.add(new Field("contents", text, AosFieldType.INDEXED_STOREDNOT_TERMVECTORS)); } return doc; }
From source file:io.datalayer.lucene.index.LuceneLifecycleTest.java
License:Apache License
/** * #A 2 docs in the index/* w ww . j a v a 2 s. c o m*/ * * #B Delete first document * * #C 1 indexed document, 0 deleted documents */ @Test public void testUpdate() throws IOException { assertEquals(1, getHitCount("city", "Amsterdam")); IndexWriter writer = getWriter(); Document doc = new Document(); doc.add(new StoredField("id", "1")); doc.add(new StoredField("country", "Netherlands")); doc.add(new Field("contents", "Den Haag has a lot of museums", AosFieldType.INDEXED_STOREDNOT_TERMVECTORS)); doc.add(new Field("city", "Den Haag", AosFieldType.INDEXED_STOREDNOT_TERMVECTORS)); writer.updateDocument(new Term("id", "1"), doc); writer.close(); assertEquals(0, getHitCount("city", "Amsterdam")); assertEquals(1, getHitCount("city", "Haag")); }
From source file:io.datalayer.lucene.index.SimpleIndexer.java
License:Apache License
protected Document getDocument(File f) throws Exception { Document doc = new Document(); doc.add(new Field("contents", new FileReader(f), AosFieldType.INDEXED_STORED_TERMVECTORS)); doc.add(new StoredField("filename", f.getName())); doc.add(new StoredField("fullpath", f.getCanonicalPath())); return doc;/*from w w w. jav a 2 s. c o m*/ }
From source file:io.datalayer.lucene.index.VerboseIndexing.java
License:Apache License
private void index() throws IOException { Directory dir = new RAMDirectory(); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_46, AosAnalyser.NO_LIMIT_TOKEN_COUNT_SIMPLE_ANALYSER); config.setInfoStream(System.out); IndexWriter writer = new IndexWriter(dir, config); for (int i = 0; i < 100; i++) { Document doc = new Document(); doc.add(new StoredField("keyword", "goober")); writer.addDocument(doc);// w ww .j a v a 2s .c o m } writer.close(); }
From source file:io.datalayer.lucene.tika.DigesterXmlDocument.java
License:Apache License
public void populateDocument(Contact contact) { doc = new Document(); doc.add(new StoredField("type", contact.getType())); doc.add(new StoredField("name", contact.getName())); doc.add(new StoredField("address", contact.getAddress())); doc.add(new StoredField("city", contact.getCity())); doc.add(new StoredField("province", contact.getProvince())); doc.add(new StoredField("postalcode", contact.getPostalcode())); doc.add(new StoredField("country", contact.getCountry())); doc.add(new StoredField("telephone", contact.getTelephone())); }
From source file:io.datalayer.lucene.tika.SaxXmlDocument.java
License:Apache License
@Override public void endElement(String uri, String localName, String qName) // throws SAXException { if (qName.equals("address-book")) { return;/* w w w. j a v a2s . c o m*/ } else if (qName.equals("contact")) { for (Entry<String, String> attribute : attributeMap.entrySet()) { String attName = attribute.getKey(); String attValue = attribute.getValue(); doc.add(new StoredField(attName, attValue)); } } else { doc.add(new StoredField(qName, elementBuffer.toString())); } }