Sean's Blog

心之所向,身之所往。

How to invoke a method in the jar?

We can use URLClassLoader to load classes from a given path. URL myJar = new File("jar/LibraryA-1.0-SNAPSHOT.jar").toURI().toURL(); URLClassLoader clsLoader = new URLClassLoader( new URL[] {myJar}, this.getClass().getClassLoader() ); Class<?> loadedClass = clsLoader.loadClass("com.sean.liba.Main"); Method method = loadedClass.getDeclaredMethod("print"); Object instance = loadedClass.newInstance(); method.invoke(instance); // Output: Hello World! Let’s look at other use cases. What if you have two jars, and liba.jar deppends on another class in the libb.jar? Take the above example, the print method has a dependency on the com.

[Elasticsearch] Working with disjunction max query - dis_max

GET /_search
{
  "query": {
    "dis_max": {
      "queries": [
        { "term": { "title": "iphone" } },
        { "term": { "body": "iphone" } }
      ],
      // "tie_breaker": 0.7
    }
  }
}

ㄉ12121221 This is the official document written about dis_max:

Returns documents matching one or more wrapped queries, called query clauses or clauses.

If a returned document matches multiple query clauses, the dis_max query assigns the document the highest relevance score from any matching clause, plus a tie breaking increment for any additional matching subqueries.


[Elasticsearch] How to use minimum_should_match and operator with match query?

GET /_search
{
  "query": {
    "match": {
      "message": {
        "query": "this is a test yo",
        // "operator": "or"
      }
    }
  }
}

This is the Match query we see quite often when using ES. However, if you did specify an analyzer during mapping, the query “this is a test yo" will likely be tokenized into five terms ”this”, “is”, “a”, “test”, and “yo” in the search phases. And there is an implicit parameter operator, and its default value is “or”. This means, this query will look up the documents in the index, and whenever there is any term match in the message of a doc, then that it’s a match!


How To Get A List Of Sheet Names In Google Sheets With Script?

There’s no built-in formula to do this, and we have to write our own script with Google’s Apps Script to achieve the function. First, go to the Extensions → Apps Script. Second, write our own method getSheetsName in the Apps Script console, and save. Code snippets: function getSheetsName() { var sheetNames = new Array() var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); for (var i=0 ; i<sheets.length ; i++) { sheetNames.push( [ sheets[i].getName() ] ) } return sheetNames } Then go back to your sheet, and type the formula with the function name we just created in the Apps Script.

[Elasticsearch] Function score query

By reading the official document of the Function score query, I still couldn’t get a sense of how to use it correctly. After reading through more articles written by others, here’s how I interpret it with the formula of the newly computed score: function_score = min(score_mode(f1_score, f2_score, ...), max_boost) _score = boost_mode(boost*query_score, function_score) Example 1: { "query": { "function_score": { "query": { "match_all": {} }, "boost": "5", "random_score": {}, "boost_mode": "multiply" } } } Score: