Skip to content

Commit

Permalink
add weight
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Nov 4, 2024
1 parent 5a20703 commit 8013500
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class EsUrlQueue extends UrlQueueImpl<String> implements ToXContent {

public static final String CREATE_TIME = "createTime";

public static final String WEIGHT = "weight";

@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
builder.startObject();
Expand All @@ -62,6 +64,7 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
if (createTime != null) {
builder.field(CREATE_TIME, createTime);
}
builder.field(WEIGHT, weight);
builder.endObject();
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ protected <T> T get(final Class<T> clazz, final String sessionId, final String u
}

protected <T> List<T> getList(final Class<T> clazz, final String sessionId, final QueryBuilder queryBuilder, final Integer from,
final Integer size, final SortBuilder<?> sortBuilder) {
final Integer size, final SortBuilder<?>... sortBuilders) {
return getList(clazz, builder -> {
if (StringUtil.isNotBlank(sessionId)) {
if (queryBuilder instanceof BoolQueryBuilder) {
Expand All @@ -370,8 +370,10 @@ protected <T> List<T> getList(final Class<T> clazz, final String sessionId, fina
} else {
builder.setQuery(QueryBuilders.matchAllQuery());
}
if (sortBuilder != null) {
builder.addSort(sortBuilder);
if (sortBuilders != null) {
for (SortBuilder<?> sortBuilder : sortBuilders) {
builder.addSort(sortBuilder);
}
}
if (from != null) {
builder.setFrom(from);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ public EsUrlQueue poll(final String sessionId) {
}

protected List<EsUrlQueue> fetchUrlQueueList(final String sessionId) {
return getList(EsUrlQueue.class, sessionId, null, 0, pollingFetchSize, SortBuilders.fieldSort(CREATE_TIME).order(SortOrder.ASC));
return getList(EsUrlQueue.class, sessionId, null, 0, pollingFetchSize,
SortBuilders.fieldSort(EsUrlQueue.WEIGHT).order(SortOrder.DESC), SortBuilders.fieldSort(CREATE_TIME).order(SortOrder.ASC));
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions fess-crawler-es/src/main/resources/mapping/queue.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"method": {
"type": "keyword"
},
"weight": {
"type": "float"
},
"createTime": {
"type": "long"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ public interface UrlQueue<IDTYPE> {

void setCreateTime(Long createTime);

float getWeight();

void setWeight(float weight);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class UrlQueueImpl<IDTYPE> implements UrlQueue<IDTYPE> {

protected Long createTime;

protected float weight = 1.0f;

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -220,6 +222,16 @@ public void setLastModified(final Long lastModified) {
this.lastModified = lastModified;
}

@Override
public float getWeight() {
return weight;
}

@Override
public void setWeight(float weight) {
this.weight = weight;
}

@Override
public String toString() {
return "UrlQueueImpl [id=" + id + ", sessionId=" + sessionId + ", method=" + method + ", url=" + url + ", encoding=" + encoding
Expand Down

0 comments on commit 8013500

Please sign in to comment.