@Test
  public void testFilenameNumberedDelimiterDash() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField("id", "1");
    doc1.addField("pathnamebase", "MAP-12345678");
    solr.add(doc1);
    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField("id", "2");
    doc2.addField("pathnamebase", "TOP-12345678");
    solr.add(doc2);
    solr.commit();

    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:MAP-12345678")).getResults().getNumFound());
    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:TOP-12345678")).getResults().getNumFound());
    // split on dash
    assertEquals(
        "split on dash", 1, solr.query(new SolrQuery("name:TOP")).getResults().getNumFound());
    assertEquals(
        "split on dash", 2, solr.query(new SolrQuery("name:12345678")).getResults().getNumFound());
    assertEquals(
        "split on dash",
        1,
        solr.query(new SolrQuery("name:TOP 12345678")).getResults().getNumFound());
  }
  // Documents the effect of the caveat in http://wiki.apache.org/solr/Atomic_Updates
  @Test
  public void testHeadFlagUpdateEffect() throws Exception {
    SolrServer solr = getSolr();

    IndexingDocIncrementalSolrj doc = new IndexingDocIncrementalSolrj();
    doc.addField("id", "f#01");
    doc.addField("head", true);
    doc.addField("pathstat", "A");
    doc.addField("path", "dir/file.txt");
    doc.addField("pathext", "txt");
    doc.addField("text", "quite secret content, though searchable");
    solr.add(doc.getSolrDoc());
    solr.commit();
    assertEquals(
        "Should be searchable on path",
        1,
        solr.query(new SolrQuery("path:dir*")).getResults().getNumFound());
    assertEquals(
        "Should be searchable on pathext",
        1,
        solr.query(new SolrQuery("pathext:txt")).getResults().getNumFound());
    assertEquals(
        "Should be searchable on text",
        1,
        solr.query(new SolrQuery("text:secret")).getResults().getNumFound());

    IndexingDocIncrementalSolrj docd = new IndexingDocIncrementalSolrj();
    docd.addField("id", "f#02");
    docd.addField("head", true);
    docd.addField("pathstat", "D");
    docd.addField("path", "dir/file.txt");
    docd.addField("pathext", "txt");
    doc.setUpdateMode(true);
    doc.setField("head", false);
    solr.add(docd.getSolrDoc());
    solr.add(doc.getSolrDoc());
    solr.commit();
    assertEquals(
        "Both head and historical should be searchable on path",
        2,
        solr.query(new SolrQuery("path:dir*")).getResults().getNumFound());
    assertEquals(
        "Both head and historical should be searchable on pathext",
        2,
        solr.query(new SolrQuery("pathext:txt")).getResults().getNumFound());
    assertEquals(
        "Text search for historical has been scoped out, if made stored it might affect access control requirements",
        // assertEquals("Historical should still be searchable on text after head flag update",
        0,
        solr.query(new SolrQuery("text:secret")).getResults().getNumFound());
  }
  private static void createSolrAlert(String userId, String created, String hashtag) {

    Date d = new Date(created);
    // SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z+9HOUR'");
    // SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z-4HOUR'");
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    created = formatter.format(d);

    SolrServer server = new HttpSolrServer("http://sandbox.hortonworks.com:8983/solr/tweets");
    // create a tweet doc
    SolrInputDocument doc = new SolrInputDocument();

    doc.addField("id", userId + ":" + hashtag + "-" + created);
    doc.addField("doctype_s", "alert");
    doc.addField("createdAt_dt", created);
    doc.addField("tag_s", hashtag);

    try {
      server.add(doc);
      System.out.println("SolrBolt: successfully added alert to Solr server" + hashtag);
    } catch (Exception e) {
      e.printStackTrace();
      // collector.fail(input);
    }
  }
 protected void indexAndDelete(
     List<SolrInputDocument> solrDocs, List<String> idsToDelete, boolean isCommit) {
   synchronized (this.getClass()) {
     SolrServer solr = null;
     try {
       solr = SolrServerManager.getInstance().getSolrServer();
       if (CollectionUtils.isNotEmpty(solrDocs)) {
         UpdateResponse response = solr.add(solrDocs);
       }
       // deleting document which contains operation delete
       delete(idsToDelete, solr);
       if (isCommit) {
         try {
           commitRecordsToSolr(solr);
         } catch (HttpSolrServer.RemoteSolrException e) {
           lastCommitTime = System.currentTimeMillis();
           if (e.getMessage().startsWith(MAX_WARM_SEARCH)) {
             LOG.warn(e.getMessage());
           } else {
             throw e;
           }
         }
       }
     } catch (Exception e) {
       LOG.info("Exception :", e);
       rollback(solr);
       throw new DocstoreIndexException(e);
     }
   }
 }
 protected void indexSolrDocuments(List<SolrInputDocument> solrDocs, boolean isCommit) {
   synchronized (this.getClass()) {
     SolrServer solr = null;
     try {
       solr = SolrServerManager.getInstance().getSolrServer();
       UpdateResponse response = solr.add(solrDocs);
       if (isCommit) {
         try {
           commitRecordsToSolr(solr);
         } catch (HttpSolrServer.RemoteSolrException e) {
           lastCommitTime = System.currentTimeMillis();
           if (e.getMessage().startsWith(MAX_WARM_SEARCH)) {
             LOG.warn(e.getMessage());
           } else {
             throw e;
           }
         }
       }
     } catch (Exception e) {
       LOG.info("Exception :", e);
       rollback(solr);
       throw new DocstoreIndexException(e);
     }
   }
 }
