<commit_before><template lang="pug">
div(v-show="panel")
</template>

<script>
import {createPoint, createBounds} from '@/base/factory.js'
import {isPoint} from '@/base/util.js'
import commonMixin from '@/base/mixins/common.js'

export default {
  name: 'bm-local-search',
  mixins: [commonMixin('search')],
  props: {
    location: {
      type: [Object, String]
    },
    keyword: {
      type: [Array, String]
    },
    panel: {
      type: Boolean,
      default: true
    },
    forceLocal: {
      type: Boolean
    },
    customData: {
      type: Object
    },
    bounds: {
      type: Object
    },
    nearby: {
      type: Object
    },
    // page: {
    //   type: Number
    // },
    pageCapacity: {
      type: Number
    },
    autoViewport: {
      type: Boolean
    },
    selectFirstResult: {
      type: Boolean
    }
  },
  watch: {
    location: {
      handler (val) {
        this.originInstance.setLocation(val || this.map)
      },
      deep: true
    },
    keyword (val) {
      const {originInstance, forceLocal, customData} = this
      originInstance && originInstance.search(val, {
        forceLocal,
        customData
      })
    },
    bounds: {
      handler (val) {
        const {searchInBounds} = this
        searchInBounds(val)
      },
      deep: true
    },
    nearby: {
      handler (val) {
        const {searchNearby} = this
        searchNearby(val)
      },
      deep: true
    },
    forceLocal () {
      this.reload()
    },
    customData: {
      deep: true,
      handler () {
        this.reload()
      }
    },
    // panel () {
    //   this.reload()
    // },
    pageCapacity (val) {
      this.originInstance && this.originInstance.setPageCapacity(val)
    },
    autoViewport (val) {
      this.originInstance && (val ? this.originInstance.enableAutoViewport() : this.originInstance.disableAutoViewport())
    },
    selectFirstResult (val) {
      this.originInstance && (val ? this.originInstance.enableFirstResultSelection() : this.originInstance.disableFirstResultSelection())
    },
    highlightMode () {
      this.reload()
    }
  },
  methods: {
    searchNearby (nearby) {
      const {originInstance, keyword, customData, BMap} = this
      originInstance.searchNearby(keyword, createPoint(BMap, nearby.center), nearby.radius, customData)
    },
    searchInBounds (bounds) {
      const {originInstance, keyword, customData, BMap} = this
      originInstance.searchInBounds(keyword, createBounds(BMap, bounds), customData)
    },
    search () {
      const {originInstance, keyword, forceLocal, customData} = this
      originInstance.search(keyword, {
        forceLocal,
        customData
      })
    },
    load () {
      const instance = this
      const {map, BMap, search, pageCapacity, autoViewport, selectFirstResult, highlightMode, location, bounds, searchInBounds, nearby, searchNearby} = this
      const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
      this.originInstance = new BMap.LocalSearch(_location, {
        onMarkersSet (e) {
          instance.$emit('markersset', e)
        },
        onInfoHtmlSet (e) {
          instance.$emit('infohtmlset', e)
        },
        onResultsHtmlSet (e) {
          instance.$emit('resultshtmlset', e)
        },
        onSearchComplete (e) {
          instance.$emit('searchcomplete', e)
        },
        pageCapacity: pageCapacity,
        renderOptions: {
          map,
          // panel: panel && this.$el,
          panel: this.$el,
          selectFirstResult,
          autoViewport,
          highlightMode
        }
      })
      nearby ? searchNearby(nearby) : bounds ? searchInBounds(bounds) : search()
    }
  }
}
</script>
<commit_msg>Fixed bug of local search<commit_after><template lang="pug">
div(v-show="panel")
</template>

<script>
import {createPoint, createBounds} from '@/base/factory.js'
import {isPoint} from '@/base/util.js'
import commonMixin from '@/base/mixins/common.js'

export default {
  name: 'bm-local-search',
  mixins: [commonMixin('search')],
  props: {
    location: {
      type: [Object, String]
    },
    keyword: {
      type: [Array, String]
    },
    panel: {
      type: Boolean,
      default: true
    },
    forceLocal: {
      type: Boolean
    },
    customData: {
      type: Object
    },
    bounds: {
      type: Object
    },
    nearby: {
      type: Object
    },
    // page: {
    //   type: Number
    // },
    pageCapacity: {
      type: Number
    },
    autoViewport: {
      type: Boolean
    },
    selectFirstResult: {
      type: Boolean
    }
  },
  watch: {
    location: {
      handler (val) {
        const {originInstance, search} = this
        originInstance.setLocation(val || this.map)
        search()
      },
      deep: true
    },
    keyword (val) {
      const {originInstance, forceLocal, customData} = this
      originInstance && originInstance.search(val, {
        forceLocal,
        customData
      })
    },
    bounds: {
      handler (val) {
        const {searchInBounds} = this
        searchInBounds(val)
      },
      deep: true
    },
    nearby: {
      handler (val) {
        const {searchNearby} = this
        searchNearby(val)
      },
      deep: true
    },
    forceLocal () {
      this.reload()
    },
    customData: {
      deep: true,
      handler () {
        this.reload()
      }
    },
    // panel () {
    //   this.reload()
    // },
    pageCapacity (val) {
      this.originInstance && this.originInstance.setPageCapacity(val)
    },
    autoViewport (val) {
      this.originInstance && (val ? this.originInstance.enableAutoViewport() : this.originInstance.disableAutoViewport())
    },
    selectFirstResult (val) {
      this.originInstance && (val ? this.originInstance.enableFirstResultSelection() : this.originInstance.disableFirstResultSelection())
    },
    highlightMode () {
      this.reload()
    }
  },
  methods: {
    searchNearby (nearby) {
      const {originInstance, keyword, customData, BMap} = this
      originInstance.searchNearby(keyword, createPoint(BMap, nearby.center), nearby.radius, customData)
    },
    searchInBounds (bounds) {
      const {originInstance, keyword, customData, BMap} = this
      originInstance.searchInBounds(keyword, createBounds(BMap, bounds), customData)
    },
    search () {
      const {originInstance, keyword, forceLocal, customData, nearby, bounds, searchNearby, searchInBounds} = this
      nearby ? searchNearby(nearby) : bounds ? searchInBounds(bounds) : originInstance.search(keyword, {
        forceLocal,
        customData
      })
    },
    load () {
      const instance = this
      const {map, BMap, search, pageCapacity, autoViewport, selectFirstResult, highlightMode, location} = this
      const _location = location ? isPoint(location) ? createPoint(BMap, location) : location : map
      this.originInstance = new BMap.LocalSearch(_location, {
        onMarkersSet (e) {
          instance.$emit('markersset', e)
        },
        onInfoHtmlSet (e) {
          instance.$emit('infohtmlset', e)
        },
        onResultsHtmlSet (e) {
          instance.$emit('resultshtmlset', e)
        },
        onSearchComplete (e) {
          instance.$emit('searchcomplete', e)
        },
        pageCapacity: pageCapacity,
        renderOptions: {
          map,
          // panel: panel && this.$el,
          panel: this.$el,
          selectFirstResult,
          autoViewport,
          highlightMode
        }
      })
      search()
    }
  }
}
</script>

{'fraction_non_alphanumeric': 0.12628934144406243, 'fraction_numerical': 0.0, 'mean_word_length': 2.161789297658863, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6481564', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2237, 'n_words': 459}