فهرست منبع

Merge pull request #5072 from weseek/imprv/7608-elasticsearch-clean-code

imprv: clean up code
Yuki Takei 4 سال پیش
والد
کامیت
1becb59d08

+ 0 - 0
packages/app/resource/search/mappings.json → packages/app/resource/search/mappings-es6.json


+ 1 - 10
packages/app/src/components/SearchPage/SearchResult.jsx

@@ -285,15 +285,6 @@ class SearchResult extends React.Component {
 
     const listView = this.renderListView(this.props.pages);
 
-    let totalValue;
-
-    if (typeof this.props.searchResultMeta.total === 'string') {
-      totalValue = this.props.searchResultMeta.total; // elasticsearch V6
-    }
-    else {
-      totalValue = this.props.searchResultMeta.total.value; // elasticsearch v7
-    }
-
     /*
     UI あとで考える
     <span className="search-result-meta">Found: {this.props.searchResultMeta.total} pages with "{this.props.searchingKeyword}"</span>
@@ -305,7 +296,7 @@ class SearchResult extends React.Component {
             <nav>
               <div className="d-flex align-items-start justify-content-between mt-1">
                 <div className="search-result-meta">
-                  <i className="icon-magnifier" /> Found {totalValue} pages with &quot;{this.props.searchingKeyword}&quot;
+                  <i className="icon-magnifier" /> Found {this.props.searchResultMeta.total} pages with &quot;{this.props.searchingKeyword}&quot;
                 </div>
                 <div className="text-nowrap">
                   {deletionModeButtons}

+ 4 - 2
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -311,7 +311,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
   }
 
   async createIndex(index) {
-    const body = this.isElasticsearchV6 ? require('^/resource/search/mappings.json') : require('^/resource/search/mappings-es7.json');
+    const body = this.isElasticsearchV6 ? require('^/resource/search/mappings-es6.json') : require('^/resource/search/mappings-es7.json');
     return this.client.indices.create({ index, body });
   }
 
@@ -617,10 +617,12 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     // for debug
     logger.debug('ES result: ', result);
 
+    const totalValue = this.isElasticsearchV6 ? result.hits.total : result.hits.total.value;
+
     return {
       meta: {
         took: result.took,
-        total: result.hits.total,
+        total: totalValue,
         results: result.hits.hits.length,
       },
       data: result.hits.hits.map((elm) => {