Skip to content
Snippets Groups Projects

defining document fields. check the TODO

Merged Christine Brovkina requested to merge master into main
4 files
+ 33
18
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 11
7
@@ -38,10 +38,15 @@ public class Indexer {
}
public static void insertDoc(IndexWriter i, String item_id, String name, String category, String description){
Document doc = new Document();
doc.add(new TextField("item_id", line,Field.Store.YES));
doc.add(new TextField("name", line,Field.Store.YES));
doc.add(new TextField("category", line,Field.Store.YES));
doc.add(new TextField("description", line,Field.Store.YES));
doc.add(new TextField("item_id", item_id, Field.Store.YES, Field.Index.NOT_ANALYZED));
//TODO: latitude and longitude?
doc.add(new TextField("name", item_name,Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
for (String category : categories)
{
doc.add(new TextField("category", item_category, Field.Store.YES, Field.Index.ANALYZED));
}
doc.add(new TextField("description", item_description,Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
try { i.addDocument(doc); } catch (Exception e) { e.printStackTrace(); }
}
@@ -51,9 +56,9 @@ public class Indexer {
long start = System.currentTimeMillis(); //keep track of the time
Path path = Paths.get(indexPath);
System.out.println("Indexing to directory '" + indexPath + "'...\n");
Directory directory = FSDirectory.open(path);
//ANALYZER
// DEFINE ANALYZER
IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer());
//IndexWriterConfig config = new IndexWriterConfig(new StandardAnalyzer());
//IndexWriterConfig config = new IndexWriterConfig(new EnglishAnalyzer());
@@ -61,7 +66,6 @@ public class Indexer {
//--START INDEXING--
IndexWriter i = new IndexWriter(directory, config);
i.deleteAll();
//keep count
//--OPEN DB CONNECTION--
conn = DbManager.getConnection(true);
Loading