Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.36k stars 2k forks source link

[BUG][Autosuggest] Autosuggest method path is only '/Suggestions'; should be '/bing/v7.0/Suggestions' #4560

Closed v-jaswel closed 8 months ago

v-jaswel commented 5 years ago

Describe the bug The path for autosuggest method is '/Suggestions'. It should be '/bing/v7.0/Suggestions'.

Exception or Stack Trace No exception, but the call to BingAutoSuggestSearchAPI.bingAutoSuggestSearch().autoSuggest().withQuery("xb").execute() returns null for a query that returns results in other languages and in the API testing console.

To Reproduce Steps to reproduce the behavior:

  1. Copy the contents of pom.xml below into a file named pom.xml.
  2. Copy the contents of quickstart.java below into a file named quickstart.java.
  3. Install Maven (https://maven.apache.org/download.cgi) if you don't have it.
  4. Open an Administrator command prompt and navigate to the folder that contains pom.xml and quickstart.java.
  5. Run mvn clean dependency:copy-dependencies
  6. Run javac Quickstart.java -cp .;lib\*
  7. Run java -cp .;lib\* Quickstart
  8. Output:
    No suggestions found.

Note This also causes me to get a null response when running the sample at https://github.com/Azure-Samples/cognitive-services-java-sdk-samples/blob/master/Search/BingAutoSuggest/src/main/java/com/microsoft/azure/cognitiveservices/search/autosuggest/samples/BingAutoSuggestSample.java.

Code Snippet pom.xml:

<?xml version="1.0" encoding="utf-8"?>
<!--
Source: https://gist.github.com/statico/547434f630d589651afcbe3f132b91d9
Run with: mvn clean dependency:copy-dependencies
-->
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.foo</groupId>
  <artifactId>bar</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>

    <!-- https://mvnrepository.com/artifact/com.microsoft.azure.cognitiveservices/azure-cognitiveservices-autosuggest -->
    <dependency>
      <groupId>com.microsoft.azure.cognitiveservices</groupId>
      <artifactId>azure-cognitiveservices-autosuggest</artifactId>
      <version>1.0.2-beta</version>
    </dependency>

    <!-- This fixes the following runtime warnings:
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.7.25</version>
    </dependency>

  </dependencies>

  <build>
    <directory>lib</directory>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <configuration>
          <outputDirectory>
            ${project.build.directory}
          </outputDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

quickstart.java:

import com.microsoft.azure.cognitiveservices.search.autosuggest.BingAutoSuggestSearchAPI;
import com.microsoft.azure.cognitiveservices.search.autosuggest.BingAutoSuggestSearchManager;
import com.microsoft.azure.cognitiveservices.search.autosuggest.models.SearchAction;
import com.microsoft.azure.cognitiveservices.search.autosuggest.models.Suggestions;
import com.microsoft.azure.cognitiveservices.search.autosuggest.models.SuggestionsSuggestionGroup;

import java.io.*;
import java.lang.Object.*;
import java.util.*;
import java.net.*;

public class Quickstart {
    private static String subscription_key = System.getenv("AUTOSUGGEST_SUBSCRIPTION_KEY");
    private static String endpoint = System.getenv("AUTOSUGGEST_ENDPOINT");
    BingAutoSuggestSearchAPI client = BingAutoSuggestSearchManager.authenticate(endpoint, subscription_key);

    public void get_suggestions() {
        Suggestions suggestions = client.bingAutoSuggestSearch().autoSuggest().withQuery("xb").execute();
        if (suggestions != null && suggestions.suggestionGroups() != null && suggestions.suggestionGroups().size() > 0) {
            SuggestionsSuggestionGroup group = suggestions.suggestionGroups().get(0);
            System.out.println("First suggestion group: " + group.name());
            System.out.println("Suggestions:");
            for (SearchAction suggestion: group.searchSuggestions()) {
                System.out.println("Query: " + suggestion.query());
                System.out.println("Text: " + suggestion.displayText());
                System.out.println("URL: " + suggestion.url());
                System.out.println("Kind: " + suggestion.searchKind());
                System.out.println();
            }
        } else {
            System.out.println("No suggestions found.");
        }
    }

    public static void main(String[] args) {
        try {
            Quickstart quickstart = new Quickstart();
            quickstart.get_suggestions();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}

Expected behavior Expected output:

First suggestion group: Web
Suggestions:
Query: xbox
Text: xbox
URL: https://www.bing.com/search?q=xbox&FORM=USBAPI
Kind: WebSearch

Query: xbox game pass
Text: xbox game pass
URL: https://www.bing.com/search?q=xbox+game+pass&FORM=USBAPI
Kind: WebSearch

Query: xbox reddit
Text: xbox reddit
URL: https://www.bing.com/search?q=xbox+reddit&FORM=USBAPI
Kind: WebSearch

Query: xbox live
Text: xbox live
URL: https://www.bing.com/search?q=xbox+live&FORM=USBAPI
Kind: WebSearch

Query: xbox one x
Text: xbox one x
URL: https://www.bing.com/search?q=xbox+one+x&FORM=USBAPI
Kind: WebSearch

Query: xbox one
Text: xbox one
URL: https://www.bing.com/search?q=xbox+one&FORM=USBAPI
Kind: WebSearch

Query: xbox app
Text: xbox app
URL: https://www.bing.com/search?q=xbox+app&FORM=USBAPI
Kind: WebSearch

Query: xbox game pass ultimate
Text: xbox game pass ultimate
URL: https://www.bing.com/search?q=xbox+game+pass+ultimate&FORM=USBAPI
Kind: WebSearch

Setup (please complete the following information):

Additional context I am able to resolve the issue and get the expected output as follows.

  1. In [My Github base folder]\azure-sdk-for-java\cognitiveservices\data-plane\search\bingautosuggest\src\main\java\com\microsoft\azure\cognitiveservices\search\autosuggest\implementation\BingAutoSuggestSearchImpl.java, change line 62 from:
    @GET("Suggestions")

    to:

    @GET("/bing/v7.0/Suggestions")
  2. Recompile azure-cognitiveservices-autosuggest-1.0.2-beta.jar from my modified source and place it in the lib subfolder of my project folder (where quickstart.java is).

There is a similar issue in the Azure SDK for Python (https://github.com/Azure/azure-sdk-for-python/issues/6472).

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jaggerbodas-ms, @arwong.

joshfree commented 8 months ago

Closing old issue with no activity from June 23, 2020