You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by br...@apache.org on 2020/09/02 16:02:29 UTC
[lucene-solr] branch branch_8x updated: SOLR-14782: Document how to
unescape for the QueryElevationComponent.
This is an automated email from the ASF dual-hosted git repository.
broustant pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 838bd16 SOLR-14782: Document how to unescape for the QueryElevationComponent.
838bd16 is described below
commit 838bd16b8442855303358834147e894c3ba84071
Author: Bruno Roustant <br...@salesforce.com>
AuthorDate: Wed Sep 2 11:45:36 2020 +0200
SOLR-14782: Document how to unescape for the QueryElevationComponent.
---
.../TestPatternReplaceCharFilterFactory.java | 23 ++++++++++++++++++++++
.../src/the-query-elevation-component.adoc | 15 +++++++++++++-
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/pattern/TestPatternReplaceCharFilterFactory.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/pattern/TestPatternReplaceCharFilterFactory.java
index 74733d6..04f9269 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/pattern/TestPatternReplaceCharFilterFactory.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/pattern/TestPatternReplaceCharFilterFactory.java
@@ -77,4 +77,27 @@ public class TestPatternReplaceCharFilterFactory extends BaseTokenStreamFactoryT
});
assertTrue(expected.getMessage().contains("Unknown parameters"));
}
+
+ /** Test with backslash unescape */
+ public void testUnescape() throws Exception {
+ Reader reader = new StringReader("aaa\\ bbb\\-ccc");
+ reader = charFilterFactory("PatternReplace",
+ "pattern", "\\\\(.)",
+ "replacement", "$1").create(reader);
+ TokenStream ts = whitespaceMockTokenizer(reader);
+ assertTokenStreamContents(ts,
+ new String[] { "aaa", "bbb-ccc" },
+ new int[] { 0, 5 },
+ new int[] { 3, 13 });
+
+ reader = new StringReader("a\\b\\0\\-c\\é\\ d");
+ reader = charFilterFactory("PatternReplace",
+ "pattern", "\\\\([^\\p{IsAlphabetic}\\p{Digit}])",
+ "replacement", "$1").create(reader);
+ ts = whitespaceMockTokenizer(reader);
+ assertTokenStreamContents(ts,
+ new String[] { "a\\b\\0-c\\é", "d" },
+ new int[] { 0, 12 },
+ new int[] { 10, 13 });
+ }
}
diff --git a/solr/solr-ref-guide/src/the-query-elevation-component.adoc b/solr/solr-ref-guide/src/the-query-elevation-component.adoc
index f381de3..2c06628 100644
--- a/solr/solr-ref-guide/src/the-query-elevation-component.adoc
+++ b/solr/solr-ref-guide/src/the-query-elevation-component.adoc
@@ -61,7 +61,20 @@ Optionally, in the Query Elevation Component configuration you can also specify
The Query Elevation Search Component takes the following parameters:
`queryFieldType`::
-Specifies which fieldType should be used to analyze the incoming text. For example, it may be appropriate to use a fieldType with a LowerCaseFilter.
+Specifies which fieldType should be used to analyze the incoming text. For example, it may be appropriate to use a fieldType with a LowerCaseFilter. Other example, if you need to unescape backslash-escaped queries, then you can define the fieldType to preprocess with a PatternReplaceCharFilter. Here is the corresponding example of fieldType (traditionally in `schema.xml`):
+
+[source,xml]
+----
+<fieldType name="unescapelowercase" class="solr.TextField">
+ <analyzer>
+ <charFilter class="solr.PatternReplaceCharFilterFactory" pattern="\\(.)" replacement="$1"/>
+ <tokenizer class="solr.StandardTokenizerFactory"/>
+ <filter class="solr.LowerCaseFilterFactory"/>
+ </analyzer>
+</fieldType>
+----
+
+For example, to unescape only non-alphanumeric, the pattern could be `\\([^\p{IsAlphabetic}\p{Digit}])`.
`config-file`::
Path to the file that defines query elevation. This file must exist in `<instanceDir>/conf/<config-file>` or `<dataDir>/<config-file>`. If the file exists in the `conf/` directory it will be loaded once at startup. If it exists in the `data/` directory, it will be reloaded for each IndexReader.