val) {
48 | fields.addAll(val);
49 | return this;
50 | }
51 |
52 | public Builder maxDocFreq(int val) {
53 | maxDocFreq = val;
54 | return this;
55 | }
56 |
57 | public Builder minDocFreq(int val) {
58 | minDocFreq = val;
59 | return this;
60 | }
61 |
62 | public Builder minTermFreq(int val) {
63 | minTermFreq = val;
64 | return this;
65 | }
66 |
67 | public MLTConfig build() {
68 | return new MLTConfig(this);
69 | }
70 | }
71 |
72 | private MLTConfig(Builder builder) {
73 | this.fields = Collections.unmodifiableList(builder.fields);
74 | this.maxDocFreq = builder.maxDocFreq;
75 | this.minDocFreq = builder.minDocFreq;
76 | this.minTermFreq = builder.minTermFreq;
77 | }
78 |
79 | public String[] getFieldNames() {
80 | return fields.toArray(new String[fields.size()]);
81 | }
82 |
83 | public int getMaxDocFreq() {
84 | return maxDocFreq;
85 | }
86 |
87 | public int getMinDocFreq() {
88 | return minDocFreq;
89 | }
90 |
91 | public int getMinTermFreq() {
92 | return minTermFreq;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/search/SearchFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.search;
19 |
20 | import org.apache.lucene.index.IndexReader;
21 |
22 | /** Factory of {@link Search} */
23 | public class SearchFactory {
24 |
25 | public Search newInstance(IndexReader reader) {
26 | return new SearchImpl(reader);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/search/SimilarityConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.search;
19 |
20 | /**
21 | * Configurations for Similarity.
22 | */
23 | public final class SimilarityConfig {
24 |
25 | private final boolean useClassicSimilarity;
26 |
27 | /* BM25Similarity parameters */
28 |
29 | private final float k1;
30 |
31 | private final float b;
32 |
33 | /* Common parameters */
34 |
35 | private final boolean discountOverlaps;
36 |
37 | public static class Builder {
38 | private boolean useClassicSimilarity = false;
39 | private float k1 = 1.2f;
40 | private float b = 0.75f;
41 | private boolean discountOverlaps = true;
42 |
43 | public Builder useClassicSimilarity(boolean val) {
44 | useClassicSimilarity = val;
45 | return this;
46 | }
47 |
48 | public Builder k1(float val) {
49 | k1 = val;
50 | return this;
51 | }
52 |
53 | public Builder b(float val) {
54 | b = val;
55 | return this;
56 | }
57 |
58 | public Builder discountOverlaps (boolean val) {
59 | discountOverlaps = val;
60 | return this;
61 | }
62 |
63 | public SimilarityConfig build() {
64 | return new SimilarityConfig(this);
65 | }
66 | }
67 |
68 | private SimilarityConfig(Builder builder) {
69 | this.useClassicSimilarity = builder.useClassicSimilarity;
70 | this.k1 = builder.k1;
71 | this.b = builder.b;
72 | this.discountOverlaps = builder.discountOverlaps;
73 | }
74 |
75 | public boolean isUseClassicSimilarity() {
76 | return useClassicSimilarity;
77 | }
78 |
79 | public float getK1() {
80 | return k1;
81 | }
82 |
83 | public float getB() {
84 | return b;
85 | }
86 |
87 | public boolean isDiscountOverlaps() {
88 | return discountOverlaps;
89 | }
90 |
91 | public String toString() {
92 | return "SimilarityConfig: [" +
93 | " use classic similarity=" + useClassicSimilarity + ";" +
94 | " discount overlaps=" + discountOverlaps + ";" +
95 | " k1=" + k1 + ";" +
96 | " b=" + b + ";" +
97 | "]";
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/search/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** Models and APIs for the Search tab */
19 | package org.apache.lucene.luke.models.search;
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/tools/IndexTools.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.tools;
19 |
20 | import org.apache.lucene.analysis.Analyzer;
21 | import org.apache.lucene.document.Document;
22 | import org.apache.lucene.document.Field;
23 | import org.apache.lucene.index.CheckIndex;
24 | import org.apache.lucene.luke.models.LukeException;
25 | import org.apache.lucene.search.Query;
26 |
27 | import java.io.PrintStream;
28 | import java.util.Collection;
29 |
30 | /**
31 | * A dedicated interface for Luke's various index manipulations.
32 | */
33 | public interface IndexTools {
34 |
35 | /**
36 | * Execute force merges.
37 | *
38 | *
39 | * Merges are executed until there are maxNumSegments segments.
40 | * When expunge is true, maxNumSegments parameter is ignored.
41 | *
42 | *
43 | * @param expunge - if true, only segments having deleted documents are merged
44 | * @param maxNumSegments - max number of segments
45 | * @param ps - information stream
46 | * @throws LukeException - if an internal error occurs when accessing index
47 | */
48 | void optimize(boolean expunge, int maxNumSegments, PrintStream ps);
49 |
50 | /**
51 | * Check the current index status.
52 | *
53 | * @param ps information stream
54 | * @return index status
55 | * @throws LukeException - if an internal error occurs when accessing index
56 | */
57 | CheckIndex.Status checkIndex(PrintStream ps);
58 |
59 | /**
60 | * Try to repair the corrupted index using previously returned index status.
61 | *
62 | * This method must be called with the return value from {@link IndexTools#checkIndex(PrintStream)}.
63 | *
64 | * @param st - index status
65 | * @param ps - information stream
66 | * @throws LukeException - if an internal error occurs when accessing index
67 | */
68 | void repairIndex(CheckIndex.Status st, PrintStream ps);
69 |
70 | /**
71 | * Add new document to this index.
72 | *
73 | * @param doc - document to be added
74 | * @param analyzer - analyzer for parsing to document
75 | * @throws LukeException - if an internal error occurs when accessing index
76 | */
77 | void addDocument(Document doc, Analyzer analyzer);
78 |
79 | /**
80 | * Delete documents from this index by the specified query.
81 | *
82 | * @param query - query for deleting
83 | * @throws LukeException - if an internal error occurs when accessing index
84 | */
85 | void deleteDocuments(Query query);
86 |
87 | /**
88 | * Create a new index.
89 | *
90 | * @throws LukeException - if an internal error occurs when accessing index
91 | */
92 | void createNewIndex();
93 |
94 | /**
95 | * Create a new index with sample documents.
96 | * @param dataDir - the directory path which contains sample documents (20 Newsgroups).
97 | */
98 | void createNewIndex(String dataDir);
99 |
100 | /**
101 | * Returns preset {@link Field} classes.
102 | */
103 | Collection> getPresetFields();
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/tools/IndexToolsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.tools;
19 |
20 | import org.apache.lucene.index.IndexReader;
21 | import org.apache.lucene.store.Directory;
22 |
23 | /** Factory of {@link IndexTools} */
24 | public class IndexToolsFactory {
25 |
26 | public IndexTools newInstance(Directory dir) {
27 | return new IndexToolsImpl(dir, false, false);
28 | }
29 |
30 | public IndexTools newInstance(IndexReader reader, boolean useCompound, boolean keepAllCommits) {
31 | return new IndexToolsImpl(reader, useCompound, keepAllCommits);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/tools/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** Models and APIs for various index manipulation */
19 | package org.apache.lucene.luke.models.tools;
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** Utilities for models and APIs */
19 | package org.apache.lucene.luke.models.util;
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/reflection/ClassScanner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.util.reflection;
19 |
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import java.io.IOException;
24 | import java.lang.invoke.MethodHandles;
25 | import java.net.URL;
26 | import java.nio.file.Path;
27 | import java.nio.file.Paths;
28 | import java.util.ArrayList;
29 | import java.util.Collections;
30 | import java.util.Enumeration;
31 | import java.util.HashSet;
32 | import java.util.List;
33 | import java.util.Set;
34 | import java.util.concurrent.ExecutorService;
35 | import java.util.concurrent.Executors;
36 | import java.util.concurrent.TimeUnit;
37 |
38 | /**
39 | * Utility class for scanning class files in jars.
40 | */
41 | public class ClassScanner {
42 |
43 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
44 |
45 | private final String packageName;
46 | private final ClassLoader[] classLoaders;
47 |
48 | public ClassScanner(String packageName, ClassLoader... classLoaders) {
49 | this.packageName = packageName;
50 | this.classLoaders = classLoaders;
51 | }
52 |
53 | public Set> scanSubTypes(Class superType) {
54 | final int numThreads = Runtime.getRuntime().availableProcessors();
55 |
56 | List> collectors = new ArrayList<>();
57 | for (int i = 0; i < numThreads; i++) {
58 | collectors.add(new SubtypeCollector(superType, packageName, classLoaders));
59 | }
60 |
61 | try {
62 | List urls = getJarUrls();
63 | for (int i = 0; i < urls.size(); i++) {
64 | collectors.get(i % numThreads).addUrl(urls.get(i));
65 | }
66 |
67 | ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
68 | for (SubtypeCollector collector : collectors) {
69 | executorService.submit(collector);
70 | }
71 |
72 | try {
73 | executorService.shutdown();
74 | executorService.awaitTermination(10, TimeUnit.SECONDS);
75 | } catch (InterruptedException e) {
76 | } finally {
77 | executorService.shutdownNow();
78 | }
79 |
80 | Set> types = new HashSet<>();
81 | for (SubtypeCollector collector : collectors) {
82 | types.addAll(collector.getTypes());
83 | }
84 | return types;
85 | } catch (IOException e) {
86 | log.error("Cannot load jar file entries", e);
87 | }
88 | return Collections.emptySet();
89 | }
90 |
91 | private List getJarUrls() throws IOException {
92 | List urls = new ArrayList<>();
93 | String resourceName = resourceName(packageName);
94 | for (ClassLoader loader : classLoaders) {
95 | for (Enumeration e = loader.getResources(resourceName); e.hasMoreElements(); ) {
96 | URL url = e.nextElement();
97 | // extract jar file path from the resource name
98 | int index = url.getPath().lastIndexOf(".jar");
99 | if (index > 0) {
100 | String path = url.getPath().substring(0, index + 4);
101 | urls.add(new URL(path));
102 | }
103 | }
104 | }
105 | return urls;
106 | }
107 |
108 | private static String resourceName(String packageName) {
109 | if (packageName == null || packageName.equals("")) {
110 | return packageName;
111 | }
112 | return packageName.replace('.', '/');
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/reflection/SubtypeCollector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.util.reflection;
19 |
20 | import org.slf4j.Logger;
21 | import org.slf4j.LoggerFactory;
22 |
23 | import java.io.IOException;
24 | import java.lang.invoke.MethodHandles;
25 | import java.net.URL;
26 | import java.util.Collections;
27 | import java.util.HashMap;
28 | import java.util.HashSet;
29 | import java.util.Map;
30 | import java.util.Set;
31 | import java.util.jar.JarInputStream;
32 | import java.util.zip.ZipEntry;
33 |
34 | final class SubtypeCollector implements Runnable {
35 |
36 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
37 |
38 | private static final Map> cache = new HashMap<>();
39 |
40 | private final Set urls = new HashSet<>();
41 |
42 | private final Class superType;
43 |
44 | private final String packageName;
45 |
46 | private final ClassLoader[] classLoaders;
47 |
48 | private final Set> types = new HashSet<>();
49 |
50 | SubtypeCollector(Class superType, String packageName, ClassLoader... classLoaders) {
51 | this.superType = superType;
52 | this.packageName = packageName;
53 | this.classLoaders = classLoaders;
54 | }
55 |
56 | void addUrl(URL url) {
57 | urls.add(url);
58 | }
59 |
60 | Set> getTypes() {
61 | return Collections.unmodifiableSet(types);
62 | }
63 |
64 | @Override
65 | public void run() {
66 | for (URL url : urls) {
67 | try (JarInputStream jis = new JarInputStream(url.openStream())) {
68 | // iterate all zip entry in the jar
69 | ZipEntry entry;
70 | while ((entry = jis.getNextEntry()) != null) {
71 | String name = entry.getName();
72 | if (name.endsWith(".class") && name.indexOf('$') < 0
73 | && !name.contains("package-info") && !name.startsWith("META-INF")) {
74 | String fqcn = convertToFQCN(name);
75 | if (!fqcn.startsWith(packageName)) {
76 | continue;
77 | }
78 | for (ClassLoader cl : classLoaders) {
79 | try {
80 | Class> clazz = Class.forName(fqcn, false, cl);
81 | if (isSubclassOf(clazz, superType)) {
82 | types.add(clazz.asSubclass(superType));
83 | }
84 | break;
85 | } catch (Throwable e) {
86 | }
87 | }
88 | }
89 | }
90 | } catch (IOException e) {
91 | log.error("Cannot load jar " + url.toString(), e);
92 | }
93 | }
94 | }
95 |
96 | private static String convertToFQCN(String name) {
97 | if (name == null || name.equals("")) {
98 | return name;
99 | }
100 | int index = name.lastIndexOf(".class");
101 | return name.replace('/', '.').substring(0, index);
102 | }
103 |
104 | private static boolean isSubclassOf(Class> clazz, Class> superType) {
105 | String superTypeName = superType.getName();
106 | cache.putIfAbsent(superTypeName, new HashSet<>());
107 | Class> c = clazz.getSuperclass();
108 | while (c != null) {
109 | if (cache.get(superTypeName).contains(clazz.getName())) {
110 | return true;
111 | }
112 | if (c.getName().equals(superTypeName)) {
113 | cache.get(superTypeName).add(clazz.getName());
114 | return true;
115 | }
116 | c = c.getSuperclass();
117 | }
118 | return false;
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/reflection/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** Utilities for reflections */
19 | package org.apache.lucene.luke.models.util.reflection;
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/twentynewsgroups/Message.java:
--------------------------------------------------------------------------------
1 | package org.apache.lucene.luke.models.util.twentynewsgroups;
2 |
3 | import org.apache.lucene.analysis.Analyzer;
4 | import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper;
5 | import org.apache.lucene.analysis.standard.StandardAnalyzer;
6 | import org.apache.lucene.analysis.standard.UAX29URLEmailAnalyzer;
7 | import org.apache.lucene.document.Document;
8 | import org.apache.lucene.document.Field;
9 | import org.apache.lucene.document.IntPoint;
10 | import org.apache.lucene.document.SortedNumericDocValuesField;
11 | import org.apache.lucene.document.StoredField;
12 | import org.apache.lucene.document.StringField;
13 | import org.apache.lucene.document.TextField;
14 |
15 | import java.util.HashMap;
16 | import java.util.Map;
17 | import java.util.Objects;
18 |
19 | /** Data holder class for a newsgroups message */
20 | public class Message {
21 |
22 | private String from;
23 | private String[] newsgroups;
24 | private String subject;
25 | private String messageId;
26 | private String date;
27 | private String organization;
28 | private String body;
29 | private int lines;
30 |
31 | public String getFrom() {
32 | return from;
33 | }
34 |
35 | public void setFrom(String from) {
36 | this.from = from;
37 | }
38 |
39 | public String[] getNewsgroups() {
40 | return newsgroups;
41 | }
42 |
43 | public void setNewsgroups(String[] newsgroups) {
44 | this.newsgroups = newsgroups;
45 | }
46 |
47 | public String getSubject() {
48 | return subject;
49 | }
50 |
51 | public void setSubject(String subject) {
52 | this.subject = subject;
53 | }
54 |
55 | public String getMessageId() {
56 | return messageId;
57 | }
58 |
59 | public void setMessageId(String messageId) {
60 | this.messageId = messageId;
61 | }
62 |
63 | public String getDate() {
64 | return date;
65 | }
66 |
67 | public void setDate(String date) {
68 | this.date = date;
69 | }
70 |
71 | public String getOrganization() {
72 | return organization;
73 | }
74 |
75 | public void setOrganization(String organization) {
76 | this.organization = organization;
77 | }
78 |
79 | public String getBody() {
80 | return body;
81 | }
82 |
83 | public void setBody(String body) {
84 | this.body = body;
85 | }
86 |
87 | public int getLines() {
88 | return lines;
89 | }
90 |
91 | public void setLines(int lines) {
92 | this.lines = lines;
93 | }
94 |
95 | public Document toLuceneDoc() {
96 | Document doc = new Document();
97 |
98 | if (Objects.nonNull(getFrom())) {
99 | doc.add(new TextField("from", getFrom(), Field.Store.YES));
100 | }
101 |
102 | if (Objects.nonNull(getNewsgroups())) {
103 | for (String newsgroup : getNewsgroups()) {
104 | doc.add(new StringField("newsgroup", newsgroup, Field.Store.YES));
105 | }
106 | }
107 |
108 | if (Objects.nonNull(getSubject())) {
109 | doc.add(new TextField("subject", getSubject(), Field.Store.YES));
110 | }
111 |
112 | if (Objects.nonNull(getMessageId())) {
113 | doc.add(new StringField("messageId", getMessageId(), Field.Store.YES));
114 | }
115 |
116 | if (Objects.nonNull(getDate())) {
117 | doc.add(new StoredField("date_raw", getDate()));
118 | }
119 |
120 |
121 | if (getOrganization() != null) {
122 | doc.add(new TextField("organization", getOrganization(), Field.Store.YES));
123 | }
124 |
125 | doc.add(new IntPoint("lines_range", getLines()));
126 | doc.add(new SortedNumericDocValuesField("lines_sort", getLines()));
127 | doc.add(new StoredField("lines_raw", String.valueOf(getLines())));
128 |
129 | if (Objects.nonNull(getBody())) {
130 | doc.add(new TextField("body", getBody(), Field.Store.YES));
131 | }
132 |
133 | return doc;
134 | }
135 |
136 | public static Analyzer createLuceneAnalyzer() {
137 | Map map = new HashMap<>();
138 | map.put("from", new UAX29URLEmailAnalyzer());
139 | return new PerFieldAnalyzerWrapper(new StandardAnalyzer(), map);
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/twentynewsgroups/MessageFilesParser.java:
--------------------------------------------------------------------------------
1 | package org.apache.lucene.luke.models.util.twentynewsgroups;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.nio.charset.StandardCharsets;
9 | import java.nio.file.FileVisitResult;
10 | import java.nio.file.Files;
11 | import java.nio.file.Path;
12 | import java.nio.file.SimpleFileVisitor;
13 | import java.nio.file.attribute.BasicFileAttributes;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /** 20 Newsgroups (http://kdd.ics.uci.edu/databases/20newsgroups/20newsgroups.html) message files parser */
18 | public class MessageFilesParser extends SimpleFileVisitor {
19 |
20 | private static final Logger log = LoggerFactory.getLogger(MessageFilesParser.class);
21 |
22 | private final Path root;
23 |
24 | private final List messages = new ArrayList<>();
25 |
26 | public MessageFilesParser(Path root) {
27 | this.root = root;
28 | }
29 |
30 | public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
31 | try {
32 | if (attr.isRegularFile()) {
33 | Message message = parse(file);
34 | if (message != null) {
35 | messages.add(parse(file));
36 | }
37 | }
38 | } catch (IOException e) {
39 | log.warn("Invalid file? " + file.toString());
40 | }
41 | return FileVisitResult.CONTINUE;
42 | }
43 |
44 | Message parse(Path file) throws IOException {
45 | try (BufferedReader br = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
46 | String line = br.readLine();
47 |
48 | Message message = new Message();
49 | while (!line.equals("")) {
50 | String[] ary = line.split(":", 2);
51 | if (ary.length < 2) {
52 | line = br.readLine();
53 | continue;
54 | }
55 | String att = ary[0].trim();
56 | String val = ary[1].trim();
57 | switch (att) {
58 | case "From":
59 | message.setFrom(val);
60 | break;
61 | case "Newsgroups":
62 | message.setNewsgroups(val.split(","));
63 | break;
64 | case "Subject":
65 | message.setSubject(val);
66 | break;
67 | case "Message-ID":
68 | message.setMessageId(val);
69 | break;
70 | case "Date":
71 | message.setDate(val);
72 | break;
73 | case "Organization":
74 | message.setOrganization(val);
75 | break;
76 | case "Lines":
77 | try {
78 | message.setLines(Integer.parseInt(ary[1].trim()));
79 | } catch (NumberFormatException e) {}
80 | default:
81 | break;
82 | }
83 |
84 | line = br.readLine();
85 | }
86 |
87 | StringBuilder sb = new StringBuilder();
88 | while (line != null) {
89 | sb.append(line);
90 | sb.append(" ");
91 | line = br.readLine();
92 | }
93 | message.setBody(sb.toString());
94 |
95 | return message;
96 | }
97 | }
98 |
99 | public List parseAll() throws IOException {
100 | Files.walkFileTree(root, this);
101 | return messages;
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/models/util/twentynewsgroups/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** Utilities for indexing 20 Newsgroups data */
19 | package org.apache.lucene.luke.models.util.twentynewsgroups;
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** Luke : Lucene toolbox project */
19 | package org.apache.lucene.luke;
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/util/BytesRefUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.util;
19 |
20 | import org.apache.lucene.util.BytesRef;
21 |
22 | /**
23 | * An utility class for handling {@link BytesRef} objects.
24 | */
25 | public final class BytesRefUtils {
26 |
27 | public static String decode(BytesRef ref) {
28 | try {
29 | return ref.utf8ToString();
30 | } catch (Exception e) {
31 | return ref.toString();
32 | }
33 | }
34 |
35 | private BytesRefUtils() {
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/apache/lucene/luke/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /** General utilities */
19 | package org.apache.lucene.luke.util;
--------------------------------------------------------------------------------
/src/main/java/overview.html:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
21 | Luke
22 |
23 |
24 | Luke - Lucene Toolbox
25 |
26 |
--------------------------------------------------------------------------------
/src/main/resources/font/ElegantIcons.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/font/ElegantIcons.ttf
--------------------------------------------------------------------------------
/src/main/resources/img/indicator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/indicator.gif
--------------------------------------------------------------------------------
/src/main/resources/img/lucene-logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/lucene-logo.gif
--------------------------------------------------------------------------------
/src/main/resources/img/lucene.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/lucene.gif
--------------------------------------------------------------------------------
/src/main/resources/img/luke-logo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/luke-logo.gif
--------------------------------------------------------------------------------
/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 | [%d{ISO8601}] %5p (%F:%L) - %m%n
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | false
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/lucene/luke/app/desktop/util/inifile/SimpleIniFileTest.java:
--------------------------------------------------------------------------------
1 | package org.apache.lucene.luke.app.desktop.util.inifile;
2 |
3 | import org.apache.lucene.util.LuceneTestCase;
4 | import org.junit.Test;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.nio.charset.StandardCharsets;
9 | import java.nio.file.Files;
10 | import java.nio.file.Path;
11 | import java.util.List;
12 | import java.util.Map;
13 | import java.util.stream.Collectors;
14 |
15 | public class SimpleIniFileTest extends LuceneTestCase {
16 |
17 | @Test
18 | public void testStore() throws IOException {
19 | Path path = saveTestIni();
20 | assertTrue(Files.exists(path));
21 | assertTrue(Files.isRegularFile(path));
22 |
23 | try (BufferedReader br = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
24 | List lines = br.lines().collect(Collectors.toList());
25 | assertEquals(8, lines.size());
26 | assertEquals("[section1]", lines.get(0));
27 | assertEquals("s1 = aaa", lines.get(1));
28 | assertEquals("s2 = bbb", lines.get(2));
29 | assertEquals("", lines.get(3));
30 | assertEquals("[section2]", lines.get(4));
31 | assertEquals("b1 = true", lines.get(5));
32 | assertEquals("b2 = false", lines.get(6));
33 | assertEquals("", lines.get(7));
34 | }
35 | }
36 |
37 | @Test
38 | public void testLoad() throws IOException {
39 | Path path = saveTestIni();
40 |
41 | SimpleIniFile iniFile = new SimpleIniFile();
42 | iniFile.load(path);
43 |
44 | Map sections = iniFile.getSections();
45 | assertEquals(2, sections.size());
46 | assertEquals(2, sections.get("section1").size());
47 | assertEquals(2, sections.get("section2").size());
48 | }
49 |
50 | @Test
51 | public void testPut() {
52 | SimpleIniFile iniFile = new SimpleIniFile();
53 | iniFile.put("section1", "s1", "aaa");
54 | iniFile.put("section1", "s1", "aaa_updated");
55 | iniFile.put("section2", "b1", true);
56 | iniFile.put("section2", "b2", null);
57 |
58 | Map sections = iniFile.getSections();
59 | assertEquals("aaa_updated", sections.get("section1").get("s1"));
60 | assertEquals("true", sections.get("section2").get("b1"));
61 | assertNull(sections.get("section2").get("b2"));
62 | }
63 |
64 | @Test
65 | public void testGet() throws IOException {
66 | Path path = saveTestIni();
67 | SimpleIniFile iniFile = new SimpleIniFile();
68 | iniFile.load(path);
69 |
70 | assertNull(iniFile.getString("", ""));
71 |
72 | assertEquals("aaa", iniFile.getString("section1", "s1"));
73 | assertEquals("bbb", iniFile.getString("section1", "s2"));
74 | assertNull(iniFile.getString("section1", "s3"));
75 | assertNull(iniFile.getString("section1", ""));
76 |
77 | assertEquals(true, iniFile.getBoolean("section2", "b1"));
78 | assertEquals(false, iniFile.getBoolean("section2", "b2"));
79 | assertFalse(iniFile.getBoolean("section2", "b3"));
80 | }
81 |
82 | private Path saveTestIni() throws IOException {
83 | SimpleIniFile iniFile = new SimpleIniFile();
84 | iniFile.put("", "s0", "000");
85 |
86 | iniFile.put("section1", "s1", "aaa");
87 | iniFile.put("section1", "s2", "---");
88 | iniFile.put("section1", "s2", "bbb");
89 | iniFile.put("section1", "", "ccc");
90 |
91 | iniFile.put("section2", "b1", true);
92 | iniFile.put("section2", "b2", false);
93 |
94 | Path path = createTempFile();
95 | iniFile.store(path);
96 | return path;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/lucene/luke/models/overview/OverviewTestBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.overview;
19 |
20 | import org.apache.lucene.analysis.MockAnalyzer;
21 | import org.apache.lucene.document.Document;
22 | import org.apache.lucene.document.Field;
23 | import org.apache.lucene.document.TextField;
24 | import org.apache.lucene.index.DirectoryReader;
25 | import org.apache.lucene.index.IndexReader;
26 | import org.apache.lucene.index.RandomIndexWriter;
27 | import org.apache.lucene.store.Directory;
28 | import org.apache.lucene.util.LuceneTestCase;
29 | import org.junit.After;
30 | import org.junit.Before;
31 |
32 | import java.io.IOException;
33 | import java.nio.file.Path;
34 | import java.util.Collections;
35 | import java.util.HashMap;
36 | import java.util.Map;
37 |
38 | public abstract class OverviewTestBase extends LuceneTestCase {
39 |
40 | IndexReader reader;
41 |
42 | Directory dir;
43 |
44 | Path indexDir;
45 |
46 | @Override
47 | @Before
48 | public void setUp() throws Exception {
49 | super.setUp();
50 | indexDir = createIndex();
51 | dir = newFSDirectory(indexDir);
52 | reader = DirectoryReader.open(dir);
53 | }
54 |
55 | private Path createIndex() throws IOException {
56 | Path indexDir = createTempDir();
57 |
58 | Directory dir = newFSDirectory(indexDir);
59 | RandomIndexWriter writer = new RandomIndexWriter(random(), dir, new MockAnalyzer(random()));
60 |
61 | Document doc1 = new Document();
62 | doc1.add(newStringField("f1", "1", Field.Store.NO));
63 | doc1.add(newTextField("f2", "a b c d e", Field.Store.NO));
64 | writer.addDocument(doc1);
65 |
66 | Document doc2 = new Document();
67 | doc2.add(newStringField("f1", "2", Field.Store.NO));
68 | doc2.add(new TextField("f2", "a c", Field.Store.NO));
69 | writer.addDocument(doc2);
70 |
71 | Document doc3 = new Document();
72 | doc3.add(newStringField("f1", "3", Field.Store.NO));
73 | doc3.add(newTextField("f2", "a f", Field.Store.NO));
74 | writer.addDocument(doc3);
75 |
76 | Map userData = new HashMap<>();
77 | userData.put("data", "val");
78 | writer.w.setLiveCommitData(userData.entrySet());
79 |
80 | writer.commit();
81 |
82 | writer.close();
83 | dir.close();
84 |
85 | return indexDir;
86 | }
87 |
88 | @Override
89 | @After
90 | public void tearDown() throws Exception {
91 | super.tearDown();
92 | reader.close();
93 | dir.close();
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/test/java/org/apache/lucene/luke/models/overview/TermCountsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.overview;
19 |
20 | import org.junit.Test;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Arrays;
24 | import java.util.Map;
25 |
26 | public class TermCountsTest extends OverviewTestBase {
27 |
28 | @Test
29 | public void testNumTerms() throws Exception {
30 | TermCounts termCounts = new TermCounts(reader);
31 | assertEquals(9, termCounts.numTerms());
32 | }
33 |
34 | @Test
35 | @SuppressWarnings("unchecked")
36 | public void testSortedTermCounts_count_asc() throws Exception {
37 | TermCounts termCounts = new TermCounts(reader);
38 |
39 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.COUNT_ASC);
40 | assertEquals(Arrays.asList("f1", "f2"), new ArrayList<>(countsMap.keySet()));
41 |
42 | assertEquals(3, (long) countsMap.get("f1"));
43 | assertEquals(6, (long) countsMap.get("f2"));
44 | }
45 |
46 | @Test
47 | @SuppressWarnings("unchecked")
48 | public void testSortedTermCounts_count_desc() throws Exception {
49 | TermCounts termCounts = new TermCounts(reader);
50 |
51 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.COUNT_DESC);
52 | assertEquals(Arrays.asList("f2", "f1"), new ArrayList<>(countsMap.keySet()));
53 |
54 | assertEquals(3, (long) countsMap.get("f1"));
55 | assertEquals(6, (long) countsMap.get("f2"));
56 | }
57 |
58 | @Test
59 | @SuppressWarnings("unchecked")
60 | public void testSortedTermCounts_name_asc() throws Exception {
61 | TermCounts termCounts = new TermCounts(reader);
62 |
63 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.NAME_ASC);
64 | assertEquals(Arrays.asList("f1", "f2"), new ArrayList<>(countsMap.keySet()));
65 |
66 | assertEquals(3, (long) countsMap.get("f1"));
67 | assertEquals(6, (long) countsMap.get("f2"));
68 | }
69 |
70 | @Test
71 | @SuppressWarnings("unchecked")
72 | public void testSortedTermCounts_name_desc() throws Exception {
73 | TermCounts termCounts = new TermCounts(reader);
74 |
75 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.NAME_DESC);
76 | assertEquals(Arrays.asList("f2", "f1"), new ArrayList<>(countsMap.keySet()));
77 |
78 | assertEquals(3, (long) countsMap.get("f1"));
79 | assertEquals(6, (long) countsMap.get("f2"));
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/src/test/java/org/apache/lucene/luke/models/overview/TopTermsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package org.apache.lucene.luke.models.overview;
19 |
20 | import org.junit.Test;
21 |
22 | import java.util.List;
23 |
24 | public class TopTermsTest extends OverviewTestBase {
25 |
26 | @Test
27 | public void testGetTopTerms() throws Exception {
28 | TopTerms topTerms = new TopTerms(reader);
29 | List result = topTerms.getTopTerms("f2", 2);
30 |
31 | assertEquals("a", result.get(0).getDecodedTermText());
32 | assertEquals(3, result.get(0).getDocFreq());
33 | assertEquals("f2", result.get(0).getField());
34 |
35 | assertEquals("c", result.get(1).getDecodedTermText());
36 | assertEquals(2, result.get(1).getDocFreq());
37 | assertEquals("f2", result.get(1).getField());
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
20 |
21 |
22 | [%d{ISO8601}] %5p (%F:%L) - %m%n
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------