From efee88ec17707167e758fa8efe91c96d8995b00d Mon Sep 17 00:00:00 2001 From: lcomplete Date: Sat, 29 Apr 2023 02:08:34 +0800 Subject: [PATCH] fix: tweet screen name & url author use TextField --- .../huntly/server/connector/twitter/TweetParser.java | 5 ++++- .../com/huntly/server/domain/constant/DocFields.java | 5 +++-- .../java/com/huntly/server/domain/entity/Page.java | 3 +++ .../com/huntly/server/service/CapturePageService.java | 5 +++-- .../java/com/huntly/server/service/LuceneService.java | 11 +++++++---- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/connector/twitter/TweetParser.java b/app/server/huntly-server/src/main/java/com/huntly/server/connector/twitter/TweetParser.java index 8509172..7120d4e 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/connector/twitter/TweetParser.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/connector/twitter/TweetParser.java @@ -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()); diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/domain/constant/DocFields.java b/app/server/huntly-server/src/main/java/com/huntly/server/domain/constant/DocFields.java index 0d20415..d07cd7b 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/domain/constant/DocFields.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/domain/constant/DocFields.java @@ -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"; } diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/domain/entity/Page.java b/app/server/huntly-server/src/main/java/com/huntly/server/domain/entity/Page.java index d13da79..02b087b 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/domain/entity/Page.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/domain/entity/Page.java @@ -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; diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/service/CapturePageService.java b/app/server/huntly-server/src/main/java/com/huntly/server/service/CapturePageService.java index 0082e86..f451843 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/service/CapturePageService.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/service/CapturePageService.java @@ -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()); @@ -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)) { @@ -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) { diff --git a/app/server/huntly-server/src/main/java/com/huntly/server/service/LuceneService.java b/app/server/huntly-server/src/main/java/com/huntly/server/service/LuceneService.java index 8ba3a9b..db65ef8 100644 --- a/app/server/huntly-server/src/main/java/com/huntly/server/service/LuceneService.java +++ b/app/server/huntly-server/src/main/java/com/huntly/server/service/LuceneService.java @@ -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())); @@ -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) { @@ -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 {