Beispiel #6
0
  private static boolean commit(List<Review> rs) throws Exception {
    if (server == null) {
      server = getServer();
    }
    Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();

    for (Review r : rs) {
      SolrInputDocument doc1 = new SolrInputDocument();

      for (Field f : r.getClass().getDeclaredFields()) {
        if (!f.getName().equals("content") && !f.getName().equals("title")) {
          doc1.addField(f.getName(), f.getLong(r), 1.0f);
        } else {
          doc1.addField(f.getName(), f.get(r), 1.0f);
        }
      }

      docs.add(doc1);
      if (counter++ % 10000 == 0) {
        System.out.println("Process " + counter);
      }
    }
    server.add(docs);
    // 提交
    server.commit();
    System.out.println("Commit @ " + counter);
    return true;
  }
  @Test
  public void testFulltextSearchNumbersHyphen() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField("text", "word The SD-500 product");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should match simple word",
        1,
        solr.query(new SolrQuery("text:word")).getResults().getNumFound());
    assertEquals(
        "Should match exact product",
        1,
        solr.query(new SolrQuery("text:SD-500")).getResults().getNumFound());
    assertEquals(
        "Should match exact product lowercase",
        1,
        solr.query(new SolrQuery("text:sd-500")).getResults().getNumFound());

    // With hyphen also the StandardTokenizer will split.
    assertEquals(
        "Could match part 1", 1, solr.query(new SolrQuery("text:SD")).getResults().getNumFound());
    assertEquals(
        "Could match part 2", 1, solr.query(new SolrQuery("text:500")).getResults().getNumFound());

    assertEquals(
        "Could match quoted context",
        1,
        solr.query(new SolrQuery("text:\"The SD-500 product\"")).getResults().getNumFound());
  }
  @Test
  public void testFulltextSearchEmail() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField("text", "contact [email protected]");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should match simple word",
        1,
        solr.query(new SolrQuery("text:contact")).getResults().getNumFound());
    // Likely NOT possible with WDF in index pipeline.
    assertEquals(
        "Should match exact email",
        1,
        solr.query(new SolrQuery("text:[email protected]")).getResults().getNumFound());
    assertEquals(
        "Should match exact email - Quoted",
        1,
        solr.query(new SolrQuery("text:\"[email protected]\"")).getResults().getNumFound());

    assertEquals(
        "Could match part 1",
        1,
        solr.query(new SolrQuery("text:support")).getResults().getNumFound());
    assertEquals(
        "Could match part 2",
        1,
        solr.query(new SolrQuery("text:example.com")).getResults().getNumFound());
  }
  @Test
  @Ignore // very incomplete
  public void testPathAnalysis() throws SolrServerException, IOException {
    SolrServer solr = getSolr();
    // Not really unit testing the schema here because the path logic in the handler is too relevant
    // - could be switched to
    IndexingItemProgress p = mock(IndexingItemProgress.class);
    CmsRepository repo = new CmsRepository("http://ex.ampl:444/s/rep1");
    when(p.getRepository()).thenReturn(repo);
    when(p.getRevision()).thenReturn(new RepoRevision(35L, new Date()));
    CmsChangesetItem item = mock(CmsChangesetItem.class);
    when(item.getPath())
        .thenReturn(new CmsItemPath("/dir/doc main.xml"))
        .thenReturn(new CmsItemPath("/dir sect/doc appendix.xml"));
    ;
    IndexingDocIncrementalSolrj doc = new IndexingDocIncrementalSolrj();
    when(p.getFields()).thenReturn(doc);
    when(p.getItem()).thenReturn(item);
    HandlerPathinfo handlerPathinfo = new HandlerPathinfo();
    handlerPathinfo.handle(p);
    solr.add(doc.getSolrDoc());

    fail(
        "need to test effects of analyzed path* fields and confirm the need for name and extension");
  }
  @Override
  public void write(NutchDocument doc) throws IOException {
    final SolrInputDocument inputDoc = new SolrInputDocument();
    for (final Entry<String, List<String>> e : doc) {
      for (final String val : e.getValue()) {

        Object val2 = val;
        if (e.getKey().equals("content") || e.getKey().equals("title")) {
          val2 = SolrUtils.stripNonCharCodepoints(val);
        }

        inputDoc.addField(solrMapping.mapKey(e.getKey()), val2);
        String sCopy = solrMapping.mapCopyKey(e.getKey());
        if (sCopy != e.getKey()) {
          inputDoc.addField(sCopy, val2);
        }
      }
    }
    inputDoc.setDocumentBoost(doc.getScore());
    inputDocs.add(inputDoc);
    if (inputDocs.size() >= commitSize) {
      try {
        LOG.info("Adding " + Integer.toString(inputDocs.size()) + " documents");
        solr.add(inputDocs);
      } catch (final SolrServerException e) {
        throw new IOException(e);
      }
      inputDocs.clear();
    }
  }
  private SolrServer createServerAndTableWithSimpleTestDoc(String table)
      throws BlurException, TException, IOException, SolrServerException {
    createTable(table);
    SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), table);
    SolrInputDocument doc;

    doc = createSimpleTestDoc();

    server.add(doc);
    return server;
  }
 @Override
 public void close() throws IOException {
   try {
     if (!inputDocs.isEmpty()) {
       LOG.info("Adding " + Integer.toString(inputDocs.size()) + " documents");
       solr.add(inputDocs);
       inputDocs.clear();
     }
   } catch (final SolrServerException e) {
     throw new IOException(e);
   }
 }
