diff --git a/frontend/src/components/search/ai-search.js b/frontend/src/components/search/ai-search.js
index 9f98f547f5..4cccf547f4 100644
--- a/frontend/src/components/search/ai-search.js
+++ b/frontend/src/components/search/ai-search.js
@@ -8,11 +8,8 @@ import Icon from '../icon';
import { gettext, siteRoot, username } from '../../utils/constants';
import SearchResultItem from './search-result-item';
import SearchResultLibrary from './search-result-library';
-import { Utils } from '../../utils/utils';
import { isMac } from '../../utils/extra-attributes';
-import toaster from '../toast';
import Loading from '../loading';
-import Switch from '../common/switch';
const INDEX_STATE = {
RUNNING: 'running',
@@ -51,7 +48,6 @@ export default class AISearch extends Component {
showRecent: true,
isResultGetted: false,
isCloseShow: false,
- isSettingsShown: false,
isSearchInputShow: false, // for mobile
searchPageUrl: this.baseSearchPageURL,
indexState: '',
@@ -74,27 +70,6 @@ export default class AISearch extends Component {
document.addEventListener('compositionstart', this.onCompositionStart);
document.addEventListener('compositionend', this.onCompositionEnd);
document.addEventListener('click', this.handleOutsideClick);
- if (this.props.isLibView) {
- this.queryLibraryIndexState(this.props.repoID);
- }
- }
-
- UNSAFE_componentWillReceiveProps(nextProps) {
- this.calculateStoreKey(nextProps);
- if (nextProps.isLibView) {
- if (this.props.repoID !== nextProps.repoID) {
- this.queryLibraryIndexState(nextProps.repoID);
- }
- } else {
- if (this.indexStateTimer) {
- clearInterval(this.indexStateTimer);
- this.indexStateTimer = null;
- }
- this.isChineseInput = false;
- this.setState({
- indexState: '',
- });
- }
}
calculateStoreKey = (props) => {
@@ -112,19 +87,6 @@ export default class AISearch extends Component {
this.storeKey = storeKey;
};
- queryLibraryIndexState(repoID) {
- seafileAPI.queryLibraryIndexState(repoID).then(res => {
- const { state: indexState, task_id: taskId } = res.data;
- this.setState({ indexState }, () => {
- if (indexState === INDEX_STATE.RUNNING) {
- this.queryIndexTaskStatus(taskId);
- }
- });
- }).catch(error => {
- this.setState({ indexState: INDEX_STATE.UNCREATED });
- });
- }
-
componentWillUnmount() {
document.removeEventListener('keydown', this.onDocumentKeydown);
document.removeEventListener('compositionstart', this.onCompositionStart);
@@ -354,6 +316,7 @@ export default class AISearch extends Component {
this.setState({ value: newValue });
setTimeout(() => {
const trimmedValue = newValue.trim();
+ const isInRepo = this.props.repoID;
if (this.isChineseInput === false && this.state.inputValue !== newValue) {
this.setState({
inputValue: newValue,
@@ -362,7 +325,7 @@ export default class AISearch extends Component {
// resultItems: [],
isResultGetted: false,
}, () => {
- if (trimmedValue !== '') {
+ if (!isInRepo && trimmedValue !== '') {
this.getRepoSearchResult(newValue);
}
});
@@ -479,7 +442,6 @@ export default class AISearch extends Component {
inputValue: '',
isMaskShow: false,
isCloseShow: false,
- isSettingsShown: false,
isResultGetted: false,
resultItems: [],
highlightIndex: 0,
@@ -699,95 +661,10 @@ export default class AISearch extends Component {
});
};
- queryIndexTaskStatus = (taskId) => {
- if (!taskId) return;
- this.indexStateTimer = setInterval(() => {
- seafileAPI.queryIndexTaskStatus(taskId).then(res => {
- const isFinished = res.data.is_finished;
- if (isFinished) {
- this.setState({ indexState: INDEX_STATE.FINISHED });
- this.indexStateTimer && clearInterval(this.indexStateTimer);
- this.indexStateTimer = null;
- }
- }).catch(error => {
- this.indexStateTimer && clearInterval(this.indexStateTimer);
- this.indexStateTimer = null;
- const errorMsg = Utils.getErrorMsg(error);
- toaster.danger(errorMsg);
- this.setState({ indexState: INDEX_STATE.UNCREATED });
- });
- }, 3000);
- };
-
- onCreateIndex = () => {
- this.setState({ indexState: INDEX_STATE.RUNNING });
- seafileAPI.createLibraryIndex(this.props.repoID).then(res => {
- const taskId = res.data.task_id;
- toaster.notify(gettext('Indexing the library. Semantic search will be available within a few minutes.'));
- this.queryIndexTaskStatus(taskId);
- }).catch(error => {
- const errorMsg = Utils.getErrorMsg(error);
- toaster.danger(errorMsg);
- this.setState({ indexState: INDEX_STATE.UNCREATED });
- });
- };
-
- onDeleteIndex = () => {
- seafileAPI.deleteLibraryIndex(this.props.repoID).then(res => {
- toaster.notify(gettext('Successfully turned it off'));
- this.setState({ indexState: INDEX_STATE.UNCREATED });
- }).catch(error => {
- const errorMsg = Utils.getErrorMsg(error);
- toaster.danger(errorMsg);
- });
- };
-
setSettingsContainerRef = (ref) => {
this.settingsContainer = ref;
};
- renderSwitch = () => {
- const { indexState } = this.state;
- if (indexState === INDEX_STATE.RUNNING) {
- return (
-
- );
- } else if (indexState === INDEX_STATE.FINISHED) {
- return (
-
- );
- } else if (indexState === '' || indexState === INDEX_STATE.UNCREATED) {
- return (
-
- );
- }
- return null;
- };
-
renderSearchIcon = () => {
const { indexState } = this.state;
if (indexState === INDEX_STATE.RUNNING || indexState === INDEX_STATE.FINISHED) {
@@ -797,21 +674,6 @@ export default class AISearch extends Component {
}
};
- toggleSettingsShown = () => {
- this.setState({
- isSettingsShown: !this.state.isSettingsShown
- });
- };
-
- handleOutsideClick = (e) => {
- const { isSettingsShown } = this.state;
- if (isSettingsShown &&
- !this.settingsContainer.contains(e.target) &&
- !this.settingIcon.contains(e.target)) {
- this.toggleSettingsShown();
- }
- };
-
render() {
let width = this.state.width !== 'default' ? this.state.width : '';
let style = {'width': width};
@@ -858,7 +720,6 @@ export default class AISearch extends Component {
>
}
- {this.state.isSettingsShown && this.renderSwitch()}
{
const trimmedValue = newValue.trim();
+ const isInRepo = this.props.repoID;
if (this.isChineseInput === false && this.state.inputValue !== newValue) {
this.setState({
inputValue: newValue,
@@ -311,7 +312,7 @@ class Search extends Component {
// resultItems: [],
isResultGetted: false,
}, () => {
- if (trimmedValue !== '') {
+ if (!isInRepo && trimmedValue !== '') {
this.getRepoSearchResult(newValue);
}
});
diff --git a/frontend/src/components/toolbar/common-toolbar.js b/frontend/src/components/toolbar/common-toolbar.js
index d6cf249847..7f53f63fd0 100644
--- a/frontend/src/components/toolbar/common-toolbar.js
+++ b/frontend/src/components/toolbar/common-toolbar.js
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
-import { isPro, gettext, showLogoutIcon, enableSeafileAI } from '../../utils/constants';
+import { isPro, gettext, showLogoutIcon, enableSeasearch, enableElasticsearch } from '../../utils/constants';
import Search from '../search/search';
import AISearch from '../search/ai-search';
import SearchByName from '../search/search-by-name';
@@ -65,7 +65,7 @@ class CommonToolbar extends React.Component {
const placeholder = searchPlaceholder || gettext('Search files');
if (isPro) {
- if (enableSeafileAI) {
+ if (enableSeasearch && !enableElasticsearch) {
return (
current_page * per_page else False
return Response({"total":total, "results":results, "has_more":has_more})
- if ENABLE_SEAFILE_AI:
+ if HAS_FILE_SEASEARCH:
repos = [repo,]
searched_repos, repos_map = format_repos(repos)
count = per_page
diff --git a/seahub/settings.py b/seahub/settings.py
index f9741d4afd..25237a0a01 100644
--- a/seahub/settings.py
+++ b/seahub/settings.py
@@ -851,10 +851,6 @@ ENABLE_REPO_SNAPSHOT_LABEL = False
# Repo wiki mode
ENABLE_REPO_WIKI_MODE = True
-SEAFILE_AI_SECRET_KEY = ''
-SEAFILE_AI_SERVER_URL = ''
-ENABLE_SEAFILE_AI = False
-
############################
# HU berlin additional #
############################
@@ -917,6 +913,7 @@ del d
if not os.path.exists(EVENTS_CONFIG_FILE):
del EVENTS_CONFIG_FILE
+
#####################
# External settings #
#####################
diff --git a/seahub/templates/base_for_react.html b/seahub/templates/base_for_react.html
index ccd0365f64..9e43f74277 100644
--- a/seahub/templates/base_for_react.html
+++ b/seahub/templates/base_for_react.html
@@ -150,7 +150,8 @@
enableOnlyoffice: {% if enableOnlyoffice %} true {% else %} false {% endif %},
onlyofficeConverterExtensions: {% if onlyofficeConverterExtensions %} {{onlyofficeConverterExtensions|safe}} {% else %} null {% endif %},
enableSeadoc: {% if enable_seadoc %} true {% else %} false {% endif %},
- enableSeafileAI: {% if enable_seafile_ai %} true {% else %} false {% endif %},
+ enableElasticsearch: {% if enable_elasticsearch %} true {% else %} false {% endif %},
+ enableSeasearch: {% if enable_seasearch %} true {% else %} false {% endif %},
enableSeaTableIntegration: {% if enable_seatable_integration %} true {% else %} false {% endif %},
isOrgContext: {% if org is not None %} true {% else %} false {% endif %},
enableMetadataManagement: {% if enable_metadata_management %} true {% else %} false {% endif %},
diff --git a/seahub/urls.py b/seahub/urls.py
index b84c5390a3..0244164040 100644
--- a/seahub/urls.py
+++ b/seahub/urls.py
@@ -202,8 +202,7 @@ from seahub.api2.endpoints.repo_auto_delete import RepoAutoDeleteView
from seahub.seadoc.views import sdoc_revision, sdoc_revisions, sdoc_to_docx
from seahub.ocm.settings import OCM_ENDPOINT
-from seahub.ai.apis import LibrarySdocIndexes, Search, LibrarySdocIndex, TaskStatus, \
- LibraryIndexState, QuestionAnsweringSearchInLibrary, FileDownloadToken
+from seahub.ai.apis import Search
from seahub.wiki2.views import wiki_view
from seahub.api2.endpoints.wiki2 import Wikis2View, Wiki2View, Wiki2ConfigView, Wiki2PagesView, Wiki2PageView, Wiki2DuplicatePageView
from seahub.api2.endpoints.subscription import SubscriptionView, SubscriptionPlansView, SubscriptionLogsView
@@ -1006,16 +1005,10 @@ if getattr(settings, 'ENABLE_SEADOC', False):
re_path(r'^api/v2.1/seadoc/', include('seahub.seadoc.urls')),
]
-if settings.ENABLE_SEAFILE_AI:
- urlpatterns += [
- re_path(r'^api/v2.1/ai/library-sdoc-indexes/$', LibrarySdocIndexes.as_view(), name='api-v2.1-ai-library-sdoc-indexes'),
- re_path(r'^api/v2.1/ai/search/$', Search.as_view(), name='api-v2.1-ai-search'),
- re_path(r'^api/v2.1/ai/question-answering-search-in-library/$', QuestionAnsweringSearchInLibrary.as_view(), name='api-v2.1-ai-question-answering-search-in-library'),
- re_path(r'^api/v2.1/ai/library-sdoc-index/$', LibrarySdocIndex.as_view(), name='api-v2.1-ai-library-sdoc-index'),
- re_path(r'^api/v2.1/ai/task-status/$', TaskStatus.as_view(), name='api-v2.1-ai-task-status'),
- re_path(r'^api/v2.1/ai/library-index-state/$', LibraryIndexState.as_view(), name='api-v2.1-ai-library-index-state'),
- re_path(r'^api/v2.1/ai/repo/file-download-token/$', FileDownloadToken.as_view(), name='api-v2.1-ai-repo-file-download-token'),
- ]
+# Seasearch
+urlpatterns += [
+ re_path(r'^api/v2.1/ai/search/$', Search.as_view(), name='api-v2.1-ai-search'),
+]
if getattr(settings, 'CLIENT_SSO_VIA_LOCAL_BROWSER', False):
urlpatterns += [
diff --git a/seahub/utils/__init__.py b/seahub/utils/__init__.py
index 78926136a9..4998803bd1 100644
--- a/seahub/utils/__init__.py
+++ b/seahub/utils/__init__.py
@@ -1177,6 +1177,7 @@ if HAS_OFFICE_CONVERTER:
# search realted
HAS_FILE_SEARCH = False
+HAS_FILE_SEASEARCH = False
if EVENTS_CONFIG_FILE:
def check_search_enabled():
enabled = False
@@ -1188,8 +1189,15 @@ if EVENTS_CONFIG_FILE:
else:
logging.debug('search: not enabled')
return enabled
+
+ def check_seasearch_enabled():
+ enabled = False
+ if hasattr(seafevents_api, 'is_seasearch_enabled'):
+ enabled = seafevents_api.is_seasearch_enabled(parsed_events_conf)
+ return enabled
HAS_FILE_SEARCH = check_search_enabled()
+ HAS_FILE_SEASEARCH = check_seasearch_enabled()
# repo auto delete related
ENABLE_REPO_AUTO_DEL = False