Example usage for org.apache.lucene.document IntPoint IntPoint

List of usage examples for org.apache.lucene.document IntPoint IntPoint

Introduction

In this page you can find the example usage for org.apache.lucene.document IntPoint IntPoint.

Prototype

public IntPoint(String name, int... point) 

Source Link

Document

Creates a new IntPoint, indexing the provided N-dimensional int point.

Usage

From source file:IndexAndSearchOpenStreetMaps1D.java

License:Apache License

private static void createIndex() throws IOException {

    long t0 = System.nanoTime();

    CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);

    int BUFFER_SIZE = 1 << 16; // 64K
    InputStream is = Files
            .newInputStream(Paths.get("/lucenedata/open-street-maps/latlon.subsetPlusAllLondon.txt"));
    BufferedReader reader = new BufferedReader(new InputStreamReader(is, decoder), BUFFER_SIZE);

    Directory dir = FSDirectory.open(Paths.get("/c/tmp/bkdtest1d" + (USE_NF ? "_nf" : "")));

    IndexWriterConfig iwc = new IndexWriterConfig(null);
    iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
    //iwc.setMaxBufferedDocs(109630);
    //iwc.setRAMBufferSizeMB(IndexWriterConfig.DISABLE_AUTO_FLUSH);
    iwc.setRAMBufferSizeMB(256.0);/*www .j  av a  2s .c o  m*/
    iwc.setMergePolicy(new LogDocMergePolicy());
    iwc.setMergeScheduler(new SerialMergeScheduler());
    iwc.setInfoStream(new PrintStreamInfoStream(System.out));
    IndexWriter w = new IndexWriter(dir, iwc);

    int count = 0;
    byte[] scratch = new byte[4];
    while (true) {
        String line = reader.readLine();
        if (line == null) {
            break;
        }

        String[] parts = line.split(",");
        //long id = Long.parseLong(parts[0]);
        int lat = (int) (1000000. * Double.parseDouble(parts[1]));
        //int lon = (int) (1000000. * Double.parseDouble(parts[2]));
        Document doc = new Document();
        if (USE_NF) {
            doc.add(new LegacyIntField("latnum", lat, Field.Store.NO));
            //doc.add(new LongField("lonnum", lon, Field.Store.NO));
        } else {
            doc.add(new IntPoint("lat", lat));
            //doc.add(new SortedNumericDocValuesField("lon", lon));
        }
        w.addDocument(doc);
        count++;
        if (count % 1000000 == 0) {
            System.out.println(count + "...");
        }
    }
    //w.forceMerge(1);
    w.commit();
    System.out.println(w.maxDoc() + " total docs");

    w.close();
    long t1 = System.nanoTime();
    System.out.println(((t1 - t0) / 1000000000.0) + " sec to build index");
}

From source file:IndexTaxis.java

License:Apache License

static void addOneField(Document doc, String fieldName, String rawValue) {
    // nocommit/* w  ww . ja va2  s .  com*/
    /*
    if (fieldName.equals("pick_up_lat")) {
      double value = Double.parseDouble(rawValue);
      doc.add(new DoublePoint(fieldName, value));
      doc.add(new SortedNumericDocValuesField(fieldName, NumericUtils.doubleToSortableLong(value)));
    }
    */
    switch (fieldName) {
    case "vendor_id":
    case "cab_color":
    case "payment_type":
    case "trip_type":
    case "rate_code":
    case "store_and_fwd_flag":
        doc.add(new StringField(fieldName, rawValue, Field.Store.NO));
        doc.add(new SortedSetDocValuesField(fieldName, new BytesRef(rawValue)));
        break;
    case "vendor_name":
        doc.add(new TextField(fieldName, rawValue, Field.Store.NO));
        break;
    case "pick_up_date_time":
    case "drop_off_date_time": {
        long value = Long.parseLong(rawValue);
        doc.add(new LongPoint(fieldName, value));
        doc.add(new SortedNumericDocValuesField(fieldName, value));
    }
        break;
    case "passenger_count": {
        int value = Integer.parseInt(rawValue);
        doc.add(new IntPoint(fieldName, value));
        doc.add(new SortedNumericDocValuesField(fieldName, value));
    }
        break;
    case "trip_distance":
    case "pick_up_lat":
    case "pick_up_lon":
    case "drop_off_lat":
    case "drop_off_lon":
    case "fare_amount":
    case "surcharge":
    case "mta_tax":
    case "extra":
    case "ehail_fee":
    case "improvement_surcharge":
    case "tip_amount":
    case "tolls_amount":
    case "total_amount": {
        double value;
        try {
            value = Double.parseDouble(rawValue);
        } catch (NumberFormatException nfe) {
            System.out.println(
                    "WARNING: failed to parse \"" + rawValue + "\" as double for field \"" + fieldName + "\"");
            return;
        }
        doc.add(new DoublePoint(fieldName, value));
        doc.add(new SortedNumericDocValuesField(fieldName, NumericUtils.doubleToSortableLong(value)));
    }
        break;
    default:
        throw new AssertionError("failed to handle field \"" + fieldName + "\"");
    }
}

