1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 19:08:21 +00:00

12.0 integrate filename seasearch (#6412)

* seafevents integrate filename seasearch

* feat: integrate filename seasearch

* control seasearch open and close at seafevents conf

* fix post redundant api

* feat/seasearch: change seasearch control option

* cancel seasearch url verify

* fix bug

* add es search control  field

* delete redundant seafile ai code

* update

---------

Co-authored-by: ‘JoinTyang’ <yangtong1009@163.com>
This commit is contained in:
cir9no
2024-07-25 14:17:24 +08:00
committed by GitHub
parent 113a88d850
commit 24ad6cda3e
14 changed files with 48 additions and 469 deletions

View File

@@ -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 (
<Switch
checked={true}
placeholder={gettext('Turn on semantic search for this library')}
className="position-absolute p-4 bg-white border rounded shadow-sm search-settings"
size="small"
textPosition='right'
disabled={true}
setRef={this.setSettingsContainerRef}
/>
);
} else if (indexState === INDEX_STATE.FINISHED) {
return (
<Switch
checked={true}
placeholder={gettext('Turn off semantic search for this library')}
className="position-absolute p-4 bg-white border rounded shadow-sm search-settings"
size="small"
onChange={this.onDeleteIndex}
textPosition='right'
setRef={this.setSettingsContainerRef}
/>
);
} else if (indexState === '' || indexState === INDEX_STATE.UNCREATED) {
return (
<Switch
checked={false}
placeholder={gettext('Turn on semantic search for this library')}
className="position-absolute p-4 bg-white border rounded shadow-sm search-settings"
size="small"
onChange={this.onCreateIndex}
textPosition='right'
setRef={this.setSettingsContainerRef}
/>
);
}
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 {
</>
}
</div>
{this.state.isSettingsShown && this.renderSwitch()}
<div
className="search-result-container dropdown-search-result-container"
onScroll={this.onResultListScroll}

View File

@@ -303,6 +303,7 @@ class Search 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,
@@ -311,7 +312,7 @@ class Search extends Component {
// resultItems: [],
isResultGetted: false,
}, () => {
if (trimmedValue !== '') {
if (!isInRepo && trimmedValue !== '') {
this.getRepoSearchResult(newValue);
}
});

View File

@@ -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 (
<AISearch
repoID={repoID}