Skip to content

Commit 1f57af7

Browse files
author
mkorzhemanova
committed
Changes according to the code review
1 parent 425ed86 commit 1f57af7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+553
-298
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,10 @@
7272
<artifactId>lucene-queryparser</artifactId>
7373
<version>5.0.0</version>
7474
</dependency>
75+
<dependency>
76+
<groupId>com.google.guava</groupId>
77+
<artifactId>guava</artifactId>
78+
<version>18.0</version>
79+
</dependency>
7580
</dependencies>
7681
</project>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<indexerConfiguration>
3-
<indexPath>D:\CS\Projects\Prompter\resources\index\arXiv\test</indexPath>
4-
<directory>D:\CS\Projects\Prompter\resources\test\arXiv</directory>
3+
<indexPath>resources\data\index\test</indexPath>
4+
<directory>resources\data\test\arXiv</directory>
55
</indexerConfiguration>

resources/retriever/oai_retrieve_config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
<prefix>oai_dc</prefix>
77
<class>com.bardsoftware.papeeria.sufler.retriever.oai.metadata.DublinCoreMetadata</class>
88
</metadata>
9-
<path>D:\CS\Projects\Prompter\resources\test\</path>
9+
<path>resources\data\test\</path>
1010
<source>arXiv</source>
1111
</oaiConfiguration>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<searcherConfiguration>
3-
<indexDirectory>D:\CS\Projects\Prompter\resources\index\arXiv\test</indexDirectory>
3+
<indexDirectory>resources\data\index\test</indexDirectory>
44
<size>10</size>
55
</searcherConfiguration>

src/com/bardsoftware/papeeria/sufler/indexer/IndexedField.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
Copyright 2015 BarD Software s.r.o
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
115
package com.bardsoftware.papeeria.sufler.indexer;
216

