Skip to content

Commit

Permalink
feat: query_popularity plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Nov 4, 2023
1 parent f803776 commit 27ef0c4
Show file tree
Hide file tree
Showing 33 changed files with 588 additions and 296 deletions.
130 changes: 124 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,132 @@
# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
All notable changes to this project will be documented in this file.

## [0.5.0](https://github.com/DataShades/ckanext-search-tweaks/compare/v0.4.12...v0.5.0) (2023-05-30)
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- insertion marker -->
## [v0.5.0](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.5.0) - 2023-05-30

### ⚠ BREAKING CHANGES

* CKAN v2.10 support
<small>[Compare with v0.4.12](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.4.12...v0.5.0)</small>

### Features

* CKAN v2.10 support ([1e48497](https://github.com/DataShades/ckanext-search-tweaks/commit/1e48497301ea2fe488709b08958c427c7c63c79d))
- CKAN v2.10 support ([1e48497](https://github.com/dataShades/ckanext-search-tweaks/commit/1e48497301ea2fe488709b08958c427c7c63c79d) by Sergey Motornyuk).

## [v0.4.12](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.4.12) - 2023-03-16

<small>[Compare with v0.3.10](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.10...v0.4.12)</small>

## [v0.3.10](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.10) - 2021-11-08

<small>[Compare with v0.3.8](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.8...v0.3.10)</small>

## [v0.3.8](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.8) - 2021-09-13

<small>[Compare with v0.3.7](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.7...v0.3.8)</small>

## [v0.3.7](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.7) - 2021-08-19

<small>[Compare with v0.3.6](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.6...v0.3.7)</small>

## [v0.3.6](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.6) - 2021-08-16

<small>[Compare with v0.3.4](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.4...v0.3.6)</small>

## [v0.3.4](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.4) - 2021-08-16

<small>[Compare with v0.3.3](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.3...v0.3.4)</small>

## [v0.3.3](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.3) - 2021-08-13

<small>[Compare with v0.3.2](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.2...v0.3.3)</small>

## [v0.3.2](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.2) - 2021-08-11

<small>[Compare with v0.3.1](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.1...v0.3.2)</small>

## [v0.3.1](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.1) - 2021-07-19

<small>[Compare with v0.3.0](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.3.0...v0.3.1)</small>

## [v0.3.0](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.3.0) - 2021-07-09

<small>[Compare with v0.2.8](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.8...v0.3.0)</small>

## [v0.2.8](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.8) - 2021-07-05

<small>[Compare with v0.2.7](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.7...v0.2.8)</small>

## [v0.2.7](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.7) - 2021-07-01

<small>[Compare with v0.2.6](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.6...v0.2.7)</small>

## [v0.2.6](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.6) - 2021-06-30

<small>[Compare with v0.2.5](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.5...v0.2.6)</small>

## [v0.2.5](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.5) - 2021-06-24

<small>[Compare with v0.2.4](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.4...v0.2.5)</small>

## [v0.2.4](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.4) - 2021-06-24

<small>[Compare with v0.2.3](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.3...v0.2.4)</small>

## [v0.2.3](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.3) - 2021-06-24

<small>[Compare with v0.2.2](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.2...v0.2.3)</small>

## [v0.2.2](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.2) - 2021-06-24

<small>[Compare with v0.2.1](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.1...v0.2.2)</small>

## [v0.2.1](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.1) - 2021-06-21

<small>[Compare with v0.2.0](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.2.0...v0.2.1)</small>

## [v0.2.0](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.2.0) - 2021-06-21

<small>[Compare with v0.1.7](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.7...v0.2.0)</small>

## [v0.1.7](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.7) - 2021-06-18

<small>[Compare with v0.1.6](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.6...v0.1.7)</small>

## [v0.1.6](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.6) - 2021-06-16

<small>[Compare with v0.1.5](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.5...v0.1.6)</small>

## [v0.1.5](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.5) - 2021-06-16

<small>[Compare with v0.1.4](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.4...v0.1.5)</small>

## [v0.1.4](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.4) - 2021-06-16

<small>[Compare with v0.1.3](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.3...v0.1.4)</small>

## [v0.1.3](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.3) - 2021-06-16

<small>[Compare with v0.1.2](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.2...v0.1.3)</small>

## [v0.1.2](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.2) - 2021-06-16

<small>[Compare with v0.1.1](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.1...v0.1.2)</small>

## [v0.1.1](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.1) - 2021-06-16

<small>[Compare with v0.1.0](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.1.0...v0.1.1)</small>

## [v0.1.0](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.1.0) - 2021-06-15

<small>[Compare with v0.0.2](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.0.2...v0.1.0)</small>

## [v0.0.2](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.0.2) - 2021-06-11

<small>[Compare with v0.0.1](https://github.com/dataShades/ckanext-search-tweaks/compare/v0.0.1...v0.0.2)</small>

## [v0.0.1](https://github.com/dataShades/ckanext-search-tweaks/releases/tag/v0.0.1) - 2021-06-11

<small>[Compare with first commit](https://github.com/dataShades/ckanext-search-tweaks/compare/990e2ae0dd6781a4d32d2bda6929c5ce11975703...v0.0.1)</small>

48 changes: 0 additions & 48 deletions CHANGELOG.rst

This file was deleted.

9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DEFAULT_GOAL := help
.PHONY = help

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'


changelog: ## compile changelog
git changelog -c conventional -o CHANGELOG.md
1 change: 0 additions & 1 deletion ckanext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8

# this is a namespace package
try:
Expand Down
18 changes: 1 addition & 17 deletions ckanext/search_tweaks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
from __future__ import annotations

from typing import Any
import ckan.plugins.toolkit as tk

CONFIG_PREFER_BOOST = "ckanext.search_tweaks.common.prefer_boost"
DEFAULT_PREFER_BOOST = True


def boost_preffered() -> bool:
return tk.asbool(tk.config.get(CONFIG_PREFER_BOOST, DEFAULT_PREFER_BOOST))


def feature_disabled(feature: str, search_params: dict[str, Any]) -> bool:
return tk.asbool(
search_params.get("extras", {}).get(
f"ext_search_tweaks_disable_{feature}", False
)
)
from .shared import feature_disabled
6 changes: 3 additions & 3 deletions ckanext/search_tweaks/advanced_search/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
{"value": "private", "label": "Private"},
],
},
}
},
)
DEFAULT_FIELD_ORDER = None


def form_config():
definition = json.loads(
tk.config.get(CONFIG_FORM_DEFINITION, DEFAULT_FORM_DEFINITION)
tk.config.get(CONFIG_FORM_DEFINITION, DEFAULT_FORM_DEFINITION),
)
order = tk.aslist(tk.config.get(CONFIG_FIELD_ORDER, DEFAULT_FIELD_ORDER))
if not order:
Expand Down Expand Up @@ -74,7 +74,7 @@ def configure(self, config):
from ckanext.composite_search.interfaces import ICompositeSearch
except ImportError:
raise CkanConfigurationException(
"ckanext-composite-search is not installed"
"ckanext-composite-search is not installed",
)
if not p.plugin_loaded("composite_search"):
msg = "Advanced search requires `composite_search` plugin"
Expand Down
6 changes: 3 additions & 3 deletions ckanext/search_tweaks/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import click


def get_commands():
return [search_tweaks]
__all__ = [
"search_tweaks",
]


@click.group(short_help="Search tweaks")
Expand Down
37 changes: 37 additions & 0 deletions ckanext/search_tweaks/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import ckan.plugins.toolkit as tk
from ckan.lib.search.query import QUERY_FIELDS

CONFIG_QF = "ckanext.search_tweaks.common.qf"
DEFAULT_QF = QUERY_FIELDS

CONFIG_FUZZY = "ckanext.search_tweaks.common.fuzzy_search.enabled"
CONFIG_FUZZY_DISTANCE = "ckanext.search_tweaks.common.fuzzy_search.distance"
CONFIG_MM = "ckanext.search_tweaks.common.mm"
CONFIG_FUZZY_KEEP_ORIGINAL = "ckanext.search_tweaks.common.fuzzy_search.keep_original"
CONFIG_PREFER_BOOST = "ckanext.search_tweaks.common.prefer_boost"


def qf() -> str:
return tk.config[CONFIG_QF] or DEFAULT_QF


def fuzzy() -> bool:
return tk.config[CONFIG_FUZZY]


def fuzzy_distance() -> int:
return tk.config[CONFIG_FUZZY_DISTANCE]


def mm() -> str:
return tk.config[CONFIG_MM]


def fuzzy_with_original() -> bool:
return tk.config[CONFIG_FUZZY_KEEP_ORIGINAL]


def prefer_boost() -> bool:
return tk.config[CONFIG_PREFER_BOOST]
24 changes: 24 additions & 0 deletions ckanext/search_tweaks/config_declaration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 1
groups:
- annotation: "ckanext-search-tweaks: common"
options:
- key: ckanext.search_tweaks.common.qf
placeholder: "name^4 title^4 tags^2 groups^2 text"

- key: ckanext.search_tweaks.common.mm
default: "1"

- key: ckanext.search_tweaks.common.fuzzy_search.enabled
type: bool

- key: ckanext.search_tweaks.common.fuzzy_search.distance
type: int
default: 1

- key: ckanext.search_tweaks.common.fuzzy_search.keep_original
type: bool
default: true

- key: ckanext.search_tweaks.common.prefer_boost
type: bool
default: true
6 changes: 3 additions & 3 deletions ckanext/search_tweaks/field_relevance/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ckan.plugins as p
import ckan.plugins.toolkit as tk

from .. import feature_disabled
from ..interfaces import ISearchTweaks
from ckanext.search_tweaks import feature_disabled
from ckanext.search_tweaks.interfaces import ISearchTweaks
from . import views

CONFIG_BOOST_FN = "ckanext.search_tweaks.field_relevance.boost_function"
Expand All @@ -23,7 +23,7 @@ class FieldRelevancePlugin(p.SingletonPlugin):
# ISearchTweaks
def get_search_boost_fn(self, search_params: dict[str, Any]) -> str | None:
if feature_disabled("field_boost", search_params):
return
return None

return tk.config.get(CONFIG_BOOST_FN, DEFAULT_BOOST_FN)

Expand Down
Loading

0 comments on commit 27ef0c4

Please sign in to comment.