Package com.google.appengine.api.search.Document

Examples of com.google.appengine.api.search.Document.Builder


    public void testDocFields() throws Exception {
        String indexName = "test-doc-fields";
        Index index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName));
        delDocs(index);

        Builder docBuilder = Document.newBuilder();
        Field field = Field.newBuilder().setName("textfield").setText("text field").build();
        docBuilder.addField(field);
        field = Field.newBuilder().setName("numberfield").setNumber(123).build();
        docBuilder.addField(field);
        Date now = new Date();
        field = Field.newBuilder().setName("datefield").setDate(now).build();
        docBuilder.addField(field);
        field = Field.newBuilder().setName("htmlfield").setHTML("<html>html field</html>").build();
        docBuilder.addField(field);
        User currentUser = new User("prometheus-qa@appenginetest.com", "appenginetest.com");
        field = Field.newBuilder().setName("atomfield").setAtom(currentUser.getAuthDomain()).build();
        docBuilder.addField(field);
        GeoPoint geoPoint = new GeoPoint((double) -10, 10.000001);
        field = Field.newBuilder().setName("geofield").setGeoPoint(geoPoint).build();
        docBuilder.addField(field);
        index.put(docBuilder);
        sync();

        Results<ScoredDocument> result = searchDocs(index, "", 0);
        assertEquals(1, result.getNumberReturned());
View Full Code Here


        if (searchDocs(index, "", 0).getNumberFound() == 0) {
            List<Document> documents = new ArrayList<>();
            Calendar cal = Calendar.getInstance();
            DateFormat dfDate = new SimpleDateFormat("yyyy,M,d");
            for (int i = 0; i < docCount; i++) {
                Builder docBuilder = Document.newBuilder();
                // two text field with different locale
                docBuilder.addField(Field.newBuilder().setName("textfield").setText("text with num " + i));
                Field field = Field.newBuilder().setName("textfield").setText("C'est la vie " + i).setLocale(Locale.FRENCH).build();
                docBuilder.addField(field);
                docBuilder.addField(Field.newBuilder().setName("numfield").setNumber(i));
                String dateVal = "" + cal.get(Calendar.YEAR) + ",";
                dateVal += cal.get(Calendar.MONTH) + ",";
                int day = cal.get(Calendar.DATE) + i;
                dateVal += day;
                docBuilder.addField(Field.newBuilder().setName("datefield").setDate(dfDate.parse(dateVal)));
                docBuilder.addField(Field.newBuilder().setName("htmlfield").setHTML("<B>html</B> " + i));
                docBuilder.addField(Field.newBuilder().setName("atomfield").setAtom("atom" + i + ".com"));
                GeoPoint geoPoint = new GeoPoint((double) i, (double) (100 + i));
                docBuilder.addField(Field.newBuilder().setName("geofield").setGeoPoint(geoPoint));
                // two field in same name and with different field type
                docBuilder.addField(Field.newBuilder().setName("mixfield").setText("text and number mix field"));
                docBuilder.addField(Field.newBuilder().setName("mixfield").setNumber(987));
                docBuilder.setId("selfid" + i);
                // only doc(id="selfid0") has "cn" locale, others have "en" locale
                if (i == 0) {
                    docBuilder.setLocale(new Locale("cn"));
                } else {
                    docBuilder.setLocale(new Locale("en"));
                }
                documents.add(docBuilder.build());
            }
            index.put(documents);
            sync();
        }
    }
View Full Code Here

    @Test
    public void testCreateDocument() throws Exception {
        String indexName = "test-doc";
        Index index = searchService.getIndex(IndexSpec.newBuilder().setName(indexName));
        delDocs(index);
        Builder docBuilder = Document.newBuilder().setId("tck").setLocale(Locale.FRENCH).setRank(8);
        docBuilder.addField(Field.newBuilder().setName("field1").setText("text field"));
        docBuilder.addField(Field.newBuilder().setName("field1").setNumber(987));
        docBuilder.addField(Field.newBuilder().setName("field2").setNumber(123));
        docBuilder.addField(Field.newBuilder().setName("field3").setDate(new Date()));
        index.put(docBuilder.build());
        sync();

        Results<ScoredDocument> result = searchDocs(index, "", 0);
        assertEquals(1, result.getNumberReturned());
        ScoredDocument retDoc = result.iterator().next();
View Full Code Here

        assertEquals(FieldType.NUMBER, field.getType());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testMultipleNumField() {
        Builder docBuilder = Document.newBuilder();
        docBuilder.addField(Field.newBuilder().setName("numfield").setNumber(123));
        docBuilder.addField(Field.newBuilder().setName("numfield").setNumber(789));
    }
View Full Code Here

        docBuilder.addField(Field.newBuilder().setName("numfield").setNumber(789));
    }

    @Test(expected = IllegalArgumentException.class)
    public void testMultipleDateField() {
        Builder docBuilder = Document.newBuilder();
        docBuilder.addField(Field.newBuilder().setName("datefield").setDate(new Date()));
        docBuilder.addField(Field.newBuilder().setName("datefield").setDate(new Date()));
    }
View Full Code Here

        implements IndexSearch<T>
{
    @Override
    protected Builder documentBuilderFor(T entity)
    {
        Builder builder = super.documentBuilderFor(entity);
        if (entity.getDescription() != null)
        {
            builder = builder.addField(Field.newBuilder().setName("description").setText(entity.getDescription()));
        }
        return builder;
    }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.search.Document.Builder

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.