Browse Source

Some more scalafication

Abhinav Sarkar 6 years ago
parent
commit
75004747b3

+ 158
- 157
pom.xml View File

@@ -1,161 +1,162 @@
1
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
-	<modelVersion>4.0.0</modelVersion>
4
-	<groupId>net.abhinavsarkar.ircsearch</groupId>
5
-	<artifactId>irc-search</artifactId>
6
-	<version>1.0-SNAPSHOT</version>
7
-	<name>${project.artifactId}</name>
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" 
2
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
+  <modelVersion>4.0.0</modelVersion>
5
+  <groupId>net.abhinavsarkar.ircsearch</groupId>
6
+  <artifactId>irc-search</artifactId>
7
+  <version>1.0-SNAPSHOT</version>
8
+  <name>${project.artifactId}</name>
8 9
 
9
-	<properties>
10
-		<maven.compiler.source>1.6</maven.compiler.source>
11
-		<maven.compiler.target>1.6</maven.compiler.target>
12
-		<encoding>UTF-8</encoding>
13
-		<scala.version>2.10.0</scala.version>
14
-		<scala.majorversion>2.10</scala.majorversion>
15
-		<lucene.version>4.3.0</lucene.version>
16
-		<project.dependencyDir>${project.build.directory}/dependency</project.dependencyDir>
17
-	</properties>
10
+  <properties>
11
+    <maven.compiler.source>1.6</maven.compiler.source>
12
+    <maven.compiler.target>1.6</maven.compiler.target>
13
+    <encoding>UTF-8</encoding>
14
+    <scala.version>2.10.0</scala.version>
15
+    <scala.majorversion>2.10</scala.majorversion>
16
+    <lucene.version>4.3.0</lucene.version>
17
+    <project.dependencyDir>${project.build.directory}/dependency</project.dependencyDir>
18
+  </properties>
18 19
 
19
-	<dependencies>
20
-		<dependency>
21
-			<groupId>org.scala-lang</groupId>
22
-			<artifactId>scala-library</artifactId>
23
-			<version>${scala.version}</version>
24
-		</dependency>
25
-		<dependency>
26
-			<groupId>org.scala-lang</groupId>
27
-			<artifactId>scala-reflect</artifactId>
28
-			<version>${scala.version}</version>
29
-		</dependency>
30
-		<dependency>
31
-			<groupId>org.scala-lang</groupId>
32
-			<artifactId>scala-compiler</artifactId>
33
-			<version>${scala.version}</version>
34
-		</dependency>
35
-		<dependency>
36
-			<groupId>io.netty</groupId>
37
-			<artifactId>netty</artifactId>
38
-			<version>4.0.0.Alpha5</version>
39
-			<scope>compile</scope>
40
-		</dependency>
41
-		<dependency>
42
-			<groupId>com.typesafe</groupId>
43
-			<artifactId>scalalogging-slf4j_${scala.majorversion}</artifactId>
44
-			<version>1.0.1</version>
45
-		</dependency>
46
-		<dependency>
47
-			<groupId>ch.qos.logback</groupId>
48
-			<artifactId>logback-classic</artifactId>
49
-			<version>1.0.0</version>
50
-			<scope>runtime</scope>
51
-		</dependency>
52
-		<dependency>
53
-			<groupId>net.liftweb</groupId>
54
-			<artifactId>lift-json_${scala.majorversion}</artifactId>
55
-			<version>2.5-RC5</version>
56
-		</dependency>
57
-		<dependency>
58
-			<groupId>org.scala-lang</groupId>
59
-			<artifactId>jline</artifactId>
60
-			<version>2.11.0-M2</version>
61
-		</dependency>
62
-		<dependency>
63
-			<groupId>org.apache.lucene</groupId>
64
-			<artifactId>lucene-core</artifactId>
65
-			<version>${lucene.version}</version>
66
-		</dependency>
67
-		<dependency>
68
-			<groupId>org.apache.lucene</groupId>
69
-			<artifactId>lucene-analyzers-common</artifactId>
70
-			<version>${lucene.version}</version>
71
-		</dependency>
72
-		<dependency>
73
-			<groupId>org.apache.lucene</groupId>
74
-			<artifactId>lucene-queryparser</artifactId>
75
-			<version>${lucene.version}</version>
76
-		</dependency>
77
-		<dependency>
78
-			<groupId>net.sf.opencsv</groupId>
79
-			<artifactId>opencsv</artifactId>
80
-			<version>2.3</version>
81
-		</dependency>
82
-		<dependency>
83
-			<groupId>com.google.guava</groupId>
84
-			<artifactId>guava</artifactId>
85
-			<version>14.0.1</version>
86
-		</dependency>
87
-		<dependency>
88
-			<groupId>org.streum</groupId>
89
-			<artifactId>configrity-core_${scala.majorversion}</artifactId>
90
-			<version>1.0.0</version>
91
-			<exclusions>
92
-				<exclusion>
93
-					<groupId>org.scalatest</groupId>
94
-					<artifactId>scalatest_${scala.majorversion}</artifactId>
95
-				</exclusion>
96
-			</exclusions>
97
-		</dependency>
98
-	</dependencies>
20
+  <dependencies>
21
+    <dependency>
22
+      <groupId>org.scala-lang</groupId>
23
+      <artifactId>scala-library</artifactId>
24
+      <version>${scala.version}</version>
25
+    </dependency>
26
+    <dependency>
27
+      <groupId>org.scala-lang</groupId>
28
+      <artifactId>scala-reflect</artifactId>
29
+      <version>${scala.version}</version>
30
+    </dependency>
31
+    <dependency>
32
+      <groupId>org.scala-lang</groupId>
33
+      <artifactId>scala-compiler</artifactId>
34
+      <version>${scala.version}</version>
35
+    </dependency>
36
+    <dependency>
37
+      <groupId>io.netty</groupId>
38
+      <artifactId>netty</artifactId>
39
+      <version>4.0.0.Alpha5</version>
40
+      <scope>compile</scope>
41
+    </dependency>
42
+    <dependency>
43
+      <groupId>com.typesafe</groupId>
44
+      <artifactId>scalalogging-slf4j_${scala.majorversion}</artifactId>
45
+      <version>1.0.1</version>
46
+    </dependency>
47
+    <dependency>
48
+      <groupId>ch.qos.logback</groupId>
49
+      <artifactId>logback-classic</artifactId>
50
+      <version>1.0.0</version>
51
+      <scope>runtime</scope>
52
+    </dependency>
53
+    <dependency>
54
+      <groupId>net.liftweb</groupId>
55
+      <artifactId>lift-json_${scala.majorversion}</artifactId>
56
+      <version>2.5-RC5</version>
57
+    </dependency>
58
+    <dependency>
59
+      <groupId>org.scala-lang</groupId>
60
+      <artifactId>jline</artifactId>
61
+      <version>2.11.0-M2</version>
62
+    </dependency>
63
+    <dependency>
64
+      <groupId>org.apache.lucene</groupId>
65
+      <artifactId>lucene-core</artifactId>
66
+      <version>${lucene.version}</version>
67
+    </dependency>
68
+    <dependency>
69
+      <groupId>org.apache.lucene</groupId>
70
+      <artifactId>lucene-analyzers-common</artifactId>
71
+      <version>${lucene.version}</version>
72
+    </dependency>
73
+    <dependency>
74
+      <groupId>org.apache.lucene</groupId>
75
+      <artifactId>lucene-queryparser</artifactId>
76
+      <version>${lucene.version}</version>
77
+    </dependency>
78
+    <dependency>
79
+      <groupId>net.sf.opencsv</groupId>
80
+      <artifactId>opencsv</artifactId>
81
+      <version>2.3</version>
82
+    </dependency>
83
+    <dependency>
84
+      <groupId>com.google.guava</groupId>
85
+      <artifactId>guava</artifactId>
86
+      <version>14.0.1</version>
87
+    </dependency>
88
+    <dependency>
89
+      <groupId>org.streum</groupId>
90
+      <artifactId>configrity-core_${scala.majorversion}</artifactId>
91
+      <version>1.0.0</version>
92
+      <exclusions>
93
+        <exclusion>
94
+          <groupId>org.scalatest</groupId>
95
+          <artifactId>scalatest_${scala.majorversion}</artifactId>
96
+        </exclusion>
97
+      </exclusions>
98
+    </dependency>
99
+  </dependencies>
99 100
 
