Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/2387
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Aug 9, 2024
2 parents 78076b3 + 332f4f8 commit 2ba2ad9
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 85 deletions.
8 changes: 4 additions & 4 deletions api/src/main/java/run/halo/app/search/SearchOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ public class SearchOption {
private Boolean filterPublished;

/**
* Types to include. If null, it will include all types.
* Types to include(or). If null, it will include all types.
*/
private List<String> includeTypes;

/**
* Owner names to include. If null, it will include all owners.
* Owner names to include(or). If null, it will include all owners.
*/
private List<String> includeOwnerNames;

/**
* Category names to include. If null, it will include all categories.
* Category names to include(and). If null, it will include all categories.
*/
private List<String> includeCategoryNames;

/**
* Tag names to include. If null, it will include all tags.
* Tag names to include(and). If null, it will include all tags.
*/
private List<String> includeTagNames;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilterFactory;
Expand Down Expand Up @@ -170,6 +171,45 @@ public SearchResult search(SearchOption option) {
new TermQuery(new Term("published", filterPublished.toString())), FILTER
);
}

Optional.ofNullable(option.getIncludeTypes())
.filter(types -> !types.isEmpty())
.ifPresent(types -> {
var typeTerms = types.stream()
.distinct()
.map(BytesRef::new)
.toList();
queryBuilder.add(new TermInSetQuery("type", typeTerms), FILTER);
});

Optional.ofNullable(option.getIncludeOwnerNames())
.filter(ownerNames -> !ownerNames.isEmpty())
.ifPresent(ownerNames -> {
var ownerTerms = ownerNames.stream()
.distinct()
.map(BytesRef::new)
.toList();
queryBuilder.add(new TermInSetQuery("ownerName", ownerTerms), FILTER);
});

Optional.ofNullable(option.getIncludeTagNames())
.filter(tagNames -> !tagNames.isEmpty())
.ifPresent(tagNames -> tagNames
.stream()
.distinct()
.forEach(tagName ->
queryBuilder.add(new TermQuery(new Term("tag", tagName)), FILTER)
));

Optional.ofNullable(option.getIncludeCategoryNames())
.filter(categoryNames -> !categoryNames.isEmpty())
.ifPresent(categoryNames -> categoryNames
.stream()
.distinct()
.forEach(categoryName ->
queryBuilder.add(new TermQuery(new Term("category", categoryName)), FILTER)
));

var finalQuery = queryBuilder.build();
var limit = option.getLimit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static run.halo.app.core.extension.content.Post.VisibleEnum.PUBLIC;

import java.time.Duration;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -122,6 +123,9 @@ void assertNoResult(int maxAttempts) {
option.setKeyword("halo");
option.setHighlightPreTag("<my-tag>");
option.setHighlightPostTag("</my-tag>");
option.setIncludeTagNames(List.of("search"));
option.setIncludeCategoryNames(List.of("halo"));
option.setIncludeOwnerNames(List.of("admin"));
retryTemplate.execute(context -> {
webClient.post().uri("/apis/api.halo.run/v1alpha1/indices/-/search")
.bodyValue(option)
Expand Down Expand Up @@ -218,6 +222,8 @@ void createPost(String postName) {
spec.setPriority(0);
spec.setSlug("/first-post");
spec.setDeleted(false);
spec.setTags(List.of("search"));
spec.setCategories(List.of("halo"));
var excerpt = new Post.Excerpt();
excerpt.setRaw("first post description");
excerpt.setAutoGenerate(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import type {
SettingForm,
Theme,
} from "@halo-dev/api-client";
import { axiosInstance, consoleApiClient } from "@halo-dev/api-client";
import { consoleApiClient } from "@halo-dev/api-client";
import {
IconArrowLeft,
IconComputer,
IconLink,
IconPalette,
Expand All @@ -29,6 +28,7 @@ import { storeToRefs } from "pinia";
import { computed, markRaw, onMounted, ref, toRaw } from "vue";
import { useI18n } from "vue-i18n";
import ThemePreviewListItem from "./ThemePreviewListItem.vue";
import StickyBlock from "@/components/sticky-block/StickyBlock.vue";
const props = withDefaults(
defineProps<{
Expand All @@ -54,6 +54,7 @@ interface SettingTab {
const { activatedTheme } = storeToRefs(useThemeStore());
const previewFrame = ref<HTMLIFrameElement | null>(null);
const themesVisible = ref(false);
const switching = ref(false);
const selectedTheme = ref<Theme>();
Expand Down Expand Up @@ -99,26 +100,6 @@ const modalTitle = computed(() => {
});
});
const {
data: previewHTML,
isLoading,
refetch: refetchPreviewHTML,
} = useQuery({
queryKey: ["site-preview", previewUrl],
queryFn: async () => {
const { data } = await axiosInstance.get(previewUrl.value, {
headers: {
Accept: "text/html",
"Cache-Control": "no-cache",
Pragma: "no-cache",
Expires: "0",
},
});
return data;
},
enabled: computed(() => !!previewUrl.value),
});
// theme settings
const saving = ref(false);
const settingTabs = ref<SettingTab[]>([] as SettingTab[]);
Expand Down Expand Up @@ -169,6 +150,10 @@ const { formSchema, configMapFormData, convertToSave } = useSettingFormConvert(
activeSettingTab
);
const handleRefresh = () => {
previewFrame.value?.contentWindow?.location.reload();
};
const handleSaveConfigMap = async () => {
saving.value = true;
Expand All @@ -190,7 +175,7 @@ const handleSaveConfigMap = async () => {
saving.value = false;
refetchPreviewHTML();
handleRefresh();
};
const handleOpenSettings = (theme?: Theme) => {
Expand Down Expand Up @@ -271,7 +256,7 @@ const iframeClasses = computed(() => {
content: $t('core.common.buttons.refresh'),
delay: 300,
}"
@click="refetchPreviewHTML()"
@click="handleRefresh()"
>
<IconRefreshLine />
</span>
Expand Down Expand Up @@ -348,21 +333,23 @@ const iframeClasses = computed(() => {
/>
</FormKit>
</div>
<div v-permission="['system:themes:manage']" class="pt-5">
<div class="flex justify-start">
<VButton
:loading="saving"
type="secondary"
@click="
$formkit.submit(
`preview-setting-${activeSettingTab}` || ''
)
"
>
{{ $t("core.common.buttons.save") }}
</VButton>
</div>
</div>
<StickyBlock
v-permission="['system:themes:manage']"
class="-mx-4 -mb-4 -mr-3 rounded-b-base rounded-t-lg bg-white p-4 pt-5"
position="bottom"
>
<VButton
:loading="saving"
type="secondary"
@click="
$formkit.submit(
`preview-setting-${activeSettingTab}` || ''
)
"
>
{{ $t("core.common.buttons.save") }}
</VButton>
</StickyBlock>
</div>
</div>
</transition>
Expand Down Expand Up @@ -398,36 +385,18 @@ const iframeClasses = computed(() => {
</li>
</ul>
</transition>
<transition
enter-active-class="transform transition ease-in-out duration-300"
enter-from-class="translate-y-full"
enter-to-class="translate-y-0"
leave-active-class="transform transition ease-in-out duration-300"
leave-from-class="translate-y-0"
leave-to-class="translate-y-full"
>
<div v-if="settingsVisible" class="fixed bottom-2 left-2">
<VButton
size="md"
circle
type="primary"
@click="handleOpenThemes"
>
<IconArrowLeft />
</VButton>
</div>
</transition>
</OverlayScrollbarsComponent>
</transition>
<div
class="flex h-full flex-1 items-center justify-center transition-all duration-300"
>
<VLoading v-if="isLoading" />
<VLoading v-if="!previewUrl" />
<iframe
v-else
ref="previewFrame"
class="border-none transition-all duration-500"
:class="iframeClasses"
:srcdoc="previewHTML"
:src="previewUrl"
></iframe>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/editor/src/extensions/paragraph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function deleteCurrentNodeAndSetSelection(
const { tr } = state;
if (deleteNodeByPos($from)(tr) && dispatch) {
if (beforePos !== 0) {
tr.setSelection(TextSelection.create(tr.doc, beforePos - 1));
tr.setSelection(TextSelection.near(tr.doc.resolve(beforePos - 1), -1));
}
dispatch(tr);
return true;
Expand Down
22 changes: 2 additions & 20 deletions ui/src/components/preview/UrlPreviewModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts" setup>
import { axiosInstance } from "@halo-dev/api-client";
import {
IconComputer,
IconLink,
Expand All @@ -9,7 +8,6 @@ import {
VModal,
VTabbar,
} from "@halo-dev/components";
import { useQuery } from "@tanstack/vue-query";
import { computed, markRaw, ref, toRefs } from "vue";
const props = withDefaults(
Expand Down Expand Up @@ -54,22 +52,6 @@ const iframeClasses = computed(() => {
}
return "w-96 h-[50rem] ring-2 rounded ring-gray-300";
});
const { data: html, isLoading } = useQuery({
queryKey: ["url-preview", url],
queryFn: async () => {
const { data } = await axiosInstance.get(url.value, {
headers: {
Accept: "text/html",
"Cache-Control": "no-cache",
Pragma: "no-cache",
Expires: "0",
},
});
return data;
},
enabled: computed(() => !!url.value),
});
</script>
<template>
<VModal
Expand All @@ -96,12 +78,12 @@ const { data: html, isLoading } = useQuery({
</span>
</template>
<div class="flex h-full items-center justify-center">
<VLoading v-if="isLoading" />
<VLoading v-if="!url" />
<iframe
v-else
class="border-none transition-all duration-500"
:class="iframeClasses"
:srcdoc="html"
:src="url"
></iframe>
</div>
</VModal>
Expand Down

0 comments on commit 2ba2ad9

Please sign in to comment.