317
import org.apache.log4j.Logger;
@@ -15,25 +29,25 @@ public enum IndexedField {
1529
SUBJECT(StringField.class, Field.Store.YES),
1630
DATE(StringField.class, Field.Store.YES);
1731

18-
private static Logger logger = Logger.getLogger(IndexedField.class);
32+
private static final Logger LOGGER = Logger.getLogger(IndexedField.class);
1933

20-
private Class<? extends Field> fieldClass;
21-
private Field.Store fieldStore;
34+
private Class<? extends Field> myFieldClass;
35+
private Field.Store myFieldStore;
2236

23-
IndexedField(Class<? extends Field> fieldClass, Field.Store fieldStore) {
24-
this.fieldClass = fieldClass;
25-
this.fieldStore = fieldStore;
37+
IndexedField(Class<? extends Field> myFieldClass, Field.Store myFieldStore) {
38+
this.myFieldClass = myFieldClass;
39+
this.myFieldStore = myFieldStore;
2640
}
2741

2842
public Field createField(String value) {
29-
logger.debug("Creating field in index: name=" + this.name().toLowerCase() + ", value=" + value);
43+
LOGGER.debug("Creating field in index: name=" + this.name().toLowerCase() + ", value=" + value);
3044
Field result = null;
3145

3246
try {
33-
Constructor constructor = fieldClass.getConstructor(String.class, String.class, Field.Store.class);
34-
result = (Field) constructor.newInstance(this.name().toLowerCase(), value, this.fieldStore);
47+
Constructor constructor = myFieldClass.getConstructor(String.class, String.class, Field.Store.class);
48+
result = (Field) constructor.newInstance(this.name().toLowerCase(), value, this.myFieldStore);
3549
} catch (Exception e) {
36-
logger.error("Error instantiating index field: " + this.name().toLowerCase(), e);
50+
LOGGER.error("Error instantiating index field: " + this.name().toLowerCase(), e);
3751
}
3852
return result;
3953
}

src/com/bardsoftware/papeeria/sufler/indexer/Indexer.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
1+
/*
2+
Copyright 2015 BarD Software s.r.o
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
115
package com.bardsoftware.papeeria.sufler.indexer;
216

17+
import com.bardsoftware.papeeria.sufler.indexer.configuration.IndexerConfiguration;
18+
import com.google.common.base.Preconditions;
319
import org.apache.log4j.Logger;
420
import org.apache.lucene.analysis.standard.StandardAnalyzer;
521
import org.apache.lucene.index.IndexWriter;
@@ -13,29 +29,30 @@
1329
import java.nio.file.Paths;
1430

1531
public abstract class Indexer {
16-
protected static Logger logger = Logger.getLogger(Indexer.class);
32+
private static final Logger LOGGER = Logger.getLogger(Indexer.class);
1733

18-
private IndexerConfiguration configuration;
19-
protected IndexWriter writer;
34+
private IndexerConfiguration myConfiguration;
35+
protected IndexWriter myWriter;
2036

21-
public Indexer() {
22-
configuration = IndexerConfiguration.getInstance();
37+
public Indexer(IndexerConfiguration configuration) {
38+
myConfiguration = configuration;
39+
Preconditions.checkNotNull(myConfiguration);
2340
}
2441

2542
public void index() throws IOException {
26-
writer = createWriter();
27-
for (String path : configuration.getDirectories()) {
43+
myWriter = createWriter();
44+
for (String path : myConfiguration.getDirectories()) {
2845
File directory = new File(path);
2946
if (isValidDirectory(directory)) {
3047
indexDirectory(directory);
3148
}
3249
}
33-
writer.commit();
34-
writer.close();
50+
myWriter.commit();
51+
myWriter.close();
3552
}
3653

3754
private void indexDirectory(File directory) throws IOException {
38-
logger.debug("Indexing directory: " + directory.getName());
55+
LOGGER.debug("Indexing directory: " + directory.getName());
3956
File[] files = directory.listFiles();
4057
for (File file : files) {
4158
if (isValidFile(file)) {
@@ -47,23 +64,14 @@ private void indexDirectory(File directory) throws IOException {
4764
protected abstract void indexFile(File file) throws IOException;
4865

4966
private IndexWriter createWriter() throws IOException {
50-
Path path = Paths.get(configuration.getIndexPath());
67+
Path path = Paths.get(myConfiguration.getIndexPath());
5168
Directory indexDir = FSDirectory.open(path);
5269
IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
53-
IndexWriter indexWriter = new IndexWriter(indexDir, config);
54-
return indexWriter;
70+
return new IndexWriter(indexDir, config);
5571
}
5672

5773
private static boolean isValidDirectory(File directory) {
58-
if (!directory.exists()) {
59-
return false;
60-
}
61-
62-
if (!directory.isDirectory()) {
63-
return false;
64-
}
65-
66-
return true;
74+
return (directory.isDirectory());
6775
}
6876

6977
private boolean isValidFile(File file) {

src/com/bardsoftware/papeeria/sufler/indexer/IndexerConfiguration.java

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2015 BarD Software s.r.o
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
package com.bardsoftware.papeeria.sufler.indexer.configuration;
16+
17+
import java.util.List;
18+
19+
public interface IndexerConfiguration {
20+
public enum Type {
21+
OAI
22+
}
23+
String getIndexPath();
24+
25+
List<String> getDirectories();
26+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2015 BarD Software s.r.o
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
15+
package com.bardsoftware.papeeria.sufler.indexer.configuration;
16+
17+
import com.thoughtworks.xstream.XStream;
18+
import com.thoughtworks.xstream.annotations.XStreamAlias;
19+
import com.thoughtworks.xstream.annotations.XStreamImplicit;
20+
21+
import java.io.File;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
@XStreamAlias("indexerConfiguration")
26+
public class IndexerConfigurationXml implements IndexerConfiguration {
27+
28+
private static final String CONFIGURATION_PATH = "resources/indexer/";
29+
private static final String CONFIGURATION_FILENAME = "indexer_config.xml";
30+
31+
private static IndexerConfiguration ourInstance;
32+
33+
@XStreamAlias("indexPath")
34+
private String myIndexPath;
35+
36+
@XStreamImplicit(itemFieldName = "directory")
37+
private List<String> myDirectories = new ArrayList<>();
38+
39+
public IndexerConfigurationXml() {
40+
41+
}
42+
43+
private static void readFromFile() {
44+
XStream xstream = new XStream();
45+
xstream.processAnnotations(IndexerConfigurationXml.class);
46+
File file = new File(CONFIGURATION_PATH + CONFIGURATION_FILENAME);
47+
ourInstance = (IndexerConfiguration) (xstream.fromXML(file));
48+
}
49+
50+
@Override
51+
public String getIndexPath() {
52+
return myIndexPath;
53+
}
54+
55+
@Override
56+
public List<String> getDirectories() {
57+
return myDirectories;
58+
}
59+
60+
public static IndexerConfiguration getInstance() {
61+
if (ourInstance == null) {
62+
readFromFile();
63+
}
64+
return ourInstance;
65+
}
66+
}
67+

0 commit comments

Comments
 (0)