100
-	<build>
101
-		<sourceDirectory>src/main/scala</sourceDirectory>
102
-		<testSourceDirectory>src/test/scala</testSourceDirectory>
103
-		<plugins>
104
-			<plugin>
105
-				<groupId>org.apache.maven.plugins</groupId>
106
-				<artifactId>maven-dependency-plugin</artifactId>
107
-				<version>2.3</version>
108
-				<executions>
109
-					<execution>
110
-						<id>copy-dependencies</id>
111
-						<phase>package</phase>
112
-						<goals>
113
-							<goal>copy-dependencies</goal>
114
-						</goals>
115
-						<configuration>
116
-							<outputDirectory>${project.dependencyDir}</outputDirectory>
117
-							<includeScope>runtime</includeScope>
118
-							<excludeScope>provided</excludeScope>
119
-							<excludeTypes>pom</excludeTypes>
120
-						</configuration>
121
-					</execution>
122
-				</executions>
123
-			</plugin>
124
-			<plugin>
125
-				<groupId>org.scala-tools</groupId>
126
-				<artifactId>maven-scala-plugin</artifactId>
127
-				<version>2.15.0</version>
128
-				<executions>
129
-					<execution>
130
-						<goals>
131
-							<goal>compile</goal>
132
-							<goal>testCompile</goal>
133
-						</goals>
134
-						<configuration>
135
-							<args>
136
-								<arg>-make:transitive</arg>
137
-								<arg>-dependencyfile</arg>
138
-								<arg>${project.build.directory}/.scala_dependencies</arg>
139
-							</args>
140
-						</configuration>
141
-					</execution>
142
-				</executions>
143
-			</plugin>
144
-			<plugin>
145
-				<groupId>org.apache.maven.plugins</groupId>
146
-				<artifactId>maven-surefire-plugin</artifactId>
147
-				<version>2.6</version>
148
-				<configuration>
149
-					<useFile>false</useFile>
150
-					<disableXmlReport>true</disableXmlReport>
151
-					<!-- If you have classpath issue like NoDefClassError,... -->
152
-					<!-- useManifestOnlyJar>false</useManifestOnlyJar -->
153
-					<includes>
154
-						<include>**/*Test.*</include>
155
-						<include>**/*Suite.*</include>
156
-					</includes>
157
-				</configuration>
158
-			</plugin>
159
-		</plugins>
160
-	</build>
101
+  <build>
102
+    <sourceDirectory>src/main/scala</sourceDirectory>
103
+    <testSourceDirectory>src/test/scala</testSourceDirectory>
104
+    <plugins>
105
+      <plugin>
106
+        <groupId>org.apache.maven.plugins</groupId>
107
+        <artifactId>maven-dependency-plugin</artifactId>
108
+        <version>2.3</version>
109
+        <executions>
110
+          <execution>
111
+            <id>copy-dependencies</id>
112
+            <phase>package</phase>
113
+            <goals>
114
+              <goal>copy-dependencies</goal>
115
+            </goals>
116
+            <configuration>
117
+              <outputDirectory>${project.dependencyDir}</outputDirectory>
118
+              <includeScope>runtime</includeScope>
119
+              <excludeScope>provided</excludeScope>
120
+              <excludeTypes>pom</excludeTypes>
121
+            </configuration>
122
+          </execution>
123
+        </executions>
124
+      </plugin>
125
+      <plugin>
126
+        <groupId>org.scala-tools</groupId>
127
+        <artifactId>maven-scala-plugin</artifactId>
128
+        <version>2.15.0</version>
129
+        <executions>
130
+          <execution>
131
+            <goals>
132
+              <goal>compile</goal>
133
+              <goal>testCompile</goal>
134
+            </goals>
135
+            <configuration>
136
+              <args>
137
+                <arg>-make:transitive</arg>
138
+                <arg>-dependencyfile</arg>
139
+                <arg>${project.build.directory}/.scala_dependencies</arg>
140
+              </args>
141
+            </configuration>
142
+          </execution>
143
+        </executions>
144
+      </plugin>
145
+      <plugin>
146
+        <groupId>org.apache.maven.plugins</groupId>
147
+        <artifactId>maven-surefire-plugin</artifactId>
148
+        <version>2.6</version>
149
+        <configuration>
150
+          <useFile>false</useFile>
151
+          <disableXmlReport>true</disableXmlReport>
152
+          <!-- If you have classpath issue like NoDefClassError,... -->
153
+          <!-- useManifestOnlyJar>false</useManifestOnlyJar -->
154
+          <includes>
155
+            <include>**/*Test.*</include>
156
+            <include>**/*Suite.*</include>
157
+          </includes>
158
+        </configuration>
159
+      </plugin>
160
+    </plugins>
161
+  </build>
161 162
 </project>

