public void commitRecordsToSolr(SolrServer solr) throws SolrServerException, IOException {

    if (commitCounter < MAX_WARM_SEARCH_COUNT) {
      solr.commit(false, false, false);
      // LOG.info("Time taken to commit with waitSearch = false  commitCounter <
      // MAX_WARM_SEARCH_COUNT");
      commitCounter++;
    } else {

      timeSinceLastCommit = System.currentTimeMillis() - lastCommitTime;
      if (timeSinceLastCommit > TIME_FOR_WARMING_SEARCHERS) {
        solr.commit(false, false, false);
        commitCounter++;
        //                commitCounter = 1;
        // LOG.info("Time taken to commit with waitSearch = false  timeSinceLastCommit >
        // TIME_FOR_WARMING_SEARCHERS");

      } else {
        long startTime = System.currentTimeMillis();
        solr.commit(false, true, false);
        long endTime = System.currentTimeMillis();
        // LOG.info("Time taken to commit with waitSearch = true and time taken is " + (endTime -
        // startTime));
        commitCounter = 1;
      }
    }
    lastCommitTime = System.currentTimeMillis();
  }
  // 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());
  }
예제 #3
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 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());
  }
  @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());
  }
 /* (non-Javadoc)
  * @see fr.hoteia.qalingo.core.solr.service.ProductSkuSolrService#addOrUpdateProductSku(fr.hoteia.qalingo.core.domain.ProductSku)
  */
 public void addOrUpdateProductSku(
     final ProductSku productSku, final MarketArea marketArea, final Retailer retailer)
     throws SolrServerException, IOException {
   if (productSku.getId() == null) {
     throw new IllegalArgumentException("Id  cannot be blank or null.");
   }
   if (logger.isDebugEnabled()) {
     logger.debug("Indexing productSku " + productSku.getId());
     logger.debug("Indexing productSku " + productSku.getBusinessName());
     logger.debug("Indexing productSku " + productSku.getDescription());
     logger.debug("Indexing productSku " + productSku.getCode());
   }
   ProductSkuSolr productSkuSolr = new ProductSkuSolr();
   productSkuSolr.setId(productSku.getId());
   productSkuSolr.setBusinessname(productSku.getBusinessName());
   productSkuSolr.setDescription(productSku.getDescription());
   productSkuSolr.setCode(productSku.getCode());
   ProductSkuPrice productSkuPrice = productSku.getPrice(marketArea.getId(), retailer.getId());
   if (productSkuPrice != null) {
     BigDecimal salePrice = productSkuPrice.getSalePrice();
     productSkuSolr.setPrice(salePrice.toString());
   }
   productSkuSolrServer.addBean(productSkuSolr);
   productSkuSolrServer.commit();
 }
예제 #8
0
 /**
  * Commits the documents by batch
  *
  * @param indexing
  * @param counter
  * @param subject
  * @return
  * @throws CorruptIndexException
  * @throws IOException
  */
 private long commit(boolean indexing, long counter, String subject)
     throws SolrServerException, IOException {
   if (!indexing || (++counter % COMMIT) == 0) { // Index by batch
     server.commit();
     logger.info("Commited {} entities. Last entity: {}", (indexing ? COMMIT : counter), subject);
   }
   return counter;
 }
예제 #9
0
  @Test
  public void test2() throws Exception {
    SolrInputDocument doc = new SolrInputDocument();
    // ID
    doc.setField("id", "3");
    // 名称
    doc.setField("name", "何灵");

    // 添加
    solrServer.add(doc);
    // 提交
    solrServer.commit();
  }
예제 #10
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();
  }
  public void forceCommitPending() {

    try {

      server.commit();
    } catch (SolrServerException ex) {
      ex.printStackTrace();
      Logger.getRootLogger().error(ex.getMessage());
    } catch (IOException ex) {
      ex.printStackTrace();
      Logger.getRootLogger().error(ex.getMessage());
    }
  }
  @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());
  }
예제 #13
0
  public void delete(Object entity) {
    if (!(entity instanceof AbstractEntity)) {
      return;
    }

    try {
      solrServer.deleteById(((AbstractEntity) entity).getId());
      solrServer.commit();
    } catch (SolrServerException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 @Override
 public void delete(String id) {
   try {
     SolrServer server = SolrServerManager.getInstance().getSolrServer();
     deleteRecordInSolr(server, id);
     server.commit();
   } catch (SolrServerException e) {
     LOG.info("Exception :", e);
     throw new DocstoreIndexException();
   } catch (IOException e) {
     LOG.info("Exception :", e);
     throw new DocstoreIndexException();
   }
 }
예제 #15
0
  @Before
  public void initSearcher() throws Exception {
    service = new SolrSearchService();

    System.setProperty(
        "solr.solr.home", SolrTest.class.getClassLoader().getResource(".").getPath() + "solr-test");
    SolrServer solrServer =
        SolrServerFactory.newEmbeddedInstance(
            new File(
                SolrTest.class.getClassLoader().getResource(".").getPath()
                    + "/solr-test/venues/conf"),
            new File("/tmp/solrdataDir"));
    solrServer.deleteById("1");
    solrServer.commit();
    Venue v = new Venue();
    v.setId(1l);
    v.setName("La nueva galicia");
    v.setAddress("Calle del pozo,13");
    v.setSlug("nueva-galicia");
    solrServer.addBean(v);
    solrServer.commit();
    service.setSolr(solrServer);
  }
예제 #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();
  }
예제 #17
0
  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();
    }
  }
