Skip to content

Commit

Permalink
fix: tweet screen name & url author use TextField
Browse files Browse the repository at this point in the history
  • Loading branch information
lcomplete committed Apr 28, 2023
1 parent 3b83ad7 commit efee88e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ private Page getPageFromTweetDetail(String category, TweetsRoot.Result tweetResu
TweetProperties tweetProperties = getTweetProperties(user, tweetResult, views, quotedTweet);
var tweet = tweetResult.legacy;

var realTweet = tweetProperties.getRetweetedTweet() != null ? tweetProperties.getRetweetedTweet() : tweetProperties;

var page = new Page();
page.setCategory(category);
page.setContent(tweetProperties.getFullText());
page.setUrl(tweetProperties.getUrl());
page.setAuthor(user.name);
page.setAuthor(realTweet.getUserName());
page.setAuthorScreenName(realTweet.getUserScreeName());
page.setContentType(isFromQuote ? ContentType.QUOTED_TWEET.getCode() : ContentType.TWEET.getCode());
page.setLanguage(tweet.lang);
page.setPageUniqueId(tweetProperties.getTweetIdStr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ public class DocFields {
public static final String LIBRARY_SAVE_STATUS = "librarySaveStatus";
public static final String STARRED = "starred";
public static final String READ_LATER = "readLater";
@Deprecated
public static final String URL = "url";
public static final String URL_TEXT = "url_text";
public static final String THUMB_URL = "thumbUrl";
public static final String PAGE_JSON_PROPERTIES= "pageJsonProperties";
public static final String CONTENT_TYPE = "contentType";

public static final String AUTHOR = "author";
public static final String AUTHOR = "author_text";
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class Page implements Serializable {

@Column(name = "author")
private String author;

@Column(name = "author_screen_name")
private String authorScreenName;

@Column(name = "language")
private String language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public Page saveTweetPage(Page page, String loginScreenName, String browserScree
var currentPage = existPage.get();
currentPage.setContent(page.getContent());
currentPage.setAuthor(page.getAuthor());
currentPage.setAuthorScreenName(page.getAuthorScreenName());
currentPage.setContentType(page.getContentType());
currentPage.setPageJsonProperties(page.getPageJsonProperties());
currentPage.setCategory(page.getCategory());
Expand All @@ -123,7 +124,7 @@ public Page saveTweetPage(Page page, String loginScreenName, String browserScree
page.setCreatedAt(Instant.now());
}
// tweet auto save
String toUseScreenName = page.getAuthor();
String toUseScreenName = page.getAuthorScreenName();
if (Objects.equals(page.getCategory(), "like") && StringUtils.isNotBlank(browserScreenName)) {
toUseScreenName = browserScreenName;
} else if (Objects.equals(page.getCategory(), "bookmark") && StringUtils.isNotBlank(loginScreenName)) {
Expand All @@ -138,7 +139,7 @@ public Page saveTweetPage(Page page, String loginScreenName, String browserScree
} else if (Objects.equals(page.getCategory(), "like")) {
saveTypes.add(setting.getLikeToLibraryType());
}
if (Objects.equals(page.getAuthor(), setting.getScreenName())) {
if (Objects.equals(page.getAuthorScreenName(), setting.getScreenName())) {
saveTypes.add(setting.getTweetToLibraryType());
}
for (Integer saveType : saveTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ private Document pageToDocument(Page page) {
doc.add(new TextField(DocFields.CONTENT, HtmlUtils.getDocText(page.getContent()), Field.Store.YES));
}
if (StringUtils.isNotBlank(page.getAuthor())) {
doc.add(new StringField(DocFields.AUTHOR, page.getAuthor(), Field.Store.YES));
doc.add(new TextField(DocFields.AUTHOR, page.getAuthor(), Field.Store.YES));
}
if (StringUtils.isNotBlank(page.getUrl())) {
doc.add(new StringField(DocFields.URL, page.getUrl(), Field.Store.YES));
doc.add(new TextField(DocFields.URL_TEXT, page.getUrl(), Field.Store.YES));
}
if (StringUtils.isNotBlank(page.getThumbUrl())) {
doc.add(new StoredField(DocFields.THUMB_URL, page.getThumbUrl()));
Expand Down Expand Up @@ -214,7 +214,10 @@ private PageItem docToPageItem(Document doc) {
if (doc.getField(DocFields.DESCRIPTION) != null) {
item.setDescription(doc.get(DocFields.DESCRIPTION));
}
if (doc.getField(DocFields.URL) != null) {
if (doc.getField(DocFields.URL_TEXT) != null) {
item.setUrl(doc.get(DocFields.URL_TEXT));
}
else if (doc.getField(DocFields.URL) != null) {
item.setUrl(doc.get(DocFields.URL));
}
if (doc.getField(DocFields.AUTHOR) != null) {
Expand Down Expand Up @@ -395,7 +398,7 @@ private CompleteSearch extractCompleteSearch(String keyword) {
continue;
}
if (key.startsWith("url:")) {
completeSearch.advancedSearches.add(extractAdvancedSearch(key, DocFields.URL, ":"));
completeSearch.advancedSearches.add(extractAdvancedSearch(key, DocFields.URL_TEXT, ":"));
} else if (key.startsWith("author:")) {
completeSearch.advancedSearches.add(extractAdvancedSearch(key, DocFields.AUTHOR, ":"));
} else {
Expand Down

0 comments on commit efee88e

Please sign in to comment.