+ 13
- 13
src/main/scala/net/abhinavsarkar/ircsearch/Server.scala View File

@@ -91,12 +91,12 @@ private object UnifiedHandler extends ChannelInboundByteHandlerAdapter {
91 91
   }
92 92
 
93 93
   override def inboundBufferUpdated(ctx : ChannelHandlerContext, in: ByteBuf) {
94
-    if (in.readableBytes() < 5) {
94
+    if (in.readableBytes < 5) {
95 95
       return;
96 96
     }
97 97
 
98
-    val magic1 = in.getUnsignedByte(in.readerIndex())
99
-    val magic2 = in.getUnsignedByte(in.readerIndex() + 1)
98
+    val magic1 = in.getUnsignedByte(in.readerIndex)
99
+    val magic2 = in.getUnsignedByte(in.readerIndex + 1)
100 100
     if (isHttp(magic1, magic2)) {
101 101
       ctx.pipeline
102 102
         .addLast("decoder", new HttpRequestDecoder)
@@ -107,7 +107,7 @@ private object UnifiedHandler extends ChannelInboundByteHandlerAdapter {
107 107
         .remove(this)
108 108
     } else {
109 109
       ctx.pipeline
110
-        .addLast("framedecoder", new DelimiterBasedFrameDecoder(1048576, Delimiters.lineDelimiter() : _*))
110
+        .addLast("framedecoder", new DelimiterBasedFrameDecoder(1048576, Delimiters.lineDelimiter : _*))
111 111
         .addLast("decoder", new StringDecoder(Charset.forName("UTF-8")))
112 112
         .addLast("csvhandler", new TcpIndexHandler)
113 113
         .remove(this)
@@ -147,7 +147,7 @@ private class TcpIndexHandler extends ChannelInboundMessageHandlerAdapter[String
147 147
       inited = true
148 148
     } else {
149 149
       Indexer.index(IndexRequest(server, channel, botName,
150
-          List(ChatLine(values(0), values(1).toLong, values(2)))))
150
+          Seq(ChatLine(values(0), values(1).toLong, values(2)))))
151 151
     }
152 152
   }
153 153
 }