Beispiel #13
0
  @Test
  public void test2() throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    // ID
    doc.setField("id", "3");
    // 名称
    doc.setField("name", "何灵");

    // 添加
    solrServer.add(doc);
    // 提交
    solrServer.commit();
  }
Beispiel #14
0
  public static void cache(String queryId, Object obj, SolrServer server, boolean commit)
      throws IOException, SolrServerException {
    SolrInputDocument newDoc = new SolrInputDocument();
    newDoc.addField(Constants.CACHE_INDEX_idFieldName, queryId);
    newDoc.addField(Constants.CACHE_INDEX_valueFieldName, SerializableUtils.serializeBase64(obj));
    // newDoc.addField(valueTextFieldName, ojbectToString(obj));

    if (server == null) {
      throw new SolrServerException("server IS NULL!");
    }
    server.add(newDoc);
    if (commit) server.commit();
  }
  @Test
  public void testFulltextSearchNumbers() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField("text", "word The SD500 product");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should match simple word",
        1,
        solr.query(new SolrQuery("text:word")).getResults().getNumFound());
    assertEquals(
        "Should match exact product",
        1,
        solr.query(new SolrQuery("text:SD500")).getResults().getNumFound());
    assertEquals(
        "Should match exact product lowercase",
        1,
        solr.query(new SolrQuery("text:sd500")).getResults().getNumFound());
    assertEquals(
        "Should match exact product quoted",
        1,
        solr.query(new SolrQuery("text:\"SD500\"")).getResults().getNumFound());
    assertEquals(
        "Should match exact product wildcard",
        1,
        solr.query(new SolrQuery("text:SD5*")).getResults().getNumFound());

    // WDF needs splitOnNumerics for these, which requires catenate or preserve for above asserts.
    /*
    assertEquals("Could match part 1", 1, solr.query(new SolrQuery("text:SD")).getResults().getNumFound());
    assertEquals("Could match part 2", 1, solr.query(new SolrQuery("text:500")).getResults().getNumFound());
    */

    // These asserts document the desire to have less spurious hits
    assertEquals(
        "Avoid matching other product SD200",
        0,
        solr.query(new SolrQuery("text:SD200")).getResults().getNumFound());
    assertEquals(
        "Avoid matching other product XX500",
        0,
        solr.query(new SolrQuery("text:XX500")).getResults().getNumFound());

    assertEquals(
        "Should match quoted context",
        1,
        solr.query(new SolrQuery("text:\"The SD500 product\"")).getResults().getNumFound());
  }
Beispiel #16
0
  @Test
  public void test1() throws Exception {
    String baseURL = "http://192.168.19.128:8080/solr";

    SolrServer solr = new HttpSolrServer(baseURL);
    SolrInputDocument doc = new SolrInputDocument();

    doc.setField("id", "2");
    doc.setField("name", "kobe");

    solr.add(doc);
    // 提交
    solr.commit();
  }
  @Override
  // Input Map is expected to have the suffixes on the key names
  public void add(String type, Map<String, Object> properties) throws PersistenceException {
    LOGGER.debug("type = {}", type);
    if (type == null || type.isEmpty()) {
      return;
    }
    if (properties == null || properties.isEmpty() || properties.containsValue("guest")) {
      return;
    }

    LOGGER.debug("Adding entry of type {}", type);

    // Set Solr Core name to type and create/connect to Solr Core
    SolrServer coreSolrServer = getSolrCore(type);
    if (coreSolrServer == null) {
      return;
    }

    Date now = new Date();
    // DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    // String createdDate = df.format(now);

    SolrInputDocument solrInputDocument = new SolrInputDocument();
    solrInputDocument.addField("createddate_tdt", now);

    for (Map.Entry<String, Object> entry : properties.entrySet()) {
      solrInputDocument.addField(entry.getKey(), entry.getValue());
    }

    try {
      UpdateResponse response = coreSolrServer.add(solrInputDocument);
      LOGGER.debug("UpdateResponse from add of SolrInputDocument:  {}", response);
    } catch (SolrServerException e) {
      LOGGER.info("SolrServerException while adding Solr index for persistent type {}", type, e);
      doRollback(coreSolrServer, type);
      throw new PersistenceException(
          "SolrServerException while adding Solr index for persistent type " + type, e);
    } catch (IOException e) {
      LOGGER.info("IOException while adding Solr index for persistent type {}", type, e);
      doRollback(coreSolrServer, type);
      throw new PersistenceException(
          "IOException while adding Solr index for persistent type " + type, e);
    } catch (RuntimeException e) {
      LOGGER.info("RuntimeException while adding Solr index for persistent type {}", type, e);
      doRollback(coreSolrServer, type);
      throw new PersistenceException(
          "RuntimeException while adding Solr index for persistent type " + type, e);
    }
  }
  @Test
  public void testFilenameNumberedDelimiterNone() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField("id", "1");
    doc1.addField("pathnamebase", "MAP12345678");
    solr.add(doc1);
    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField("id", "2");
    doc2.addField("pathnamebase", "TOP12345678");
    solr.add(doc2);
    solr.commit();

    assertEquals(
        "exact match", 1, solr.query(new SolrQuery("name:MAP12345678")).getResults().getNumFound());
    assertEquals(
        "exact match", 1, solr.query(new SolrQuery("name:TOP12345678")).getResults().getNumFound());

    assertEquals(
        "lowercase match",
        1,
        solr.query(new SolrQuery("name:map12345678")).getResults().getNumFound());
    assertEquals(
        "lowercase match",
        1,
        solr.query(new SolrQuery("name:top12345678")).getResults().getNumFound());

    // no split on number - debatable but splitting will generate very spurious hits when searching
    // to product names etc
    assertEquals(
        "no split on number", 0, solr.query(new SolrQuery("name:TOP")).getResults().getNumFound());
    assertEquals(
        "no split on number",
        0,
        solr.query(new SolrQuery("name:12345678")).getResults().getNumFound());
  }
  public static void indextData(final SolrServer solrServer, final List<RochadeEntity> entities) {
    List<SolrInputDocument> docs = new ArrayList<>();

    int index = 0;
    for (RochadeEntity entity : entities) {
      docs.add(createDocument(index, entity));
      index++;
    }
    try {
      solrServer.add(docs);
      solrServer.commit();
    } catch (SolrServerException | IOException e) {
      e.printStackTrace();
    }
  }
  @Test
  public void testFilenameNumberedDelimiterUnderscore() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField("id", "1");
    doc1.addField("pathnamebase", "MAP_12345678");
    solr.add(doc1);
    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField("id", "2");
    doc2.addField("pathnamebase", "TOP_12345678");
    solr.add(doc2);
    solr.commit();

    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:MAP_12345678")).getResults().getNumFound());
    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:TOP_12345678")).getResults().getNumFound());

    assertEquals(
        "split on underscore", 1, solr.query(new SolrQuery("name:TOP")).getResults().getNumFound());
    assertEquals(
        "split on underscore",
        2,
        solr.query(new SolrQuery("name:12345678")).getResults().getNumFound());

    // no split on underscore - debatable but good when using numbering (have the option to use
    // space if splitting is desired)
    /*
    assertEquals("no split on underscore", 0, solr.query(new SolrQuery("name:TOP")).getResults().getNumFound());
    assertEquals("no split on underscore", 0, solr.query(new SolrQuery("name:12345678")).getResults().getNumFound());
    */
  }
  public void update(Object entity) {
    if (!(entity instanceof AbstractEntity)) {
      return;
    }

    if (!(entity instanceof Session)) {
      return;
    }

    try {
      solrServer.deleteById(((Session) entity).getId());
      solrServer.add(createIndexDocument((Session) entity));
      solrServer.commit();
    } catch (SolrServerException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
Beispiel #22
0
  public static void cacheNEVector(
      String queryId,
      Object obj,
      String neType,
      String annotationFingerprint,
      SolrServer server,
      boolean commit)
      throws IOException, SolrServerException {
    SolrInputDocument newDoc = new SolrInputDocument();
    newDoc.addField(Constants.CACHE_INDEX_idFieldName, queryId);
    newDoc.addField(Constants.CACHE_INDEX_valueFieldName, SerializableUtils.serializeBase64(obj));
    newDoc.addField(Constants.CACHE_INDEX_ANNOTATABLE, annotationFingerprint);
    newDoc.addField(Constants.CACHE_INDEX_NETYPE, neType);

    if (server == null) {
      throw new SolrServerException("server IS NULL!");
    }
    server.add(newDoc);
    if (commit) server.commit();
  }
    public SolrServer create() throws Exception {
      createTable(tableName);
      SolrServer server =
          new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), tableName);

      for (int i = 0; i < rows; i++) {
        SolrInputDocument parent = new SolrInputDocument();
        parent.addField(BlurConstants.ROW_ID, i);
        for (int j = 0; j < recordsPerRow; j++) {
          SolrInputDocument child = new SolrInputDocument();
          child.addField(BlurConstants.RECORD_ID, j);

          for (String colName : columns) {
            child.addField(colName, "value" + i + "-" + j);
          }
          parent.addChildDocument(child);
        }
        server.add(parent);
      }
      return server;
    }
  @Test
  @Ignore // Stem Possessive is a feature of the WDF.
  public void testFulltextSearchEnglishPossessive() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField("text", "word Staffan's & Thomas' code");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should match simple word",
        1,
        solr.query(new SolrQuery("text:word")).getResults().getNumFound());
    assertEquals(
        "Should match name 1",
        1,
        solr.query(new SolrQuery("text:staffan")).getResults().getNumFound());
    assertEquals(
        "Should match name 2",
        1,
        solr.query(new SolrQuery("text:thomas")).getResults().getNumFound());

    // Likely only possible with WDF in both pipelines or without WDF.
    /*
    assertEquals("Should match possessive name 1", 1, solr.query(new SolrQuery("text:Staffan's")).getResults().getNumFound());
    assertEquals("Should match possessive name 2", 1, solr.query(new SolrQuery("text:Thomas'")).getResults().getNumFound());
    */

    // Works when WDF is only in index pipeline.
    assertEquals(
        "Could match quoted no possessive",
        1,
        solr.query(new SolrQuery("text:\"Staffan & Thomas code\"")).getResults().getNumFound());

    // Likely only possible with WDF in query pipeline or without WDF.
    /*
    assertEquals("Could match quoted exact", 1, solr.query(new SolrQuery("text:\"Staffan's & Thomas' code\"")).getResults().getNumFound());
    */
  }
  @Test
  public void testFulltextSearchDelimiters() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField("text", "word top-level");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should match simple word",
        1,
        solr.query(new SolrQuery("text:word")).getResults().getNumFound());
    assertEquals(
        "Should match exact",
        1,
        solr.query(new SolrQuery("text:top-level")).getResults().getNumFound());
    assertEquals(
        "Should match exact - Quoted",
        1,
        solr.query(new SolrQuery("text:\"top-level\"")).getResults().getNumFound());
    assertEquals(
        "Could match exact - Quoted space instead of dash",
        1,
        solr.query(new SolrQuery("text:\"top level\"")).getResults().getNumFound());
    assertEquals(
        "Should match part 1", 1, solr.query(new SolrQuery("text:top")).getResults().getNumFound());
    assertEquals(
        "Should match part 2",
        1,
        solr.query(new SolrQuery("text:level")).getResults().getNumFound());

    // Below asserts just documents current behavior, would be fine if they also hit.
    assertEquals(
        "Unlikely to match catenated",
        0,
        solr.query(new SolrQuery("text:toplevel")).getResults().getNumFound());
  }
  @Test
  public void docShouldBeDiscoverableWithMultiValuedFields()
      throws SolrServerException, IOException, BlurException, TException {
    String table = "docShouldBeDiscoverableWithMultiValuedFields";
    createTable(table);
    SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), table);
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("rowid", "1");

    SolrInputDocument child = new SolrInputDocument();
    child.addField("recordid", "1");
    child.addField("fam.value", "123");
    child.addField("fam.value", "124");

    doc.addChildDocument(child);

    server.add(doc);

    assertTotalResults(table, "fam.value:123", 1l);
    assertTotalResults(table, "fam.value:124", 1l);
    assertTotalResults(table, "fam.value:justincase", 0l);

    removeTable(table);
  }
  @Test
  public void testPropertySearch() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField("prop_svn.ignore", "ignore1\nignore2");
    doc.addField("prop_svn.externals", "ext1 ^/some/folder\next2\t^/some/other/folder");
    doc.addField("prop_custom.lang", "se-SE | de-SE | en-US");
    doc.addField("prop_custom.values", "whatever, Value,Wanted");
    doc.addField("prop_custom.values2", "Semi;colon ;Separated");
    doc.addField("prop_custom.tags", "testing validation JUnit");
    doc.addField("prop_custom.json", "[{\"jsonkey\":\"jsonval\"}, \"justval\"]");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should tokenize on newline",
        1,
        solr.query(new SolrQuery("prop_svn.ignore:ignore2")).getResults().getNumFound());
    assertEquals(
        "Should still match the full value",
        1,
        solr.query(new SolrQuery("prop_svn.ignore:ignore1\nignore2")).getResults().getNumFound());
    // assertEquals("What id the full value has one token that doesn't match?", 0, solr.query(new
    // SolrQuery("prop_svn.ignore:ignore1\nignore0")).getResults().getNumFound());
    assertEquals(
        "Should tokenize on whitespace",
        1,
        solr.query(new SolrQuery("prop_svn.externals:\"^/some/folder\""))
            .getResults()
            .getNumFound());
    assertEquals(
        "Should tokenize on tab",
        1,
        solr.query(new SolrQuery("prop_svn.externals:\"^/some/other/folder\""))
            .getResults()
            .getNumFound());
    assertEquals(
        "Should match on line",
        1,
        solr.query(new SolrQuery("prop_svn.externals:\"ext1 ^/some/folder\""))
            .getResults()
            .getNumFound());
    assertEquals(
        "What if a line has a mismatching token",
        0,
        solr.query(new SolrQuery("prop_svn.externals:\"ext0 ^/some/folder\""))
            .getResults()
            .getNumFound());
    // assertEquals("What if a line has a mismatching token that exists somewhere else", 0,
    // solr.query(new SolrQuery("prop_svn.externals:\"ext2
    // ^/some/folder\"")).getResults().getNumFound());
    assertEquals(
        "Could match on line regarless of whitespace",
        1,
        solr.query(new SolrQuery("prop_svn.externals:\"ext2 ^/some/other/folder\""))
            .getResults()
            .getNumFound());
    assertEquals(
        "Should separate on comma",
        1,
        solr.query(new SolrQuery("prop_custom.values:Value")).getResults().getNumFound());
    assertEquals(
        "Should separate on semicolon",
        1,
        solr.query(new SolrQuery("prop_custom.values2:Separated")).getResults().getNumFound());
    // how?//assertEquals("Should separate on pipe", 1, solr.query(new
    // SolrQuery("prop_custom.lang:de-DE")).getResults().getNumFound());
    assertEquals(
        "Should separate on whitespace",
        1,
        solr.query(new SolrQuery("prop_custom.tags:JUnit")).getResults().getNumFound());

    /*
    assertEquals("Making property search case insensitive wouldn't be good when props contain URLs etc",
    		0, solr.query(new SolrQuery("prop_custom.tags:junit")).getResults().getNumFound());
    */
    assertEquals(
        "Expecting property search to be case insensitive.",
        1,
        solr.query(new SolrQuery("prop_custom.tags:junit")).getResults().getNumFound());
  }
  @Test
  public void testFulltextSearchCamelCase() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "1");
    doc.addField(
        "text", "word JavaClassName getMethodName getMethod2Name The ProductNAME followed by text");
    solr.add(doc);
    solr.commit();

    assertEquals(
        "Should match simple word",
        1,
        solr.query(new SolrQuery("text:word")).getResults().getNumFound());
    assertEquals(
        "Should match words in sequence",
        1,
        solr.query(new SolrQuery("text:followed by text")).getResults().getNumFound());
    assertEquals(
        "Should match quoted words in sequence",
        1,
        solr.query(new SolrQuery("text:\"followed by text\"")).getResults().getNumFound());
    assertEquals(
        "Should not match quoted words out of sequence",
        0,
        solr.query(new SolrQuery("text:\"followed text\"")).getResults().getNumFound());

    assertEquals(
        "Should match Java Class Name camelcase",
        1,
        solr.query(new SolrQuery("text:JavaClassName")).getResults().getNumFound());
    assertEquals(
        "Should match Java Class Name lowercase",
        1,
        solr.query(new SolrQuery("text:javaclassname")).getResults().getNumFound());
    assertEquals(
        "Should match Java Method Name camelcase",
        1,
        solr.query(new SolrQuery("text:getMethodName")).getResults().getNumFound());
    assertEquals(
        "Should match Java Method Name lowercase",
        1,
        solr.query(new SolrQuery("text:getmethodname")).getResults().getNumFound());
    assertEquals(
        "Should match Java Method Name wildcard",
        1,
        solr.query(new SolrQuery("text:getmethod*")).getResults().getNumFound());

    assertEquals(
        "Should match Java Method 2 Name camelcase",
        1,
        solr.query(new SolrQuery("text:getMethod2Name")).getResults().getNumFound());
    assertEquals(
        "Should match Java Method 2 Name lowercase",
        1,
        solr.query(new SolrQuery("text:getmethod2name")).getResults().getNumFound());
    assertEquals(
        "Should match Java Method 2 Name wildcard",
        1,
        solr.query(new SolrQuery("text:getmethod2*")).getResults().getNumFound());

    assertEquals(
        "Should match Product Name case-switch",
        1,
        solr.query(new SolrQuery("text:ProductNAME")).getResults().getNumFound());
    assertEquals(
        "Should match Product Name lowercase",
        1,
        solr.query(new SolrQuery("text:productname")).getResults().getNumFound());
    assertEquals(
        "Should match Product Name leading capital",
        1,
        solr.query(new SolrQuery("text:Productname")).getResults().getNumFound());
    assertEquals(
        "Should match Product Name in context",
        1,
        solr.query(new SolrQuery("text:The ProductNAME followed by text"))
            .getResults()
            .getNumFound());
    // Will fail if using preserveOriginal="1".
    assertEquals(
        "Should match Product Name in context - Quoted",
        1,
        solr.query(new SolrQuery("text:\"The ProductNAME followed by text\""))
            .getResults()
            .getNumFound());
    assertEquals(
        "Should match Product Name lowercase in context - Quoted",
        1,
        solr.query(new SolrQuery("text:\"The Productname followed by text\""))
            .getResults()
            .getNumFound());

    // Difficult to combine individual components with quoted search.
    /*
    assertEquals("Could match Product Name individual components", 1, solr.query(new SolrQuery("text:product")).getResults().getNumFound());
    assertEquals("Could match Product Name individual components", 1, solr.query(new SolrQuery("text:name")).getResults().getNumFound());
    assertEquals("Could match Product Name separated components", 1, solr.query(new SolrQuery("text:product name")).getResults().getNumFound());
    */
  }
  @Test
  public void testFilenameDescriptiveReverse() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField("id", "1");
    doc1.addField("pathnamebase", "Machine Large");
    solr.add(doc1);
    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField("id", "2");
    doc2.addField("pathnamebase", "machine Small");
    solr.add(doc2);
    solr.commit();

    assertEquals(
        "one term", 2, solr.query(new SolrQuery("name:machine")).getResults().getNumFound());
    assertEquals("one term", 1, solr.query(new SolrQuery("name:large")).getResults().getNumFound());
    assertEquals("one term", 1, solr.query(new SolrQuery("name:small")).getResults().getNumFound());

    assertEquals(
        "no exact match reverse",
        0,
        solr.query(new SolrQuery("name:Large\\ Machine")).getResults().getNumFound());
    assertEquals(
        "no exact match reverse",
        0,
        solr.query(new SolrQuery("name:Small\\ machine")).getResults().getNumFound());

    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:Machine\\ Large")).getResults().getNumFound());
    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:machine\\ Small")).getResults().getNumFound());

    assertEquals(
        "tokenized match",
        1,
        solr.query(new SolrQuery("name:Large Machine")).getResults().getNumFound());
    assertEquals(
        "tokenized match",
        1,
        solr.query(new SolrQuery("name:Small machine")).getResults().getNumFound());

    // Strange result below this point.
    // The first token seems to be special with solr.PatternTokenizerFactory
    assertEquals(
        "tokenized match reverse",
        2,
        solr.query(new SolrQuery("name:Machine Large")).getResults().getNumFound()); // Debatable
    assertEquals(
        "tokenized match reverse",
        2,
        solr.query(new SolrQuery("name:machine Small")).getResults().getNumFound()); // Debatable
    /*
    	assertEquals("different delimiter", 1, solr.query(new SolrQuery("name:Large-Machine")).getResults().getNumFound());
    	assertEquals("different delimiter", 1, solr.query(new SolrQuery("name:Small_machine")).getResults().getNumFound());
    */
    assertEquals(
        "lowercase", 1, solr.query(new SolrQuery("name:large machine")).getResults().getNumFound());

    assertEquals(
        "", 1, solr.query(new SolrQuery("name:large huge machine")).getResults().getNumFound());

    assertEquals(
        "one term", 2, solr.query(new SolrQuery("name:machine")).getResults().getNumFound());

    assertEquals(
        "all terms must match? - first term must match?",
        0,
        solr.query(new SolrQuery("name:huge machine")).getResults().getNumFound());
    assertEquals(
        "all terms must match - should be 0 hits??",
        2,
        solr.query(new SolrQuery("name:machine huge")).getResults().getNumFound());
  }
  @Test
  public void testFilenameDescriptive() throws Exception {
    SolrServer solr = getSolr();
    SolrInputDocument doc1 = new SolrInputDocument();
    doc1.addField("id", "1");
    doc1.addField("pathnamebase", "Large Machine");
    solr.add(doc1);
    SolrInputDocument doc2 = new SolrInputDocument();
    doc2.addField("id", "2");
    doc2.addField("pathnamebase", "Small machine");
    solr.add(doc2);
    solr.commit();

    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:Large\\ Machine")).getResults().getNumFound());
    assertEquals(
        "exact match",
        1,
        solr.query(new SolrQuery("name:Small\\ machine")).getResults().getNumFound());

    assertEquals(
        "tokenized match",
        1,
        solr.query(new SolrQuery("name:Large Machine")).getResults().getNumFound());
    assertEquals(
        "tokenized match",
        1,
        solr.query(new SolrQuery("name:Small machine")).getResults().getNumFound());

    assertEquals(
        "different delimiter",
        1,
        solr.query(new SolrQuery("name:Large-Machine")).getResults().getNumFound());
    assertEquals(
        "different delimiter",
        1,
        solr.query(new SolrQuery("name:Small_machine")).getResults().getNumFound());

    assertEquals(
        "lowercase", 1, solr.query(new SolrQuery("name:large machine")).getResults().getNumFound());

    assertEquals(
        "", 1, solr.query(new SolrQuery("name:large huge machine")).getResults().getNumFound());

    assertEquals(
        "one term", 2, solr.query(new SolrQuery("name:machine")).getResults().getNumFound());
    // assertEquals("term order", 1, solr.query(new SolrQuery("name:machine
    // large")).getResults().getNumFound());

    // Makes no sense...
    assertEquals(
        "all terms must match?",
        0,
        solr.query(new SolrQuery("name:huge machine")).getResults().getNumFound());
    assertEquals(
        "all terms must match - should be 0 hits??",
        2,
        solr.query(new SolrQuery("name:machine huge")).getResults().getNumFound());
  }