예제 #18
0
 public void run() {
   while (true) {
     try {
       Thread.sleep(15000);
       server.commit();
       LOG.info("Committing Index");
     } catch (InterruptedException e) {
       LOG.error("Interrupted: " + e.getMessage());
       e.printStackTrace();
     } catch (SolrServerException e) {
       LOG.error("Error committing: " + e.getMessage());
       e.printStackTrace();
     } catch (IOException e) {
       LOG.error("Error committing: " + e.getMessage());
       e.printStackTrace();
     }
   }
 }
예제 #19
0
  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);
    }
  }
  @SuppressWarnings("finally")
  public boolean deleteItems(Query query) {
    boolean status = false;
    try {
      server.deleteByQuery(query.getQueryString());
      UpdateResponse response = server.commit();
      int statusId = response.getStatus();
      if (statusId == 0) {
        status = true;
      }

    } catch (SolrServerException ex) {
      Logger.getRootLogger().error(ex.getMessage());
    } catch (IOException ex) {
      Logger.getRootLogger().error(ex.getMessage());
    } finally {
      return status;
    }
  }
  @SuppressWarnings("finally")
  public boolean deleteMediaItem(String mediaItemId) {
    mediaItemId.replaceFirst("::", "%%");
    boolean status = false;
    try {
      server.deleteByQuery("id:" + mediaItemId);
      UpdateResponse response = server.commit();
      int statusId = response.getStatus();
      if (statusId == 0) {
        status = true;
      }

    } catch (SolrServerException ex) {
      Logger.getRootLogger().error(ex.getMessage());
    } catch (IOException ex) {
      Logger.getRootLogger().error(ex.getMessage());
    } finally {
      return status;
    }
  }
예제 #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();
  }
예제 #23
0
 protected static void setup(String solrHome, String coreName) throws Exception {
   System.setProperty("solr.solr.home", solrHome);
   File index = new File(solrHome + "/" + coreName + "/data/index/");
   if (index.exists()) {
     FileUtils.cleanDirectory(index);
   }
   File tlog = new File(solrHome + "/" + coreName + "/data/tlog/");
   if (tlog.exists()) {
     FileUtils.cleanDirectory(tlog);
   }
   coreContainer = new CoreContainer(solrHome);
   coreContainer.load();
   solr = new EmbeddedSolrServer(coreContainer, coreName);
   solrCore = coreContainer.getCore(coreName);
   try {
     solr.deleteByQuery("*:*");
     solr.commit();
   } catch (SolrException e) {
     // might get "no such core" in the multi-core config
   }
 }
  @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());
    */
  }
예제 #25
0
  private void waitForIndexAndCommit(long timeout) throws Exception {
    boolean indexSuccess = false;
    try {
      // Now wait until its finished
      long tryUntil = System.currentTimeMillis() + timeout;
      while (System.currentTimeMillis() < tryUntil) {
        Thread.sleep(100);
        IndexDefinition definition = model.getIndex(INDEX_NAME);
        if (definition.getBatchBuildState() == IndexBatchBuildState.INACTIVE) {
          Long amountFailed =
              definition.getLastBatchBuildInfo().getCounters().get(COUNTER_NUM_FAILED_RECORDS);
          boolean successFlag = definition.getLastBatchBuildInfo().getSuccess();
          indexSuccess = successFlag && (amountFailed == null || amountFailed == 0L);
          if (!indexSuccess) {
            fail(
                "Batch index build did not finish successfully: success flag = "
                    + successFlag
                    + ", amount failed records = "
                    + amountFailed
                    + ", job state = "
                    + definition.getLastBatchBuildInfo().getJobState()
                    + ", job id = "
                    + definition.getLastBatchBuildInfo().getJobId()
                    + ", job url = "
                    + definition.getLastBatchBuildInfo().getTrackingUrl());
          } else {
            break;
          }
        }
      }
    } catch (Exception e) {
      throw new Exception("Error checking if batch index job ended.", e);
    }

    if (!indexSuccess) {
      fail("Batch build did not end after " + BUILD_TIMEOUT + " millis");
    } else {
      solrServer.commit();
    }
  }
  @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 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());
    */
  }
  @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());
  }
예제 #29
0
 private void buildAndCommit() throws Exception {
   lilyServerProxy.batchBuildIndex(INDEX_NAME, BUILD_TIMEOUT);
   solrServer.commit();
 }
  @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());
    */
  }