annotate src/goodjava/lucene/api/MultiFieldParserConfig.java @ 1648:224af797b1f9

Mainly small install script improvements - Consistent usage of `$LUANHOME`, removed reliance on current directory. - Made Luan build and install fine (on Linux) without requiring launching it via sudo. Only asks to elevate privileges if installation failed. - Minor spelling mistake fix.
author Fox
date Mon, 28 Mar 2022 18:00:12 +0200
parents 3bd4d7963456
children f48db13ae2d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 package goodjava.lucene.api;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 import java.util.Map;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 import java.util.Collections;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 import org.apache.lucene.analysis.Analyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 import org.apache.lucene.analysis.core.KeywordAnalyzer;
1528
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
7 import org.apache.lucene.index.IndexWriterConfig;
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
8 import org.apache.lucene.util.Version;
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 import goodjava.lucene.queryparser.MultiFieldParser;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 import goodjava.lucene.queryparser.FieldParser;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 import goodjava.lucene.queryparser.StringFieldParser;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 public class MultiFieldParserConfig implements GoodIndexWriterConfig {
1528
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
15 private final Version luceneVersion;
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 private final MultiFieldParser mfp;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
1528
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
18 public MultiFieldParserConfig(Version luceneVersion,MultiFieldParser mfp) {
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
19 this.luceneVersion = luceneVersion;
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 this.mfp = mfp;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
1528
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
23 public IndexWriterConfig newLuceneConfig() {
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
24 return new IndexWriterConfig(luceneVersion,new FieldAnalyzer());
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
25 }
3bd4d7963456 use goodjava/lucene/api
Franklin Schmidt <fschmidt@gmail.com>
parents: 1525
diff changeset
26
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 public final boolean isIndexed(String fieldName) {
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 return mfp.fields.containsKey(fieldName);
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 public final Analyzer getAnalyzer(String fieldName) {
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 FieldParser fp = mfp.fields.get(fieldName);
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 if( !(fp instanceof StringFieldParser) )
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 return null;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 StringFieldParser sfp = (StringFieldParser)fp;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 Analyzer analyzer = sfp.analyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 return analyzer instanceof KeywordAnalyzer ? null : analyzer;
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
1525
f848d40b3b07 lucene.api add boosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 1460
diff changeset
40 private static final MoreFieldInfo noMoreFieldInfo = new MoreFieldInfo(Collections.emptyMap(),Collections.emptyMap());
f848d40b3b07 lucene.api add boosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 1460
diff changeset
41
f848d40b3b07 lucene.api add boosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 1460
diff changeset
42 public MoreFieldInfo getMoreFieldInfo(Map<String,Object> storedFields) {
f848d40b3b07 lucene.api add boosts
Franklin Schmidt <fschmidt@gmail.com>
parents: 1460
diff changeset
43 return noMoreFieldInfo;
1460
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 }
3ab0d043370f start lucene.api
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 }