Skip to content

Commit

Permalink
Improved search querys
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuechner committed Oct 25, 2021
1 parent e555e71 commit 6b5b326
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ hs_err_pid*
/nb-configuration.xml
/derby.log
/files/
/src/main/resources/beagen.dev.cfg
/src/main/resources/.idea
3 changes: 2 additions & 1 deletion src/main/java/de/ddb/labs/beagen/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ public static void main(String[] args) throws Exception {
.withSchedule(CronScheduleBuilder.cronSchedule(Configuration.get().getValue(BEAGEN_CRON)))
.build();

quartzScheduler = new StdSchedulerFactory().getScheduler();
quartzScheduler = new StdSchedulerFactory().getDefaultScheduler();
quartzScheduler.start();
quartzScheduler.scheduleJob(job, trigger);


// start javalin server
final Javalin app = Javalin.create(config -> {
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/de/ddb/labs/beagen/backend/jobs/BeaconJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -67,13 +69,28 @@ public class BeaconJob implements Job {
private static final int ENTITYCOUNT = 10000;

static {
SEARCH.put(TYPE.PERSON, "/search/index/person/select?q=*:*&fl=id,variant_id,count,count_sec_01,count_sec_02,count_sec_03,count_sec_04,count_sec_05,count_sec_06,count_sec_07&rows=" + ENTITYCOUNT + "&sort=count%20DESC,%20id%20ASC&wt=json");
SEARCH.put(TYPE.ORGANISATION, "/search/index/organization/select?q=*:*&fl=id,variant_id,count,count_sec_01,count_sec_02,count_sec_03,count_sec_04,count_sec_05,count_sec_06,count_sec_07&rows=" + ENTITYCOUNT + "&sort=count%20DESC,%20id%20ASC&wt=json");
SEARCH.put(TYPE.PERSON, "/search/index/person/select?"
+ "q=count:*"
+ "&fl=id,variant_id,count,count_sec_01,count_sec_02,count_sec_03,count_sec_04,count_sec_05,count_sec_06,count_sec_07"
+ "&rows=" + ENTITYCOUNT
+ "&sort=count%20DESC,id%20ASC"
+ "&wt=json");
SEARCH.put(TYPE.ORGANISATION, "/search/index/organization/select?"
+ "q=(type:gnd-organization%20AND%20count:*)%20OR%20(type:ddb-institution%20AND%20variant_id:*)"
+ "&fl=id,variant_id,count,count_sec_01,count_sec_02,count_sec_03,count_sec_04,count_sec_05,count_sec_06,count_sec_07"
+ "&rows=" + ENTITYCOUNT
+ "&sort=count%20DESC,id%20ASC"
+ "&wt=json");
}

// Logger
private static final Logger LOG = LoggerFactory.getLogger(BeaconJob.class);

/**
*
* @param context
* @throws JobExecutionException
*/
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
// Date
Expand Down Expand Up @@ -198,12 +215,12 @@ private List<EntityCounts> getDataFromDdbApi(TYPE type) throws IOException, Pars
final String baseUrl = URL + SEARCH.get(type);

final List<EntityCounts> list = new ArrayList<>();
int totalCount = 0;
String nextCursorMark = "*";

while (true) {
final String url = baseUrl + "&cursorMark=" + nextCursorMark;
final String url = baseUrl + "&cursorMark=" + URLEncoder.encode(nextCursorMark, Charset.forName("UTF-8"));
final InputStream is = DDBApi.httpGet(url);
LOG.debug("Query: {}", url);

final JsonNode doc = mapper.readTree(is);
final String nextCursorMarkLocal = doc.get("nextCursorMark").asText("");
Expand All @@ -212,7 +229,7 @@ private List<EntityCounts> getDataFromDdbApi(TYPE type) throws IOException, Pars
} else {
nextCursorMark = nextCursorMarkLocal;
}
totalCount = doc.get("response").get("numFound").asInt(0);
int totalCount = doc.get("response").get("numFound").asInt(0);
final JsonNode docsArray = doc.get("response").get("docs");
final List<EntityCounts> ec = Arrays.asList(mapper.treeToValue(docsArray, EntityCounts[].class));
list.addAll(ec);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/beagen.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Set this here or use environment variables
beagen.baseurl=http://localhost:8080
beagen.pathprefix=
# beagen.baseurl=http://localhost/app/beagen
# beagen.baseurl=http://localhost:8080/app/beagen
# beagen.pathprefix=/app/beagen
beagen.port=8080
beagen.cron=0 0 12 * * ?
Expand Down
248 changes: 248 additions & 0 deletions src/main/resources/beagen.dev.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Configuration
# Set this here or use environment variables
beagen.baseurl=http://localhost:8080
beagen.pathprefix=
beagen.port=8080
beagen.cron=0 */1 * * * ?
beagen.database.dir=files/database/

# the following entries are not overwriteable by environment variables
beagen.beacon.header.person.all=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_01=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.archivportal-d.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite beim Archivportal-D\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Archiv der Deutschen Digitalen Bibliothek im Archivportal-D\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_02=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Bibliothek in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_03=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Denkmalpflege in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_04=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Forschung in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_05=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Mediathek in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_06=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Museum in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.person.sec_07=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/person/gnd/{ID}\n\
#MESSAGE: Personenseite bei der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Personenseiten der Kultursparte Sonstige in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.all=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_01=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Archiv in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_02=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Bibliothek in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_03=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Denkmalpflege in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_04=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Forschung in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_05=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Mediathek in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_06=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Museum in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

beagen.beacon.header.organisation.sec_07=\
#FORMAT: BEACON\n\
#PREFIX: https://d-nb.info/gnd/\n\
#TARGET: https://www.deutsche-digitale-bibliothek.de/organization/gnd/{ID}\n\
#MESSAGE: Organisationenseite der Deutschen Digitalen Bibliothek\n\
#RELATION: http://schema.org/sameAs\n\
#FEED: {{feed}}\n\
#CREATOR: Beagen <https://github.com/mbuechner/beagen>\n\
#CONTACT: Michael Büchner <[email protected]>\n\
#INSTITUTION: Deutsche Digitale Bibliothek\n\
#DESCRIPTION: Organisationenseiten der Kultursparte Sonstige in der Deutschen Digitalen Bibliothek\n\
#PERMALINK: {{id}}\n\
#TIMESTAMP: {{date}}\n\
#UPDATE: monthly

0 comments on commit 6b5b326

Please sign in to comment.