uadetector icon indicating copy to clipboard operation
uadetector copied to clipboard

Fixed mapping between agent family and type?

Open HaraldWalker opened this issue 11 years ago • 3 comments

I've been wondering if the agent types could be mapped directly to the agent families, cause it seems that depending on the type the agent also has its own family entry in the database.

For instance Internet Explorer could be family IE with as types BROWSER and MOBILE_BROWSER but the current implementation also has an IE_MOBILE family and I see the same for other mobile browsers. Family THUNDERBIRD is always an EMAIL_CLIENT type.

It would save some parsing (calling evaluateByTypeName) and I would only have to persist the family and don't need the type as I could derive it later again from the family.

HaraldWalker avatar May 14 '14 08:05 HaraldWalker

Family and type of an UserAgent will be mapped more or less straight forward from a value in string representation to the corresponding enum value. The enum UserAgentFamily supports the developer to check in a type safe way if a given agent has a certain family or not rather than comparing strings. The same goes for the UserAgentType which is maintained in the UAS database (XML or INI) itself for each browser.

Really processing costly is the pattern matching of an user agent string against the defined regular expressions.

Your proposed amendment is properly not the best way to save performance. The pull request #68 is about that by limiting the variety of user agent that can be detected to gain speed.

arouel avatar May 14 '14 21:05 arouel

#68 sounds interesting. While it is great that the library can detect many different user agents and operating systems, there are too many rare and outdated ones that are not relevant in many use cases. Limiting the variety is probably an acceptable option for many users to speed it up. Am curious if that can be achieved without getting false results.

My second aspect was persistence of the user agent result. If an agent family has a fixed type, I don't need to store the type any longer.

In the database that fixed relationship seems to exist:

<browser>
   <id>35</id>
   <type>0</type>
   <name>IE</name>
   <url><![CDATA[http://en.wikipedia.org/wiki/Internet_Explorer]]></url>
   <company><![CDATA[Microsoft Corporation.]]></company>
   <url_company><![CDATA[http://www.microsoft.com/]]></url_company>
   <icon>msie.png</icon>
   <browser_info_url>/list-of-ua/browser-detail?browser=IE</browser_info_url>
</browser>

<browser_type>
   <id>0</id>
   <type>Browser</type>
</browser_type>

HaraldWalker avatar May 14 '14 22:05 HaraldWalker

We will see if it works. In any way we need to think about how we can improve the detection algorithm based on what we can determine today. I assume we need a new database and implementation for that at some point.

To your second point: Its up to you. The enum can change at some point if the database will be changed in that area. I do not expect it in the next years and if it happens you can migrate your data.

To your last topic: I have no idea what your issue is but you can always cross-check what uadetector identifies with the online updating parser against http://user-agent-string.info. If there is any difference than file an issue here.

arouel avatar May 16 '14 09:05 arouel