From source file:com.b2international.index.lucene.IntIndexField.java

License:Apache License

@Override
protected IndexableField toField(Integer value) {
    return new IntPoint(fieldName(), value);
}

From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java

public static void addTenantDoc(Tenant data) {
    try {//from  www . j a  v a2  s  .  co  m
        Document doc = new Document();
        doc.add(new StoredField("id", data.getId()));
        doc.add(new TextField("firstName", data.getFirst(), null));
        doc.add(new TextField("secondName", data.getSecond(), null));
        doc.add(new TextField("surname", data.getSurname(), null));
        doc.add(new IntPoint("tell", data.getTell()));
        doc.add(new IntPoint("nationalID", data.getNational_ID()));
        doc.add(new TextField("bio", data.getBio(), null));

        new Build().create().indexDoc(doc);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java

public static void updateTenantDoc(Tenant data) {
    try {//from  ww  w . ja  v a 2  s . c  o m
        Document doc = new Document();
        doc.add(new StoredField("id", data.getId()));
        doc.add(new TextField("firstName", data.getFirst(), null));
        doc.add(new TextField("secondName", data.getSecond(), null));
        doc.add(new TextField("surname", data.getSurname(), null));
        doc.add(new IntPoint("tell", data.getTell()));
        doc.add(new IntPoint("nationalID", data.getNational_ID()));
        doc.add(new TextField("bio", data.getBio(), null));
        new Build().create().updateDoc(doc, "id", String.valueOf(data.getId()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java

public static void addBuildingDoc(Building data) {
    try {//from   w  w w  .  jav a2s .c  o m
        Document doc = new Document();
        doc.add(new StoredField("id", data.getId()));
        doc.add(new IntPoint("Registration ID", data.getRegistration_id()));
        doc.add(new TextField("Name", data.getName(), null));
        doc.add(new TextField("OwnerName", data.getOwner_Name(), null));
        doc.add(new StringField("License", data.getLicense(), null));
        doc.add(new TextField("Location", data.getLocation(), null));
        doc.add(new IntPoint("No of rooms", data.getNo_of_rooms()));

        new Build().create().indexDoc(doc);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java

public static void updateBuildingDoc(Building data) {
    try {/*  ww  w  .ja  v a 2 s . com*/
        Document doc = new Document();
        doc.add(new StoredField("id", data.getId()));
        doc.add(new IntPoint("Registration ID", data.getRegistration_id()));
        doc.add(new TextField("Name", data.getName(), null));
        doc.add(new TextField("OwnerName", data.getOwner_Name(), null));
        doc.add(new StringField("License", data.getLicense(), null));
        doc.add(new TextField("Location", data.getLocation(), null));
        doc.add(new IntPoint("No of rooms", data.getNo_of_rooms()));

        new Build().create().updateDoc(doc, "id", String.valueOf(data.getId()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java

public static void addOwnerDoc(Owner data) {
    try {/*w w w.  j a  v  a 2 s  .  c om*/
        Document doc = new Document();
        doc.add(new StoredField("id", data.getId()));
        doc.add(new TextField("firstName", data.getFirst(), null));
        doc.add(new TextField("secondName", data.getSecond(), null));
        doc.add(new TextField("surname", data.getSurname(), null));
        doc.add(new IntPoint("tell", data.getTell()));
        doc.add(new IntPoint("nationalID", data.getNational_id()));
        doc.add(new TextField("bio", data.getBio(), null));
        doc.add(new IntPoint("Owner Id", data.getOwner_id()));

        new Build().create().indexDoc(doc);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flycode.CRIBSearch.SearchEngine.IndexDB.java

public static void updateOwnerDoc(Owner data) {
    try {/*from   w w w. ja va 2 s.com*/
        Document doc = new Document();
        doc.add(new StoredField("id", data.getId()));
        doc.add(new TextField("firstName", data.getFirst(), null));
        doc.add(new TextField("secondName", data.getSecond(), null));
        doc.add(new TextField("surname", data.getSurname(), null));
        doc.add(new IntPoint("tell", data.getTell()));
        doc.add(new IntPoint("nationalID", data.getNational_id()));
        doc.add(new TextField("bio", data.getBio(), null));
        doc.add(new IntPoint("Owner Id", data.getOwner_id()));

        new Build().create().updateDoc(doc, "id", String.valueOf(data.getId()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.flycode.CRIBSearch.SearchEngine.SearchDocument.java

public void addBuildingDocs() {
    try {/*from www  . j  a va 2s  .  c  om*/
        ResultSet rs = p.selectTable("building");
        while (rs.next()) {
            Document doc = new Document();
            doc.add(new StoredField("id", rs.getString(1)));
            doc.add(new TextField("name", rs.getString(2), null));
            doc.add(new TextField("ownerName", rs.getString(3), null));
            doc.add(new StringField("license", rs.getString(4), null));
            doc.add(new TextField("location", rs.getString(5), null));
            doc.add(new IntPoint("NoOfRooms", Integer.parseInt(rs.getString(6))));
            w.addDocument(doc);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}