From ce7e6f1b953d0febbf1be48cc4b2cccef4d27256 Mon Sep 17 00:00:00 2001 From: Alejandro Gil Date: Wed, 7 Feb 2024 07:44:46 -0700 Subject: [PATCH 1/3] Added --fix command to our ruff pre-commit hook. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5a19435c..2b76e1f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: rev: v0.2.1 hooks: - id: ruff - args: [ --select=I ] # isort + args: [ --select=I --fix] # isort - id: ruff-format - repo: https://github.com/asottile/pyupgrade From 5b5a2dd7211992999cd42a5535884f99cad3bcc5 Mon Sep 17 00:00:00 2001 From: Alejandro Gil Date: Wed, 7 Feb 2024 09:21:14 -0700 Subject: [PATCH 2/3] Changed the quickstart guide to avoid using star imports and instead import directly only what is needed. --- docs/source/quickstart.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst index 380252c7..b96361fc 100644 --- a/docs/source/quickstart.rst +++ b/docs/source/quickstart.rst @@ -14,7 +14,7 @@ A quick introduction :: >>> from whoosh.index import create_in - >>> from whoosh.fields import * + >>> from whoosh.fields import Schema, TEXT, ID >>> schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT) >>> ix = create_in("indexdir", schema) >>> writer = ix.writer() @@ -194,7 +194,7 @@ For example, this query would match documents that contain both "apple" and # Construct query objects directly - from whoosh.query import * + from whoosh.query import And, Term myquery = And([Term("content", u"apple"), Term("content", "bear")]) To parse a query string, you can use the default query parser in the ``qparser`` From c3e62bcdad63623ae8646a4b77f8fbbe41095edc Mon Sep 17 00:00:00 2001 From: Alejandro Gil Date: Wed, 7 Feb 2024 09:54:52 -0700 Subject: [PATCH 3/3] Fixed the tests that were failing due to cyclical errors. --- .pre-commit-config.yaml | 2 +- src/whoosh/analysis/__init__.py | 64 +++++++++++++++++++++++++++---- src/whoosh/matching/__init__.py | 39 +++++++++++++++++-- src/whoosh/qparser/__init__.py | 59 ++++++++++++++++++++++++++-- src/whoosh/query/__init__.py | 68 ++++++++++++++++++++++++++++----- src/whoosh/query/qcolumns.py | 2 +- src/whoosh/query/spans.py | 3 +- src/whoosh/writing.py | 2 +- tests/test_dateparse.py | 10 ++++- 9 files changed, 221 insertions(+), 28 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b76e1f1..5e96bc34 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,7 @@ repos: rev: v0.2.1 hooks: - id: ruff - args: [ --select=I --fix] # isort + args: [ --select=I, --fix] # isort - id: ruff-format - repo: https://github.com/asottile/pyupgrade diff --git a/src/whoosh/analysis/__init__.py b/src/whoosh/analysis/__init__.py index cce0ae43..0c116bf6 100644 --- a/src/whoosh/analysis/__init__.py +++ b/src/whoosh/analysis/__init__.py @@ -60,10 +60,60 @@ a filter first or a tokenizer after the first item). """ -from whoosh.analysis.acore import * -from whoosh.analysis.analyzers import * -from whoosh.analysis.filters import * -from whoosh.analysis.intraword import * -from whoosh.analysis.morph import * -from whoosh.analysis.ngrams import * -from whoosh.analysis.tokenizers import * +from whoosh.analysis.acore import ( + Composable, + CompositionError, + Token, + entoken, + unstopped, +) +from whoosh.analysis.analyzers import ( + Analyzer, + FancyAnalyzer, + IDAnalyzer, + KeywordAnalyzer, + LanguageAnalyzer, + RegexAnalyzer, + SimpleAnalyzer, + StandardAnalyzer, + StemmingAnalyzer, +) +from whoosh.analysis.filters import ( + STOP_WORDS, + CharsetFilter, + Composable, + DelimitedAttributeFilter, + Filter, + LoggingFilter, + LowercaseFilter, + MultiFilter, + PassFilter, + ReverseTextFilter, + StopFilter, + StripFilter, + SubstitutionFilter, + TeeFilter, + url_pattern, +) +from whoosh.analysis.intraword import ( + BiWordFilter, + CompoundWordFilter, + IntraWordFilter, + ShingleFilter, +) +from whoosh.analysis.morph import DoubleMetaphoneFilter, PyStemmerFilter, StemFilter +from whoosh.analysis.ngrams import ( + NgramAnalyzer, + NgramFilter, + NgramTokenizer, + NgramWordAnalyzer, +) +from whoosh.analysis.tokenizers import ( + CharsetTokenizer, + CommaSeparatedTokenizer, + IDTokenizer, + PathTokenizer, + RegexTokenizer, + SpaceSeparatedTokenizer, + Tokenizer, +) diff --git a/src/whoosh/matching/__init__.py b/src/whoosh/matching/__init__.py index e07a0320..e640bd61 100644 --- a/src/whoosh/matching/__init__.py +++ b/src/whoosh/matching/__init__.py @@ -25,7 +25,38 @@ # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Matt Chaput. -from whoosh.matching.binary import * -from whoosh.matching.combo import * -from whoosh.matching.mcore import * -from whoosh.matching.wrappers import * +from whoosh.matching.binary import ( + AdditiveBiMatcher, + AndMaybeMatcher, + AndNotMatcher, + BiMatcher, + DisjunctionMaxMatcher, + IntersectionMatcher, + UnionMatcher, +) +from whoosh.matching.combo import ( + ArrayUnionMatcher, + CombinationMatcher, + PreloadedUnionMatcher, +) +from whoosh.matching.mcore import ( + ConstantScoreMatcher, + LeafMatcher, + ListMatcher, + Matcher, + NoQualityAvailable, + NullMatcher, + NullMatcherClass, + ReadTooFar, +) +from whoosh.matching.wrappers import ( + ConstantScoreWrapperMatcher, + CoordMatcher, + ExcludeMatcher, + FilterMatcher, + InverseMatcher, + MultiMatcher, + RequireMatcher, + SingleTermMatcher, + WrappingMatcher, +) diff --git a/src/whoosh/qparser/__init__.py b/src/whoosh/qparser/__init__.py index a61f9052..d5ce2ab3 100644 --- a/src/whoosh/qparser/__init__.py +++ b/src/whoosh/qparser/__init__.py @@ -25,6 +25,59 @@ # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Matt Chaput. -from whoosh.qparser.default import * -from whoosh.qparser.plugins import * -from whoosh.qparser.syntax import * +from whoosh.qparser.default import ( + DisMaxParser, + MultifieldParser, + QueryParser, + SimpleParser, +) +from whoosh.qparser.plugins import ( + BoostPlugin, + CopyFieldPlugin, + EveryPlugin, + FieldAliasPlugin, + FieldsPlugin, + FunctionPlugin, + FuzzyTermPlugin, + GroupPlugin, + GtLtPlugin, + MultifieldPlugin, + OperatorsPlugin, + PhrasePlugin, + Plugin, + PlusMinusPlugin, + PrefixPlugin, + PseudoFieldPlugin, + RangePlugin, + RegexPlugin, + RegexTagger, + SequencePlugin, + SingleQuotePlugin, + TaggingPlugin, + WhitespacePlugin, + WildcardPlugin, +) +from whoosh.qparser.syntax import ( + AndGroup, + AndMaybeGroup, + AndNotGroup, + BinaryGroup, + DisMaxGroup, + ErrorNode, + FieldnameNode, + GroupNode, + InfixOperator, + MarkerNode, + NotGroup, + Operator, + OrderedGroup, + OrGroup, + PostfixOperator, + PrefixOperator, + RequireGroup, + SyntaxNode, + TextNode, + Whitespace, + WordNode, + Wrapper, +) diff --git a/src/whoosh/query/__init__.py b/src/whoosh/query/__init__.py index 8a9ae0af..5129f0fd 100644 --- a/src/whoosh/query/__init__.py +++ b/src/whoosh/query/__init__.py @@ -25,12 +25,62 @@ # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Matt Chaput. -from whoosh.query.compound import * -from whoosh.query.nested import * -from whoosh.query.positional import * -from whoosh.query.qcolumns import * -from whoosh.query.qcore import * -from whoosh.query.ranges import * -from whoosh.query.spans import * -from whoosh.query.terms import * -from whoosh.query.wrappers import * + +from whoosh.query.compound import ( + And, + AndMaybe, + AndNot, + BinaryQuery, + BooleanQuery, + CompoundQuery, + DefaultOr, + DisjunctionMax, + Or, + Otherwise, + PreloadedOr, + Require, + SplitOr, +) +from whoosh.query.nested import NestedChildren, NestedParent +from whoosh.query.positional import Ordered, Phrase, Sequence +from whoosh.query.qcolumns import ColumnMatcher, ColumnQuery +from whoosh.query.qcore import ( + Every, + Highest, + Lowest, + NullQuery, + Query, + QueryError, + _NullQuery, + error_query, + token_lists, +) +from whoosh.query.ranges import DateRange, NumericRange, RangeMixin, TermRange +from whoosh.query.spans import ( + Span, + SpanBefore, + SpanBiMatcher, + SpanBiQuery, + SpanCondition, + SpanContains, + SpanFirst, + SpanNear, + SpanNear2, + SpanNot, + SpanOr, + SpanQuery, + SpanWrappingMatcher, + WrappingSpan, +) +from whoosh.query.terms import ( + ExpandingTerm, + FuzzyTerm, + MultiTerm, + PatternQuery, + Prefix, + Regex, + Term, + Variations, + Wildcard, +) +from whoosh.query.wrappers import ConstantScoreQuery, Not, WeightingQuery, WrappingQuery diff --git a/src/whoosh/query/qcolumns.py b/src/whoosh/query/qcolumns.py index 6aeab5cd..58175529 100644 --- a/src/whoosh/query/qcolumns.py +++ b/src/whoosh/query/qcolumns.py @@ -26,7 +26,7 @@ # policies, either expressed or implied, of Matt Chaput. from whoosh.matching import ConstantScoreMatcher, NullMatcher, ReadTooFar -from whoosh.query import Query +from whoosh.query.qcore import Query class ColumnQuery(Query): diff --git a/src/whoosh/query/spans.py b/src/whoosh/query/spans.py index a22c07fa..7a6749ec 100644 --- a/src/whoosh/query/spans.py +++ b/src/whoosh/query/spans.py @@ -44,7 +44,8 @@ """ from whoosh.matching import binary, mcore, wrappers -from whoosh.query import And, AndMaybe, Or, Query, Term +from whoosh.query.compound import And, AndMaybe, Or +from whoosh.query.qcore import Query from whoosh.util import make_binary_tree # Span class diff --git a/src/whoosh/writing.py b/src/whoosh/writing.py index 5d14d98b..54b76f92 100644 --- a/src/whoosh/writing.py +++ b/src/whoosh/writing.py @@ -360,7 +360,7 @@ def add_document(self, **fields): from datetime import datetime, timedelta from whoosh import index - from whoosh.fields import * + from whoosh.fields import Schema, DATETIME, NUMERIC, TEXT schema = Schema(date=DATETIME, size=NUMERIC(float), content=TEXT) myindex = index.create_in("indexdir", schema) diff --git a/tests/test_dateparse.py b/tests/test_dateparse.py index 51b6a4c7..a87e5e20 100644 --- a/tests/test_dateparse.py +++ b/tests/test_dateparse.py @@ -1,4 +1,12 @@ -from whoosh.qparser.dateparse import * +from datetime import datetime, timedelta + +from whoosh.qparser.dateparse import ( + English, + adatetime, + relative_days, + relativedelta, + timespan, +) basedate = datetime(2010, 9, 20, 15, 16, 6, 454000) english = English()