mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-21 19:37:28 +00:00
all_repo_search_use_seasearch (#5832)
This commit is contained in:
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
import isHotkey from 'is-hotkey';
|
||||
import MediaQuery from 'react-responsive';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import { gettext, siteRoot } from '../../utils/constants';
|
||||
import { enableSeafileAI, gettext, siteRoot } from '../../utils/constants';
|
||||
import SearchResultItem from './search-result-item';
|
||||
import { Utils } from '../../utils/utils';
|
||||
import { isMac } from '../../utils/extra-attributes';
|
||||
@@ -280,10 +280,19 @@ class Search extends Component {
|
||||
this.setState({ isLoading: false });
|
||||
});
|
||||
} else {
|
||||
this.updateSearchPageURL(queryData);
|
||||
queryData['per_page'] = PER_PAGE;
|
||||
queryData['page'] = page;
|
||||
seafileAPI.searchFiles(queryData, cancelToken).then(res => {
|
||||
if (enableSeafileAI) {
|
||||
this.onAiSearch(queryData, cancelToken)
|
||||
} else {
|
||||
this.onNormalSearch(queryData, cancelToken, page)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onNormalSearch = (queryData, cancelToken, page) => {
|
||||
this.updateSearchPageURL(queryData);
|
||||
queryData['per_page'] = PER_PAGE;
|
||||
queryData['page'] = page;
|
||||
seafileAPI.searchFiles(queryData, cancelToken).then(res => {
|
||||
this.source = null;
|
||||
if (res.data.total > 0) {
|
||||
this.setState({
|
||||
@@ -307,7 +316,23 @@ class Search extends Component {
|
||||
console.log(error);
|
||||
this.setState({ isLoading: false });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onAiSearch = (params, cancelToken) => {
|
||||
let results = [];
|
||||
seafileAPI.aiSearchFiles(params, cancelToken).then(res => {
|
||||
results = [...results, ...this.formatResultItems(res.data.results)];
|
||||
this.setState({
|
||||
resultItems: results,
|
||||
isResultGetted: true,
|
||||
isLoading: false,
|
||||
hasMore: false,
|
||||
});
|
||||
}).catch(error => {
|
||||
/* eslint-disable */
|
||||
console.log(error);
|
||||
this.setState({ isLoading: false });
|
||||
});
|
||||
};
|
||||
|
||||
onResultListScroll = (e) => {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import deepCopy from 'deep-copy';
|
||||
import { gettext } from '../../utils/constants';
|
||||
import { gettext, enableSeafileAI } from '../../utils/constants';
|
||||
import { seafileAPI } from '../../utils/seafile-api';
|
||||
import SearchResults from './search-results';
|
||||
import AdvancedSearch from './advanced-search';
|
||||
@@ -49,6 +49,15 @@ class SearchViewPanel extends React.Component {
|
||||
isLoading: true,
|
||||
isResultGot: false,
|
||||
});
|
||||
|
||||
if (enableSeafileAI) {
|
||||
this.onAiSearch(params)
|
||||
} else {
|
||||
this.onNormalSearch(params);
|
||||
}
|
||||
}
|
||||
|
||||
onNormalSearch = (params) => {
|
||||
const stateHistory = deepCopy(this.state);
|
||||
seafileAPI.searchFiles(params, null).then(res => {
|
||||
const { results, has_more, total } = res.data;
|
||||
@@ -75,6 +84,24 @@ class SearchViewPanel extends React.Component {
|
||||
});
|
||||
}
|
||||
|
||||
onAiSearch = (params) => {
|
||||
let results = [];
|
||||
seafileAPI.aiSearchFiles(params, null).then(res => {
|
||||
results = [...results, ...this.formatResultItems(res.data.results)];
|
||||
this.setState({
|
||||
resultItems: results,
|
||||
isResultGetted: true,
|
||||
isLoading: false,
|
||||
hasMore: false,
|
||||
});
|
||||
}).catch(error => {
|
||||
/* eslint-disable */
|
||||
console.log(error);
|
||||
this.setState({ isLoading: false });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
handleSearchParams = (page) => {
|
||||
let params = { q: this.state.q.trim(), page: page };
|
||||
const ftype = this.getFileTypesList();
|
||||
|
Reference in New Issue
Block a user