List of usage examples for org.apache.lucene.index IndexWriter addDocument
public long addDocument(Iterable<? extends IndexableField> doc) throws IOException
From source file:com.bitranger.parknshop.common.fulltext.BuildIndexForCustomer.java
License:Open Source License
@SuppressWarnings("deprecation") public void createIndex() throws IOException { // store in the directory Directory directory = new SimpleFSDirectory(indexFile); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_45, analyzer); indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig);// FetchOption option = new FetchOption(); customerlist = customerDao.findAll(option); if (customerlist.size() > 0) { long time1 = System.currentTimeMillis(); for (int i = 0; i < customerlist.size(); i++) { Document document = new Document(); document.add(new Field("nickname", customerlist.get(i).getNickname(), Field.Store.YES, Field.Index.ANALYZED)); document.add(//from ww w . j a va2 s . c om new Field("email", customerlist.get(i).getEmail(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("password", customerlist.get(i).getPassword(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("gender", String.valueOf(customerlist.get(i).getGender()), Field.Store.YES, Field.Index.ANALYZED)); document.add( new Field("name", customerlist.get(i).getName(), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(document); } long time2 = System.currentTimeMillis(); System.out.println("" + writer.numDocs() + ""); System.out.println("" + (time2 - time1) + ""); } writer.close(); }
From source file:com.bitranger.parknshop.common.fulltext.BuildIndexForItem.java
License:Open Source License
@SuppressWarnings("deprecation") public void createIndex() throws IOException { // store in the directory Directory directory = new SimpleFSDirectory(indexFile); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_45, analyzer); indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig);// itemlist = itemDao.findAll();//www . j av a 2 s . c o m if (itemlist.size() > 0) { long time1 = System.currentTimeMillis(); for (int i = 0; i < itemlist.size(); i++) { Document document = new Document(); document.add(new Field("name", itemlist.get(i).getName(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("introduction", itemlist.get(i).getIntroduction(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("price", String.valueOf(itemlist.get(i).getPrice()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("urlPicture", itemlist.get(i).getUrlPicture(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("extra1", String.valueOf(itemlist.get(i).getExtra1()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("extra2", String.valueOf(itemlist.get(i).getExtra2()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("countPurchase", String.valueOf(itemlist.get(i).getCountPurchase()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("countFavourite", String.valueOf(itemlist.get(i).getCountFavourite()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("countClick", String.valueOf(itemlist.get(i).getCountClick()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("vote", String.valueOf(itemlist.get(i).getVote()), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(document); } long time2 = System.currentTimeMillis(); System.out.println("" + writer.numDocs() + ""); System.out.println("" + (time2 - time1) + ""); } writer.close(); }
From source file:com.bitranger.parknshop.common.fulltext.BuildIndexForOrder.java
License:Open Source License
@SuppressWarnings("deprecation") public void createIndex() throws IOException { // store in the directory Directory directory = new SimpleFSDirectory(indexFile); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_45, analyzer); indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig);// Date from = new Date(), to = new Date(); orderlist = orderDao.findAll(from, to); if (orderlist.size() > 0) { long time1 = System.currentTimeMillis(); for (int i = 0; i < orderlist.size(); i++) { Document document = new Document(); document.add(new Field("id", String.valueOf(orderlist.get(i).getId()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("psCustomer", String.valueOf(orderlist.get(i).getPsCustomer()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("idShop", String.valueOf(orderlist.get(i).getId()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("status", String.valueOf(orderlist.get(i).getStatus()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("trackingNumber", orderlist.get(i).getTrackingNumber(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("address", orderlist.get(i).getPsRecipient().getAddresss(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("postalCode", orderlist.get(i).getTrackingNumber(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("nameRecipient", orderlist.get(i).getPsRecipient().getPsCustomer().getName(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("phoneRecipient", orderlist.get(i).getPsRecipient().getPhoneNumber(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("priceTotal", String.valueOf(orderlist.get(i).getPriceTotal()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("timeCreated", String.valueOf(orderlist.get(i).getTimeCreated()), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(document); }//from w w w .j a va 2 s .co m long time2 = System.currentTimeMillis(); System.out.println("" + writer.numDocs() + ""); System.out.println("" + (time2 - time1) + ""); } writer.close(); }
From source file:com.bitranger.parknshop.common.fulltext.BuildIndexForSeller.java
License:Open Source License
@SuppressWarnings("deprecation") public void createIndex() throws IOException { // store in the directory Directory directory = new SimpleFSDirectory(indexFile); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_45, analyzer); indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig);// FetchOption option = new FetchOption(); sellerlist = sellerDao.findAll(new FetchOption().limit(100)); if (sellerlist.size() > 0) { long time1 = System.currentTimeMillis(); for (int i = 0; i < sellerlist.size(); i++) { Document document = new Document(); document.add(new Field("id", String.valueOf(sellerlist.get(i).getId()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("nickname", sellerlist.get(i).getNickname(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("personIdNum", String.valueOf(sellerlist.get(i).getPersonIdNum()), Field.Store.YES, Field.Index.ANALYZED)); document.add(//from www. java 2s . c om new Field("email", sellerlist.get(i).getEmail(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("password", sellerlist.get(i).getPassword(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("status", String.valueOf(sellerlist.get(i).getStatus()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("timeCreated", String.valueOf(sellerlist.get(i).getTimeCreated()), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(document); } long time2 = System.currentTimeMillis(); System.out.println("" + writer.numDocs() + ""); System.out.println("" + (time2 - time1) + ""); } writer.close(); }
From source file:com.bitranger.parknshop.common.fulltext.BuildIndexForShop.java
License:Open Source License
@SuppressWarnings("deprecation") public void createIndex() throws IOException { // store in the directory Directory directory = new SimpleFSDirectory(indexFile); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_45, analyzer); indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE); IndexWriter writer = new IndexWriter(directory, indexWriterConfig);// shoplist = shopDao.findAll();// w w w .j a va 2s . c o m if (shoplist.size() > 0) { long time1 = System.currentTimeMillis(); for (int i = 0; i < shoplist.size(); i++) { Document document = new Document(); document.add(new Field("id", String.valueOf(shoplist.get(i).getName()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("psSeller", String.valueOf(shoplist.get(i).getPsSeller()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("name", shoplist.get(i).getName(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("status", String.valueOf(shoplist.get(i).getStatus()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("introduction", shoplist.get(i).getIntroduction(), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("timeCreated", String.valueOf(shoplist.get(i).getTimeCreated()), Field.Store.YES, Field.Index.ANALYZED)); document.add(new Field("vote", String.valueOf(shoplist.get(i).getVote()), Field.Store.YES, Field.Index.ANALYZED)); writer.addDocument(document); } long time2 = System.currentTimeMillis(); System.out.println("" + writer.numDocs() + ""); System.out.println("" + (time2 - time1) + ""); } writer.close(); }
From source file:com.bizosys.hsearch.dictionary.DictionaryValues.java
License:Apache License
public int load(Set<String> wordDescription, Writer outputWriter, Analyzer analyzer) throws Exception { if (null != reader) { try {/*from w w w . jav a2 s.com*/ reader.close(); if (null != searcher) searcher.close(); } catch (Exception ex) { } } this.idx = new RAMDirectory(); IndexWriterConfig indexWriterConfig = new IndexWriterConfig(Version.LUCENE_35, analyzer); IndexWriter writer = new IndexWriter(this.idx, indexWriterConfig); int linesAdded = 0; for (String line : wordDescription) { writer.addDocument(createDocument(line)); linesAdded++; } if (null != outputWriter) outputWriter.append("----------\n</BR>Total Lines Loaded : ") .append(new Integer(linesAdded).toString()); writer.close(); reader = IndexReader.open(this.idx); searcher = new IndexSearcher(reader); return linesAdded; }
From source file:com.bizosys.hsearch.dictionary.DictionaryValues.java
License:Apache License
private int loadReaderAndIndex(IndexWriter writer, Writer outputWriter, BufferedReader reader) throws IOException, CorruptIndexException { String line = null;/*from w ww . j av a 2s. c o m*/ int linesAddded = 0; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; writer.addDocument(createDocument(line)); } if (null != outputWriter) outputWriter.append("----------\n</BR>Total Keywords Loaded : ") .append(new Integer(linesAddded).toString()); return linesAddded; }
From source file:com.bluecubs.xinco.index.XincoIndexer.java
License:Apache License
public static synchronized boolean indexXincoCoreData(XincoCoreData d, boolean index_content, XincoDBManager dbm) {//from ww w . jav a2 s. c om IndexWriter writer = null; try { //check if document exists in index and delete XincoIndexer.removeXincoCoreData(d, dbm); //add document to index try { writer = new IndexWriter(dbm.config.FileIndexPath, new StandardAnalyzer(), false); } catch (Exception ie) { writer = new IndexWriter(dbm.config.FileIndexPath, new StandardAnalyzer(), true); } writer.addDocument(XincoDocument.getXincoDocument(d, index_content, dbm)); //writer.optimize(); writer.close(); } catch (Exception e) { if (writer != null) { try { writer.close(); } catch (Exception we) { } } return false; } return true; }
From source file:com.browseengine.bobo.facets.attribute.AttributesFacetHandlerTest.java
License:Apache License
@Override protected void setUp() throws Exception { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); selectionProperties = new HashMap<String, String>(); IndexWriter writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop5=val1")); writer.addDocument(doc("prop1=val2", "prop3=val1", "prop7=val7")); writer.addDocument(doc("prop1=val2", "prop3=val2", "prop3=val3")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop4=val2", "prop4=val3")); writer.commit();// www . j a va2 s . c om attributesFacetHandler = new AttributesFacetHandler(AttributeHandlerName, AttributeHandlerName, null, null, new HashMap<String, String>()); facetHandlers.add(attributesFacetHandler); IndexReader reader = IndexReader.open(directory, true); boboReader = BoboIndexReader.getInstance(reader, facetHandlers); attributesFacetHandler.loadFacetData(boboReader); browser = new BoboBrowser(boboReader); }
From source file:com.browseengine.bobo.facets.attribute.AttributesFacetHandlerTest.java
License:Apache License
private void modifiedSetup() throws CorruptIndexException, LockObtainFailedException, IOException { directory = new RAMDirectory(); analyzer = new WhitespaceAnalyzer(); IndexWriter writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop5=val1")); writer.addDocument(doc("prop1=val2", "prop3=val1", "prop7=val7")); writer.addDocument(doc("prop1=val2", "prop3=val2", "prop3=val3")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1")); writer.addDocument(doc("prop1=val1", "prop2=val1", "prop4=val2", "prop4=val3")); writer.commit();/*from w w w. java 2 s . co m*/ HashMap<String, String> facetProps = new HashMap<String, String>(); facetProps.put(AttributesFacetHandler.MAX_FACETS_PER_KEY_PROP_NAME, "1"); attributesFacetHandler = new AttributesFacetHandler(AttributeHandlerName, AttributeHandlerName, null, null, facetProps); facetHandlers.add(attributesFacetHandler); IndexReader reader = IndexReader.open(directory, true); boboReader = BoboIndexReader.getInstance(reader, facetHandlers); attributesFacetHandler.loadFacetData(boboReader); browser = new BoboBrowser(boboReader); }