@@ -155,7 +155,7 @@ private class TcpIndexHandler extends ChannelInboundMessageHandlerAdapter[String
155 155
 @Sharable
156 156
 private object EchoHandler extends HttpRequestHandler {
157 157
   override def messageReceived(ctx: ChannelHandlerContext, request: HttpRequest) {
158
-    val content = request.getContent().toString(Charset.forName("UTF-8"))
158
+    val content = request.getContent.toString(Charset.forName("UTF-8"))
159 159
     logRequest(ctx, request, sendSuccess(ctx, request, content))
160 160
   }
161 161
 }
@@ -165,7 +165,7 @@ private class IndexHandler extends HttpRequestHandler {
165 165
   implicit val formats = DefaultFormats
166 166
   override def messageReceived(ctx: ChannelHandlerContext, request: HttpRequest) {
167 167
     future {
168
-      val content = request.getContent().toString(Charset.forName("UTF-8"))
168
+      val content = request.getContent.toString(Charset.forName("UTF-8"))
169 169
       val indexRequest = Serialization.read[IndexRequest](content)
170 170
       Indexer.index(indexRequest)
171 171
     }
@@ -178,16 +178,16 @@ private object SearchHandler extends HttpRequestHandler {
178 178
   implicit val formats = DefaultFormats
179 179
   override def messageReceived(ctx: ChannelHandlerContext, request: HttpRequest) {
180 180
     val f = future {
181
-      val method = request.getMethod()
181
+      val method = request.getMethod
182 182
       val searchRequest = if (HttpMethod.POST.equals(method)) {
183
-        val content = request.getContent().toString(Charset.forName("UTF-8"))
183
+        val content = request.getContent.toString(Charset.forName("UTF-8"))
184 184
         Serialization.read[SearchRequest](content)
185 185
       } else if (HttpMethod.GET.equals(method)) {
186 186
         val params = new QueryStringDecoder(request.getUri).getParameters.toMap
187
-        val List(server, channel, botName, query) =
188
-          List("server", "channel", "botName", "query").map(params(_).get(0))
189
-        val List(page, pageSize, details) =
190
-          List("page", "pageSize", "details").map(params.get(_).map({ case l => l.get(0) }))
187
+        val Seq(server, channel, botName, query) =
188
+          Seq("server", "channel", "botName", "query").map(params(_).get(0))
189
+        val Seq(page, pageSize, details) =
190
+          Seq("page", "pageSize", "details").map(params.get(_).map({ case l => l.get(0) }))
191 191
 
192 192
         var sr = SearchRequest(server, channel, botName, query)
193 193
         if (page.isDefined)

+ 10
- 10
src/main/scala/net/abhinavsarkar/ircsearch/lucene/Indexer.scala View File

@@ -49,11 +49,11 @@ object Indexer extends Logging {
49 49
   private val config = Configuration.loadResource("/irc-search.conf").detach("indexing")
50 50
 
51 51
   val LuceneVersion = Version.LUCENE_43
52
-  private val ContextSize = config[Int]("context.size")
52
+  private val ContextSize =         config[Int]("context.size")
53 53
   private val ContextDurationSecs = config[Int]("context.durationSecs")
54
-  private val RunIntervalSecs = config[Int]("runIntervalSecs")
55
-  private val FlushIntervalSecs = config[Int]("flushIntervalSecs")
56
-  private val RateLimitPerSec = config[Int]("rateLimitPerSec")
54
+  private val RunIntervalSecs =     config[Int]("runIntervalSecs")
55
+  private val FlushIntervalSecs =   config[Int]("flushIntervalSecs")
56
+  private val RateLimitPerSec =     config[Int]("rateLimitPerSec")
57 57
 
58 58
   private val indexQueue = new PriorityBlockingQueue[IndexRecord]
59 59
   private val scheduler = Executors.newScheduledThreadPool(2)
@@ -78,7 +78,7 @@ object Indexer extends Logging {
78 78
     val defAnalyzer = new StandardAnalyzer(LuceneVersion)
79 79
     val fieldAnalyzers = Map(
80 80
         ChatLine.USER -> new KeywordAnalyzer,
81
-        ChatLine.MSG -> new EnglishAnalyzer(LuceneVersion),
81
+        ChatLine.MSG  -> new EnglishAnalyzer(LuceneVersion),
82 82
         ChatLine.CTXB -> new EnglishAnalyzer(LuceneVersion),
83 83
         ChatLine.CTXA -> new EnglishAnalyzer(LuceneVersion))
84 84
 
@@ -136,10 +136,10 @@ object Indexer extends Logging {
136 136
       rec.chatLine.copy(
137 137
         contextBefore = recs.slice(idx - ContextSize, idx).map(_.chatLine)
138 138
         .filter(_.timestamp >= rec.chatLine.timestamp - ContextDurationSecs * 1000)
139
-        .toList,
139
+        .toSeq,
140 140
         contextAfter = recs.slice(idx + 1, 2 * ContextSize + 1).map(_.chatLine)
141 141
         .filter(_.timestamp <= rec.chatLine.timestamp + ContextDurationSecs * 1000)
142
-        .toList))
142
+        .toSeq))
143 143
   }
144 144
 
145 145
   def start {
@@ -148,7 +148,7 @@ object Indexer extends Logging {
148 148
       if (!indexQueue.isEmpty) {
149 149
         val indexRecs = new ArrayList[IndexRecord]
150 150
         indexQueue drainTo indexRecs
151
-        val indexRecsMap = indexRecs groupBy { r => (r.server, r.channel, r.botName) }
151
+        val indexRecsMap = indexRecs.toIndexedSeq groupBy { r => (r.server, r.channel, r.botName) }
152 152
 
153 153
         val windowSize = 2 * ContextSize + 1
154 154
         for (indexRecBatch <- indexRecsMap.values) {
@@ -192,7 +192,7 @@ object Indexer extends Logging {
192 192
     }
193 193
   }
194 194
 
195
-  private def ctxToStr(ctx : List[ChatLine]) =
195
+  private def ctxToStr(ctx : Seq[ChatLine]) =
196 196
     ctx.map { line => s"${line.timestamp} ${line.user}: ${line.message}" }  mkString "\n"
197 197
 
198 198
   private def doIndex(indexRecord: IndexRecord) {
@@ -205,7 +205,7 @@ object Indexer extends Logging {
205 205
       val msg = new TextField(ChatLine.MSG, chatLine.message, Field.Store.YES)
206 206
       val ctxBfr = new TextField(ChatLine.CTXB, ctxToStr(chatLine.contextBefore), Field.Store.YES)
207 207
       val ctxAft = new TextField(ChatLine.CTXA, ctxToStr(chatLine.contextAfter), Field.Store.YES)
208
-      indexWriter.addDocument(List(ts, user, msg, ctxBfr, ctxAft), indexWriter.getAnalyzer)
208
+      indexWriter.addDocument(Seq(ts, user, msg, ctxBfr, ctxAft), indexWriter.getAnalyzer)
209 209
       logger.debug("Indexed : [{} {} {}] [{}] {}: {}",
210 210
           server, channel, botName, new Date(chatLine.timestamp), chatLine.user, chatLine.message)
211 211
     }

+ 7
- 7
src/main/scala/net/abhinavsarkar/ircsearch/lucene/Searcher.scala View File

@@ -51,7 +51,7 @@ object Searcher extends Logging {
51 51
 
52 52
   private def mkQueryParser(analyzer : Analyzer) =
53 53
     new MultiFieldQueryParser(Indexer.LuceneVersion,
54
-        List(ChatLine.MSG, ChatLine.CTXB, ChatLine.CTXA).toArray, analyzer,
54
+        Array(ChatLine.MSG, ChatLine.CTXB, ChatLine.CTXA), analyzer,
55 55
         Map(ChatLine.MSG -> MessageFieldBoost))
56 56
 
57 57
   private def filterifyQuery(query : Query) : Query =
@@ -121,13 +121,13 @@ object Searcher extends Logging {
121 121
     }
122 122
   }
123 123
 
124
-  private val DocFields = List(ChatLine.USER, ChatLine.TS, ChatLine.MSG, ChatLine.CTXB, ChatLine.CTXA)
124
+  private val DocFields = Seq(ChatLine.USER, ChatLine.TS, ChatLine.MSG, ChatLine.CTXB, ChatLine.CTXA)
125 125
 
126 126
   private def doSearch(indexDir : String, query : Query, page : Int, pageSize : Int)
127
-    : (Int, List[(ChatLine, Float)]) = {
127
+    : (Int, Seq[(ChatLine, Float)]) = {
128 128
     val searcherMgr = getSearcherMgr(indexDir)
129 129
     searcherMgr.maybeRefresh
130
-    val indexSearcher = searcherMgr.acquire()
130
+    val indexSearcher = searcherMgr.acquire
131 131
     try {
132 132
       val topDocs = indexSearcher.search(query, MaxHits.min((page + 1) * pageSize),
133 133
           new Sort(SortField.FIELD_SCORE, new SortField(ChatLine.TS, SortField.Type.LONG, true)))
@@ -139,15 +139,15 @@ object Searcher extends Logging {
139 139
           (map, field) => map += (field.name -> field.stringValue)
140 140
         }
141 141
 
142
-        val List(user, timestamp, message, contextBefore, contextAfter) = DocFields.map(doc)
142
+        val Seq(user, timestamp, message, contextBefore, contextAfter) = DocFields.map(doc)
143 143
 
144 144
         val LineRe = "(\\d+) (.*?): (.*)".r
145
-        val List(ctxBefore, ctxAfter) = List(contextBefore, contextAfter).map {
145
+        val Seq(ctxBefore, ctxAfter) = Seq(contextBefore, contextAfter).map {
146 146
           _.split('\n').filterNot(_.isEmpty).map {
147 147
             case LineRe(timestamp, user, message) => ChatLine(user, timestamp.toLong, message)
148 148
           }}
149 149
 
150
-        val chatLine = ChatLine(user, timestamp.toLong, message, ctxBefore.toList, ctxAfter.toList)
150
+        val chatLine = ChatLine(user, timestamp.toLong, message, ctxBefore, ctxAfter)
151 151
         (chatLine, score)
152 152
       }
153 153
       (topDocs.totalHits, docs.toList)

+ 7
- 7
src/main/scala/net/abhinavsarkar/ircsearch/model.scala View File

@@ -10,11 +10,11 @@ object ChatLine {
10 10
 }
11 11
 
12 12
 case class ChatLine(user : String, timestamp : Long, message : String,
13
-    contextBefore : List[ChatLine] = List(),
14
-    contextAfter : List[ChatLine] = List())
13
+    contextBefore : Seq[ChatLine] = Seq(),
14
+    contextAfter : Seq[ChatLine] = Seq())
15 15
 
16 16
 case class IndexRequest(
17
-    server : String, channel : String, botName : String, chatLines : List[ChatLine])
17
+    server : String, channel : String, botName : String, chatLines : Seq[ChatLine])
18 18
 
19 19
 case class SearchRequest(
20 20
     server : String, channel : String, botName : String, query: String,
@@ -22,13 +22,13 @@ case class SearchRequest(
22 22
 
23 23
 case class SearchResult(
24 24
     server : String, channel : String, botName : String, query: String,
25
-    page : Int, pageSize : Int, totalResults : Int, chatLines : List[ChatLine]) {
25
+    page : Int, pageSize : Int, totalResults : Int, chatLines : Seq[ChatLine]) {
26 26
   def toSimpleSearchResult =
27 27
     SimpleSearchResult(server, channel, botName, query, page, pageSize, totalResults,
28 28
       chatLines map {
29 29
         case mline@ChatLine(_, _, _, contextBefore, contextAfter) =>
30 30
           ((contextBefore :+ mline) ++ contextAfter) map { line =>
31
-            List(line.timestamp.toString, line.user, line.message)
31
+            Seq(line.timestamp.toString, line.user, line.message)
32 32
           }
33 33
       })
34 34
 }
@@ -36,12 +36,12 @@ case class SearchResult(
36 36
 object SearchResult {
37 37
   def fromSearchRequest(searchRequest : SearchRequest) = searchRequest match {
38 38
     case SearchRequest(server, channel, botName, query, page, pageSize, _) =>
39
-      new SearchResult(server, channel, botName, query, page, pageSize, 0, List())
39
+      new SearchResult(server, channel, botName, query, page, pageSize, 0, Seq())
40 40
   }
41 41
 }
42 42
 
43 43
 case class SimpleSearchResult(
44 44
     server : String, channel : String, botName : String, query: String,
45
-    page : Int, pageSize : Int, totalResults : Int, lines : List[List[List[String]]])
45
+    page : Int, pageSize : Int, totalResults : Int, lines : Seq[Seq[Seq[String]]])
46 46
 
47 47
 case class SearchError(error : String)

Loading…
Cancel
Save