Skip to content

Commit 9f09062

Browse files
authored
Merge pull request #21 from LisaLeib/java-quickstart-sample
updated package paths and a few other related changes
2 parents 4ac3272 + fdd395f commit 9f09062

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

quickstart/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
</execution>
3131
</executions>
3232
<configuration>
33-
<mainClass>app.App</mainClass>
33+
<mainClass>main.java.app.App</mainClass>
3434
<cleanupDaemonThreads>false</cleanupDaemonThreads>
3535
</configuration>
3636
</plugin>
@@ -43,5 +43,4 @@
4343
<version>1.0.2</version>
4444
</dependency>
4545
</dependencies>
46-
4746
</project>

quickstart/src/main/java/app/App.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package app;
1+
package main.java.app;
22

3-
import service.SearchServiceClient;
3+
import main.java.service.SearchServiceClient;
44
import java.io.IOException;
55
import java.util.Properties;
66

@@ -15,7 +15,7 @@ private static Properties loadPropertiesFromResource(String resourcePath) throws
1515

1616
public static void main(String[] args) {
1717
try {
18-
var config = loadPropertiesFromResource("config.properties");
18+
var config = loadPropertiesFromResource("/app/config.properties");
1919
var client = new SearchServiceClient(
2020
config.getProperty("SearchServiceName"),
2121
config.getProperty("SearchServiceAdminKey"),
@@ -26,18 +26,18 @@ public static void main(String[] args) {
2626

2727

2828
//Uncomment the next 3 lines in the 1 - Create Index section of the quickstart
29-
if (client.indexExists()) { client.deleteIndex();}
30-
client.createIndex("index.json");
29+
if(client.indexExists()){ client.deleteIndex();}
30+
client.createIndex("/service/index.json");
3131
Thread.sleep(1000L); // wait a second to create the index
3232

3333
//Uncomment the next 2 lines in the 2 - Load Documents section of the quickstart
34-
client.uploadDocuments("hotels.json");
34+
client.uploadDocuments("/service/hotels.json");
3535
Thread.sleep(2000L); // wait 2 seconds for data to upload
3636

3737
//Uncomment the following 5 search queries in the 3 - Search an index section of the quickstart
3838
// Query 1
3939
client.logMessage("\n*QUERY 1****************************************************************");
40-
client.logMessage("Search for: Atlanta");
40+
client.logMessage("Search for: Atlanta'");
4141
client.logMessage("Return: All fields'");
4242
client.searchPlus("Atlanta");
4343

@@ -84,4 +84,4 @@ public static void main(String[] args) {
8484
e.printStackTrace();
8585
}
8686
}
87-
}
87+
}

quickstart/src/main/java/service/SearchServiceClient.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package service;
1+
package main.java.service;
22

33
import javax.json.Json;
44
import javax.net.ssl.HttpsURLConnection;
@@ -13,8 +13,7 @@
1313
import java.util.Formatter;
1414
import java.util.function.Consumer;
1515

16-
/**
17-
* This class is responsible for implementing HTTP operations for creating the index, uploading documents and searching the data*/
16+
/* This class is responsible for implementing HTTP operations for creating the index, uploading documents and searching the data*/
1817
public class SearchServiceClient {
1918
private final String _adminKey;
2019
private final String _queryKey;
@@ -130,14 +129,15 @@ public boolean createIndex(String indexDefinitionFile) throws IOException, Inter
130129
"https://%s.search.windows.net/indexes/%s?api-version=%s",
131130
_serviceName,_indexName,_apiVersion));
132131
//Read in index definition file
133-
var inputStream = SearchServiceClient.class.getResourceAsStream("index.json");
132+
var inputStream = SearchServiceClient.class.getResourceAsStream(indexDefinitionFile);
134133
var indexDef = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
135134
//Send HTTP PUT request to create the index in the search service
136135
var request = httpRequest(uri, _adminKey, "PUT", indexDef);
137136
var response = sendRequest(request);
138137
return isSuccessResponse(response);
139138
}
140139

140+
141141
public boolean uploadDocuments(String documentsFile) throws IOException, InterruptedException {
142142
logMessage("\n Uploading documents...");
143143
//Build the search service URL
@@ -153,6 +153,7 @@ public boolean uploadDocuments(String documentsFile) throws IOException, Interru
153153
return isSuccessResponse(response);
154154
}
155155

156+
156157
public SearchOptions createSearchOptions() { return new SearchOptions();}
157158

158159
//Defines available search parameters that can be set
@@ -211,4 +212,6 @@ public void searchPlus(String queryString, SearchOptions options) {
211212
}
212213

213214
}
215+
216+
214217
}

0 commit comments

Comments
 (0)