mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge pull request #23 from ff-meli/xivapi_exact_search
Fix for #22 - prepending an item name with a '+' will do an exact search
This commit is contained in:
commit
942893400f
2 changed files with 17 additions and 4 deletions
|
|
@ -177,7 +177,7 @@ namespace Dalamud {
|
|||
|
||||
CommandManager.AddHandler("/xlitem", new CommandInfo(OnItemLinkCommand)
|
||||
{
|
||||
HelpMessage = "Link an item by name. Usage: /xlitem <Item name>"
|
||||
HelpMessage = "Link an item by name. Usage: /xlitem <Item name>. For matching an item exactly, use /xlitem +<Item name>"
|
||||
});
|
||||
|
||||
#if DEBUG
|
||||
|
|
@ -390,9 +390,16 @@ namespace Dalamud {
|
|||
}
|
||||
|
||||
private void OnItemLinkCommand(string command, string arguments) {
|
||||
var exactSearch = false;
|
||||
if (arguments.StartsWith("+"))
|
||||
{
|
||||
exactSearch = true;
|
||||
arguments = arguments.Substring(1);
|
||||
}
|
||||
|
||||
Task.Run(async () => {
|
||||
try {
|
||||
dynamic results = await XivApi.Search(arguments, "Item", 1);
|
||||
dynamic results = await XivApi.Search(arguments, "Item", 1, exactSearch);
|
||||
var itemId = (short) results.Results[0].ID;
|
||||
var itemName = (string)results.Results[0].Name;
|
||||
|
||||
|
|
|
|||
|
|
@ -49,10 +49,16 @@ namespace Dalamud
|
|||
return await Get("ContentFinderCondition/" + contentFinderCondition);
|
||||
}
|
||||
|
||||
public static async Task<JObject> Search(string query, string indexes, int limit = 100) {
|
||||
public static async Task<JObject> Search(string query, string indexes, int limit = 100, bool exact = false) {
|
||||
query = System.Net.WebUtility.UrlEncode(query);
|
||||
|
||||
return await Get("search" + $"?string={query}&indexes={indexes}&limit={limit}");
|
||||
var queryString = $"?string={query}&indexes={indexes}&limit={limit}";
|
||||
if (exact)
|
||||
{
|
||||
queryString += "&string_algo=match";
|
||||
}
|
||||
|
||||
return await Get("search" + queryString);
|
||||
}
|
||||
|
||||
public static async Task<JObject> GetMarketInfoWorld(int itemId, string worldName) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue