Search in sources :

Example 6 with TrieDateField

use of org.apache.solr.schema.TrieDateField in project lucene-solr by apache.

the class AtomicUpdatesTest method testRemoveDateUsingDateType.

@Ignore("Remove Date is not supported in other formats than UTC")
@Test
public void testRemoveDateUsingDateType() throws Exception {
    SolrInputDocument doc;
    doc = new SolrInputDocument();
    doc.setField("id", "10001");
    TrieDateField trieDF = new TrieDateField();
    Date tempDate = DateMathParser.parseMath(null, "2014-02-01T12:00:00Z");
    doc.setField("dateRemove", new Date[] { DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"), DateMathParser.parseMath(null, "2014-07-02T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-04T12:00:00Z") });
    assertU(adoc(doc));
    doc = new SolrInputDocument();
    doc.setField("id", "10002");
    doc.setField("dateRemove", new Date[] { DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"), DateMathParser.parseMath(null, "2014-07-02T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-02T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-04T12:00:00Z") });
    assertU(adoc(doc));
    doc = new SolrInputDocument();
    doc.setField("id", "10020");
    doc.setField("dateRemove", new Date[] { DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-03T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-04T12:00:00Z") });
    assertU(adoc(doc));
    doc = new SolrInputDocument();
    doc.setField("id", "10021");
    doc.setField("dateRemove", new Date[] { DateMathParser.parseMath(null, "2014-02-01T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-02T12:00:00Z"), DateMathParser.parseMath(null, "2014-02-04T12:00:00Z") });
    assertU(adoc(doc));
    assertU(commit());
    assertQ(req("q", "dateRemove:*", "indent", "true"), "//result[@numFound = '4']");
    String dateString = DateMathParser.parseMath(null, "2014-02-02T12:00:00Z").toString();
    //    assertQ(req("q", "dateRemove:"+URLEncoder.encode(dateString, "UTF-8"), "indent", "true"), "//result[@numFound = '3']");
    //    assertQ(req("q", "dateRemove:\"2014-09-02T12:00:00Z\"", "indent", "true"), "//result[@numFound = '3']");
    //    assertQ(req("q", "dateRemove:"+dateString, "indent", "true"), "//result[@numFound = '3']"); //Sun Feb 02 10:00:00 FNT 2014
    //Sun Feb 02 10:00:00 FNT 2014
    assertQ(req("q", "dateRemove:\"Sun Feb 02 10:00:00 FNT 2014\"", "indent", "true"), "//result[@numFound = '3']");
    doc = new SolrInputDocument();
    doc.setField("id", "10001");
    List<Date> removeList = new ArrayList<Date>();
    removeList.add(DateMathParser.parseMath(null, "2014-09-02T12:00:00Z"));
    removeList.add(DateMathParser.parseMath(null, "2014-09-03T12:00:00Z"));
    //behavior when hitting Solr through ZK
    doc.setField("dateRemove", ImmutableMap.of("remove", removeList));
    assertU(adoc(doc));
    assertU(commit());
    assertQ(req("q", "dateRemove:*", "indent", "true"), "//result[@numFound = '4']");
    assertQ(req("q", "dateRemove:\"2014-09-02T12:00:00Z\"", "indent", "true"), "//result[@numFound = '2']");
    doc = new SolrInputDocument();
    doc.setField("id", "10021");
    removeList = new ArrayList<Date>();
    removeList.add(DateMathParser.parseMath(null, "2014-09-02T12:00:00Z"));
    removeList.add(DateMathParser.parseMath(null, "2014-09-03T12:00:00Z"));
    //behavior when hitting Solr through ZK
    doc.setField("dateRemove", ImmutableMap.of("remove", removeList));
    assertU(adoc(doc));
    assertU(commit());
    assertQ(req("q", "dateRemove:*", "indent", "true"), "//result[@numFound = '4']");
    assertQ(req("q", "dateRemove:\"2014-09-02T12:00:00Z\"", "indent", "true"), "//result[@numFound = '1']");
    doc = new SolrInputDocument();
    doc.setField("id", "10001");
    //behavior when hitting Solr directly
    doc.setField("dateRemove", ImmutableMap.of("remove", DateMathParser.parseMath(null, "2014-09-01T12:00:00Z")));
    assertU(adoc(doc));
    assertU(commit());
    assertQ(req("q", "dateRemove:*", "indent", "true"), "//result[@numFound = '4']");
    assertQ(req("q", "dateRemove:\"2014-09-01T12:00:00Z\"", "indent", "true"), "//result[@numFound = '3']");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) TrieDateField(org.apache.solr.schema.TrieDateField) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TrieDateField (org.apache.solr.schema.TrieDateField)6 SchemaField (org.apache.solr.schema.SchemaField)4 TrieDoubleField (org.apache.solr.schema.TrieDoubleField)4 TrieFloatField (org.apache.solr.schema.TrieFloatField)4 TrieIntField (org.apache.solr.schema.TrieIntField)4 Date (java.util.Date)3 BoolField (org.apache.solr.schema.BoolField)3 FieldType (org.apache.solr.schema.FieldType)3 StrField (org.apache.solr.schema.StrField)3 TrieLongField (org.apache.solr.schema.TrieLongField)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LeafReader (org.apache.lucene.index.LeafReader)2 SortedDocValues (org.apache.lucene.index.SortedDocValues)2 SolrException (org.apache.solr.common.SolrException)2 IndexSchema (org.apache.solr.schema.IndexSchema)2 LinkedList (java.util.LinkedList)1 BinaryDocValues (org.apache.lucene.index.BinaryDocValues)1 DocValuesType (org.apache.lucene.index.DocValuesType)1 FieldInfo (org.apache.lucene.index.FieldInfo)1